From ebf8e3b5d49af442c12e28e23928b54ee91a4329 Mon Sep 17 00:00:00 2001 From: codex Date: Wed, 18 Nov 2026 20:57:38 +0000 Subject: [PATCH 1/2] Allow wishes in multiple folders and hide fulfilled wishes --- README.md | 12 ++-- apps/backend/package.json | 2 +- apps/backend/prisma/schema.prisma | 2 + .../src/modules/wishes/dashboard.routes.ts | 4 +- .../src/modules/wishes/wishes.service.ts | 72 ++++++++++++++----- apps/frontend/package.json | 2 +- .../src/components/WishCard/WishCard.tsx | 4 +- .../src/components/WishForm/WishForm.tsx | 59 ++++++++++----- apps/frontend/src/i18n/i18n.tsx | 12 ++-- apps/frontend/src/pages/DashboardPage.tsx | 40 ++++++++--- apps/frontend/src/styles/global.css | 7 ++ packages/shared/package.json | 2 +- packages/shared/src/wish.schema.ts | 2 + 13 files changed, 159 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index eafd6cd..1c4523d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A small, private wishlist app for two users. The signed-in dashboard shows both ## Features - Two fixed accounts (credentials in env), password stored only as a **bcrypt hash**. -- Either user can create a shared folder with an optional description and emoji or image cover, and add their own wishes to any shared folder. Each wish also appears in its author's list. +- Either user can create a shared folder with an optional description and emoji or image cover. The author can select several shared folders when creating or editing a wish. Active and fulfilled wishes also appear in All and in their author's list. The dashboard can hide fulfilled wishes across these views. - Wish entity: title, price, currency, link, comment, image (auto-fetched from link or uploaded). - Statuses: **Active → Archive / Fulfilled → Trash** (kept for 30 days, then permanently removed by a daily cron job). - Restore from archive or trash. Duplicate from fulfilled into a new active wish. @@ -60,7 +60,7 @@ utils/ errors, bcrypt helpers, version helper See `apps/backend/prisma/schema.prisma`. Tables: - `User` — `id`, `username`, `slug`, `displayName`, `bio`, `avatarUrl`. **No password hash.** -- `Wish` — `userId`, optional `folderId`, `title`, `price`, `currency`, `url`, `comment`, `imageUrl`, `imageSource`, `status`, timestamps, `sourceWishId` (for duplicates). +- `Wish` — `userId`, optional `folderId` and additional folder links, `title`, `price`, `currency`, `url`, `comment`, `imageUrl`, `imageSource`, `status`, timestamps, `sourceWishId` (for duplicates). - `WishFolder` — shared folder metadata and its creator. - `GuestView` — `(guestId, wishId)` pairs for "already seen" tracking. @@ -160,11 +160,11 @@ On first start, the backend: ### Production release -Follow the [controlled deployment runbook in infra-home](https://git.vakanaut.ru/admin/infra-home/src/branch/main/docs/runbooks/deployment.md). Build the frontend and backend images from the same merged revision and record both image digests. Release the pair together because the 0.4.0 home page uses the new `/api/dashboard` endpoint. +Follow the [controlled deployment runbook in infra-home](https://git.vakanaut.ru/admin/infra-home/src/branch/main/docs/runbooks/deployment.md). Build the frontend and backend images from the same merged revision and record both image digests. Release the pair together so the frontend can read and save multi-folder assignments. Before upgrading an existing deployment, back up PostgreSQL and the uploads volume. Verify that the backup can be restored in an isolated environment. After deployment, check `/api/health`, `/api/version` and the signed-in dashboard. Confirm that an existing wish is still visible and a new wish in a shared folder also appears in the author's folder. -If a rollback is needed, restore the previous frontend and backend images together. For a pre-0.4.0 backend image, override the command with `node dist/src/index.js` (from `/app/apps/backend`). The previous image's default startup runs `prisma db push --accept-data-loss`, which can remove the shared folder table and wish-to-folder links. +If a rollback is needed, restore the previous frontend and backend images together. Start a pre-0.5.0 backend with `node dist/src/index.js` (from `/app/apps/backend`) to preserve the new schema. Version 0.4.0 shows the first shared folder while it is running. Backend images older than 0.4.0 run `prisma db push --accept-data-loss` by default, which can remove the shared folder data. ### Development schema migrations @@ -234,6 +234,8 @@ All responses are JSON. Authenticated endpoints require the `fw_auth` cookie. | POST | `/api/public/:slug/views` | — | Body `{ wishIds: [] }`. Marks as seen. | | GET | `/api/health`, `/api/version` | — | Meta. | +For create and update, `folderIds` accepts the selected shared folder IDs. An empty array removes all shared assignments. When both keys are omitted from an update, assignments are preserved. The single `folderId` input remains supported for version 0.4.0 clients. + --- ## Versioning @@ -241,7 +243,7 @@ All responses are JSON. Authenticated endpoints require the `fw_auth` cookie. Each package has its own version (`apps/backend/package.json` and `apps/frontend/package.json`). The app footer shows both: ``` -frontend v0.4.0 · backend v0.4.0 +frontend v0.5.0 · backend v0.5.0 ``` Bump them per semver on each change: diff --git a/apps/backend/package.json b/apps/backend/package.json index becd477..aef9aae 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -1,6 +1,6 @@ { "name": "@family-wishlist/backend", - "version": "0.4.0", + "version": "0.5.0", "private": true, "type": "module", "main": "dist/index.js", diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index 455ddbf..d1883b3 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -41,6 +41,7 @@ model WishFolder { creator User @relation(fields: [creatorId], references: [id]) createdAt DateTime @default(now()) wishes Wish[] + additionalWishes Wish[] @relation("AdditionalWishFolders") } enum WishStatus { @@ -76,6 +77,7 @@ model Wish { sourceWishId String? folderId String? folder WishFolder? @relation(fields: [folderId], references: [id], onDelete: SetNull) + additionalFolders WishFolder[] @relation("AdditionalWishFolders") views GuestView[] diff --git a/apps/backend/src/modules/wishes/dashboard.routes.ts b/apps/backend/src/modules/wishes/dashboard.routes.ts index 41255d0..15d0c45 100644 --- a/apps/backend/src/modules/wishes/dashboard.routes.ts +++ b/apps/backend/src/modules/wishes/dashboard.routes.ts @@ -5,6 +5,7 @@ import { usersRegistry } from '../../auth/users.registry.js'; import { MAX_UPLOAD_BYTES } from '../../plugins/multipart.js'; import { UnauthorizedError, ValidationError } from '../../utils/errors.js'; import { deleteLocalImageIfAny, saveUploadedImage } from '../images/storage.service.js'; +import { includeWishFolders, withFolderIds } from './wishes.service.js'; const folderFields = ['name', 'description', 'emoji']; @@ -28,6 +29,7 @@ export default async function dashboardRoutes(app: FastifyInstance) { app.prisma.wish.findMany({ where: { userId: { in: authorIds }, status: { in: ['ACTIVE', 'COMPLETED'] } }, orderBy: [{ status: 'asc' }, { createdAt: 'desc' }, { id: 'asc' }], + include: includeWishFolders, }), ]); const newSince = Date.now() - NEW_BADGE_DAYS * 24 * 60 * 60 * 1000; @@ -36,7 +38,7 @@ export default async function dashboardRoutes(app: FastifyInstance) { authors: users.sort((a, b) => authorIds.indexOf(a.id) - authorIds.indexOf(b.id)), folders, wishes: wishes.map((wish) => ({ - ...wish, + ...withFolderIds(wish), isNewForOwner: wish.status === 'ACTIVE' && wish.createdAt.getTime() > newSince, })), }; diff --git a/apps/backend/src/modules/wishes/wishes.service.ts b/apps/backend/src/modules/wishes/wishes.service.ts index 4f84720..56a56da 100644 --- a/apps/backend/src/modules/wishes/wishes.service.ts +++ b/apps/backend/src/modules/wishes/wishes.service.ts @@ -15,55 +15,88 @@ const statusMap: Record = { deleted: 'DELETED', }; +export const includeWishFolders = { + additionalFolders: { select: { id: true }, orderBy: { id: 'asc' as const } }, +}; + +export function withFolderIds({ additionalFolders, ...wish }: Wish & { + additionalFolders: { id: string }[]; +}) { + const folderIds = new Set(wish.folderId ? [wish.folderId] : []); + for (const { id } of additionalFolders) folderIds.add(id); + return { ...wish, folderIds: [...folderIds] }; +} + +function requestedFolders(input: UpdateWishInput): string[] | undefined { + if (input.folderIds !== undefined) return [...new Set(input.folderIds)]; + if (input.folderId !== undefined) return input.folderId ? [input.folderId] : []; +} + export class WishesService { constructor(private readonly prisma: PrismaClient) {} - list(userId: string, status: Status): Promise { - return this.prisma.wish.findMany({ + async list(userId: string, status: Status) { + const wishes = await this.prisma.wish.findMany({ where: { userId, status: statusMap[status] }, orderBy: [{ status: 'asc' }, { createdAt: 'desc' }], + include: includeWishFolders, }); + return wishes.map(withFolderIds); } - async getOwned(userId: string, id: string): Promise { - const wish = await this.prisma.wish.findUnique({ where: { id } }); + async getOwned(userId: string, id: string) { + const wish = await this.prisma.wish.findUnique({ where: { id }, include: includeWishFolders }); if (!wish) throw new NotFoundError('Wish'); if (wish.userId !== userId) throw new ForbiddenError(); - return wish; + return withFolderIds(wish); } - private async checkFolder(folderId: string | null | undefined): Promise { - if (folderId && !(await this.prisma.wishFolder.findUnique({ where: { id: folderId } }))) { + private async checkFolders(folderIds: string[]): Promise { + if (folderIds.length && await this.prisma.wishFolder.count({ + where: { id: { in: folderIds } }, + }) !== folderIds.length) { throw new NotFoundError('Folder'); } } - async create(userId: string, input: CreateWishInput): Promise { - await this.checkFolder(input.folderId); - return this.prisma.wish.create({ + async create(userId: string, input: CreateWishInput) { + const folderIds = requestedFolders(input) ?? []; + await this.checkFolders(folderIds); + const [folderId, ...additional] = folderIds; + const wish = await this.prisma.wish.create({ data: { userId, - folderId: input.folderId, + folderId, + additionalFolders: { connect: additional.map((id) => ({ id })) }, title: input.title, price: input.price ?? null, currency: input.currency ?? 'RUB', url: input.url ?? null, comment: input.comment ?? null, }, + include: includeWishFolders, }); + return withFolderIds(wish); } - async update(userId: string, id: string, input: UpdateWishInput): Promise { + async update(userId: string, id: string, input: UpdateWishInput) { await this.getOwned(userId, id); - await this.checkFolder(input.folderId); const data: Record = {}; - if (input.folderId !== undefined) data.folderId = input.folderId; + const folderIds = requestedFolders(input); + if (folderIds !== undefined) { + await this.checkFolders(folderIds); + const [folderId, ...additional] = folderIds; + data.folderId = folderId ?? null; + data.additionalFolders = { set: additional.map((id) => ({ id })) }; + } if (input.title !== undefined) data.title = input.title; if (input.price !== undefined) data.price = input.price ?? null; if (input.currency !== undefined) data.currency = input.currency ?? 'RUB'; if (input.url !== undefined) data.url = input.url ?? null; if (input.comment !== undefined) data.comment = input.comment ?? null; - return this.prisma.wish.update({ where: { id }, data }); + return withFolderIds(await this.prisma.wish.update({ + where: { id }, data, include: includeWishFolders, + })); } async archive(userId: string, id: string): Promise { @@ -108,9 +141,9 @@ export class WishesService { }); } - async duplicate(userId: string, id: string): Promise { + async duplicate(userId: string, id: string) { const source = await this.getOwned(userId, id); - return this.prisma.wish.create({ + const wish = await this.prisma.wish.create({ data: { userId, title: source.title, @@ -122,7 +155,12 @@ export class WishesService { imageSource: source.imageSource === 'UPLOADED' ? 'DEFAULT' : source.imageSource, sourceWishId: source.id, folderId: source.folderId, + additionalFolders: { + connect: source.folderIds.filter((id) => id !== source.folderId).map((id) => ({ id })), + }, }, + include: includeWishFolders, }); + return withFolderIds(wish); } } diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 3882a91..23a7fea 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@family-wishlist/frontend", - "version": "0.4.0", + "version": "0.5.0", "private": true, "type": "module", "scripts": { diff --git a/apps/frontend/src/components/WishCard/WishCard.tsx b/apps/frontend/src/components/WishCard/WishCard.tsx index 143eeba..ac5fec4 100644 --- a/apps/frontend/src/components/WishCard/WishCard.tsx +++ b/apps/frontend/src/components/WishCard/WishCard.tsx @@ -57,8 +57,10 @@ function WishCardInner({ const actions: WishCardAction[] = []; if (view === 'owner') { + if (onEdit && (wish.status === 'ACTIVE' || completed)) { + actions.push({ key: 'edit', icon: Pencil, label: t('wish.action.edit'), onClick: onEdit }); + } if (wish.status === 'ACTIVE') { - if (onEdit) actions.push({ key: 'edit', icon: Pencil, label: t('wish.action.edit'), onClick: onEdit }); if (onComplete) actions.push({ key: 'complete', diff --git a/apps/frontend/src/components/WishForm/WishForm.tsx b/apps/frontend/src/components/WishForm/WishForm.tsx index 9022f6e..fcd7647 100644 --- a/apps/frontend/src/components/WishForm/WishForm.tsx +++ b/apps/frontend/src/components/WishForm/WishForm.tsx @@ -1,5 +1,5 @@ import { useRef } from 'react'; -import { useForm } from 'react-hook-form'; +import { Controller, useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { createWishSchema, type CreateWishInput, type Wish, type WishFolder } from '@family-wishlist/shared'; import { Button } from '../ui/Button'; @@ -21,11 +21,12 @@ interface Props { mode: 'create' | 'edit'; initial?: Wish; folders?: WishFolder[]; + authorName: string; defaultFolderId?: string; onClose: () => void; } -export function WishForm({ mode, initial, folders, defaultFolderId, onClose }: Props) { +export function WishForm({ mode, initial, folders, authorName, defaultFolderId, onClose }: Props) { const { t } = useI18n(); const create = useCreateWish(); const update = useUpdateWish(); @@ -37,6 +38,7 @@ export function WishForm({ mode, initial, folders, defaultFolderId, onClose }: P const { register, + control, handleSubmit, formState: { errors, isSubmitting }, } = useForm({ @@ -47,12 +49,13 @@ export function WishForm({ mode, initial, folders, defaultFolderId, onClose }: P currency: initial?.currency ?? 'RUB', url: initial?.url ?? '', comment: initial?.comment ?? '', - folderId: initial?.folderId ?? defaultFolderId ?? null, + folderIds: initial?.folderIds ?? + (initial?.folderId ? [initial.folderId] : defaultFolderId ? [defaultFolderId] : []), }, }); const submit = handleSubmit(async (values) => { - const input = { ...values, folderId: folders ? values.folderId : undefined }; + const input = { ...values, folderIds: folders ? values.folderIds : undefined }; try { if (mode === 'create') { await create.mutateAsync(input); @@ -99,21 +102,39 @@ export function WishForm({ mode, initial, folders, defaultFolderId, onClose }: P )} - {folders && folders.length > 0 && ( -
- - -
- )} +
+ {t('folders.field')} +

+ {t('folders.alwaysVisible', { name: authorName })} +

+ {folders && folders.length > 0 && ( + ( +
+ {folders.map(({ id, name }) => { + const ids = field.value ?? []; + return ( + + ); + })} +
+ )} + /> + )} +
diff --git a/apps/frontend/src/i18n/i18n.tsx b/apps/frontend/src/i18n/i18n.tsx index e45df18..1cc4861 100644 --- a/apps/frontend/src/i18n/i18n.tsx +++ b/apps/frontend/src/i18n/i18n.tsx @@ -50,6 +50,8 @@ const translations = { 'dashboard.emptyTitle': 'Желаний пока нет', 'dashboard.loadError': 'Не удалось загрузить список желаний.', 'dashboard.retry': 'Повторить', + 'dashboard.hideCompleted': 'Скрыть исполненные', + 'dashboard.completedHidden': 'Исполненные желания скрыты', 'folders.title': 'Папки желаний', 'folders.all': 'Все', 'folders.create': 'Создать папку', @@ -59,8 +61,8 @@ const translations = { 'folders.noCover': 'Без обложки', 'folders.emoji': 'Эмодзи', 'folders.image': 'Изображение', - 'folders.field': 'Папка', - 'folders.noFolder': 'Без общей папки', + 'folders.field': 'В каких папках видно желание', + 'folders.alwaysVisible': 'Всегда видно во «Все» и в папке «{name}».', 'folders.invalidDetails': 'Проверьте название и описание папки.', 'folders.invalidEmoji': 'Введите эмодзи для обложки.', 'folders.invalidImage': 'Выберите файл JPEG, PNG, WebP или GIF размером до 8 МБ.', @@ -182,6 +184,8 @@ const translations = { 'dashboard.emptyTitle': 'No wishes yet', 'dashboard.loadError': "Couldn't load wishes.", 'dashboard.retry': 'Try again', + 'dashboard.hideCompleted': 'Hide fulfilled wishes', + 'dashboard.completedHidden': 'Fulfilled wishes are hidden', 'folders.title': 'Wish folders', 'folders.all': 'All', 'folders.create': 'Create folder', @@ -191,8 +195,8 @@ const translations = { 'folders.noCover': 'No cover', 'folders.emoji': 'Emoji', 'folders.image': 'Image', - 'folders.field': 'Folder', - 'folders.noFolder': 'No shared folder', + 'folders.field': 'Show wish in folders', + 'folders.alwaysVisible': 'Always visible in “All” and “{name}”.', 'folders.invalidDetails': 'Check the folder name and description.', 'folders.invalidEmoji': 'Enter an emoji for the cover.', 'folders.invalidImage': 'Choose a JPEG, PNG, WebP, or GIF file up to 8 MB.', diff --git a/apps/frontend/src/pages/DashboardPage.tsx b/apps/frontend/src/pages/DashboardPage.tsx index 782901a..ce2cc54 100644 --- a/apps/frontend/src/pages/DashboardPage.tsx +++ b/apps/frontend/src/pages/DashboardPage.tsx @@ -46,6 +46,7 @@ export function DashboardPage() { const { t } = useI18n(); const { data, isPending, isError, refetch } = useWishDashboard(); const [selection, setSelection] = useState({ type: 'all' }); + const [hideCompleted, setHideCompleted] = useState(false); const [creatingFolder, setCreatingFolder] = useState(false); const [creatingWish, setCreatingWish] = useState(false); const [editing, setEditing] = useState(null); @@ -62,11 +63,14 @@ export function DashboardPage() { const selectedFolder = selection.type === 'folder' ? data?.folders.find(({ id }) => id === selection.id) : undefined; - const wishes = data?.wishes.filter((wish) => + const folderWishes = data?.wishes.filter((wish) => selectedAuthor ? wish.userId === selectedAuthor.id - : selectedFolder ? wish.folderId === selectedFolder.id + : selectedFolder ? (wish.folderIds?.includes(selectedFolder.id) ?? wish.folderId === selectedFolder.id) : true, ); + const wishes = hideCompleted + ? folderWishes?.filter(({ status }) => status !== 'COMPLETED') + : folderWishes; const canAddWish = !selectedAuthor || selectedAuthor.id === user?.id; const sectionTitle = selectedAuthor?.displayName ?? selectedFolder?.name ?? t('folders.all'); @@ -175,17 +179,29 @@ export function DashboardPage() {

)}
- {canAddWish && ( - - )} +
+ + {canAddWish && ( + + )} +
{wishes.length === 0 ? (
-

{t('dashboard.emptyTitle')}

+

+ {t(folderWishes?.length ? 'dashboard.completedHidden' : 'dashboard.emptyTitle')} +

) : (
@@ -215,17 +231,19 @@ export function DashboardPage() { )} - {creatingWish && ( + {creatingWish && user && ( setCreatingWish(false)} /> )} - {editing && ( + {editing && user && ( setEditing(null)} diff --git a/apps/frontend/src/styles/global.css b/apps/frontend/src/styles/global.css index e608c83..c1ff65f 100644 --- a/apps/frontend/src/styles/global.css +++ b/apps/frontend/src/styles/global.css @@ -152,6 +152,13 @@ .wish-folders__form { @apply grid min-w-0 max-w-xl gap-4 rounded-md border border-border bg-surface p-4; } + .wish-checkbox { + @apply inline-flex min-h-9 min-w-0 cursor-pointer items-center gap-2 text-sm text-ink; + overflow-wrap: anywhere; + } + .wish-checkbox input { + @apply h-4 w-4 shrink-0 accent-primary; + } .public-profile { @apply flex min-h-screen flex-col; diff --git a/packages/shared/package.json b/packages/shared/package.json index 6ecc6fd..160ed53 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@family-wishlist/shared", - "version": "0.4.0", + "version": "0.5.0", "private": true, "type": "module", "main": "./dist/index.js", diff --git a/packages/shared/src/wish.schema.ts b/packages/shared/src/wish.schema.ts index 8285b90..f5b7e43 100644 --- a/packages/shared/src/wish.schema.ts +++ b/packages/shared/src/wish.schema.ts @@ -23,6 +23,7 @@ export const wishSchema = z.object({ deletedAt: z.string().nullable(), sourceWishId: z.string().nullable(), folderId: z.string().nullable().optional(), + folderIds: z.array(z.string()).optional(), isNewForGuest: z.boolean().optional(), }); @@ -30,6 +31,7 @@ export type Wish = z.infer; export const createWishSchema = z.object({ folderId: z.string().cuid().nullable().optional(), + folderIds: z.array(z.string().cuid()).optional(), title: z.string().trim().min(1).max(200), price: z .union([ -- 2.54.0 From a3c05c606a26b0c0795203e1ad98e373b61a1a3c Mon Sep 17 00:00:00 2001 From: codex Date: Wed, 18 Nov 2026 21:01:24 +0000 Subject: [PATCH 2/2] Keep legacy folder assignments and allow hiding from the author's folder --- README.md | 4 +- apps/backend/prisma/schema.prisma | 1 + .../src/modules/public/public.routes.ts | 2 +- .../src/modules/wishes/wishes.service.ts | 17 ++--- .../src/components/WishForm/WishForm.tsx | 63 ++++++++++--------- apps/frontend/src/i18n/i18n.tsx | 4 +- apps/frontend/src/pages/DashboardPage.tsx | 2 +- packages/shared/src/wish.schema.ts | 2 + 8 files changed, 53 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 1c4523d..76a1b72 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A small, private wishlist app for two users. The signed-in dashboard shows both ## Features - Two fixed accounts (credentials in env), password stored only as a **bcrypt hash**. -- Either user can create a shared folder with an optional description and emoji or image cover. The author can select several shared folders when creating or editing a wish. Active and fulfilled wishes also appear in All and in their author's list. The dashboard can hide fulfilled wishes across these views. +- Either user can create a shared folder with an optional description and emoji or image cover. The author can select several shared folders and their own folder when creating or editing a wish. Active and fulfilled wishes always appear in All. The dashboard can hide fulfilled wishes across these views. - Wish entity: title, price, currency, link, comment, image (auto-fetched from link or uploaded). - Statuses: **Active → Archive / Fulfilled → Trash** (kept for 30 days, then permanently removed by a daily cron job). - Restore from archive or trash. Duplicate from fulfilled into a new active wish. @@ -234,7 +234,7 @@ All responses are JSON. Authenticated endpoints require the `fw_auth` cookie. | POST | `/api/public/:slug/views` | — | Body `{ wishIds: [] }`. Marks as seen. | | GET | `/api/health`, `/api/version` | — | Meta. | -For create and update, `folderIds` accepts the selected shared folder IDs. An empty array removes all shared assignments. When both keys are omitted from an update, assignments are preserved. The single `folderId` input remains supported for version 0.4.0 clients. +For create and update, `folderIds` accepts the selected shared folder IDs. An empty array removes all shared assignments. When both folder ID keys are omitted from an update, assignments are preserved. Version 0.4.0 clients can still update the primary folder with `folderId`. `showInAuthorFolder` is true for existing wishes and by default for new wishes. The author can set it to false to hide the wish from their own folder. --- diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index d1883b3..c7b6186 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -78,6 +78,7 @@ model Wish { folderId String? folder WishFolder? @relation(fields: [folderId], references: [id], onDelete: SetNull) additionalFolders WishFolder[] @relation("AdditionalWishFolders") + showInAuthorFolder Boolean @default(true) views GuestView[] diff --git a/apps/backend/src/modules/public/public.routes.ts b/apps/backend/src/modules/public/public.routes.ts index 67ed321..5a7dbf6 100644 --- a/apps/backend/src/modules/public/public.routes.ts +++ b/apps/backend/src/modules/public/public.routes.ts @@ -31,7 +31,7 @@ export default async function publicRoutes(app: FastifyInstance) { }) : []; const seenSet = new Set(seen.map((s) => s.wishId)); - return wishes.map(({ folderId: _folderId, ...w }) => ({ + return wishes.map(({ folderId: _folderId, showInAuthorFolder: _showInAuthorFolder, ...w }) => ({ ...w, isNewForGuest: w.status === 'ACTIVE' && !seenSet.has(w.id), })); diff --git a/apps/backend/src/modules/wishes/wishes.service.ts b/apps/backend/src/modules/wishes/wishes.service.ts index 56a56da..c4951db 100644 --- a/apps/backend/src/modules/wishes/wishes.service.ts +++ b/apps/backend/src/modules/wishes/wishes.service.ts @@ -27,11 +27,6 @@ export function withFolderIds({ additionalFolders, ...wish }: Wish & { return { ...wish, folderIds: [...folderIds] }; } -function requestedFolders(input: UpdateWishInput): string[] | undefined { - if (input.folderIds !== undefined) return [...new Set(input.folderIds)]; - if (input.folderId !== undefined) return input.folderId ? [input.folderId] : []; -} - export class WishesService { constructor(private readonly prisma: PrismaClient) {} @@ -60,7 +55,7 @@ export class WishesService { } async create(userId: string, input: CreateWishInput) { - const folderIds = requestedFolders(input) ?? []; + const folderIds = [...new Set(input.folderIds ?? (input.folderId ? [input.folderId] : []))]; await this.checkFolders(folderIds); const [folderId, ...additional] = folderIds; const wish = await this.prisma.wish.create({ @@ -69,6 +64,7 @@ export class WishesService { folderId, additionalFolders: { connect: additional.map((id) => ({ id })) }, title: input.title, + showInAuthorFolder: input.showInAuthorFolder, price: input.price ?? null, currency: input.currency ?? 'RUB', url: input.url ?? null, @@ -82,13 +78,17 @@ export class WishesService { async update(userId: string, id: string, input: UpdateWishInput) { await this.getOwned(userId, id); const data: Record = {}; - const folderIds = requestedFolders(input); - if (folderIds !== undefined) { + if (input.folderIds !== undefined) { + const folderIds = [...new Set(input.folderIds)]; await this.checkFolders(folderIds); const [folderId, ...additional] = folderIds; data.folderId = folderId ?? null; data.additionalFolders = { set: additional.map((id) => ({ id })) }; + } else if (input.folderId !== undefined) { + await this.checkFolders(input.folderId ? [input.folderId] : []); + data.folderId = input.folderId; } + if (input.showInAuthorFolder !== undefined) data.showInAuthorFolder = input.showInAuthorFolder; if (input.title !== undefined) data.title = input.title; if (input.price !== undefined) data.price = input.price ?? null; if (input.currency !== undefined) data.currency = input.currency ?? 'RUB'; @@ -154,6 +154,7 @@ export class WishesService { imageUrl: source.imageSource === 'UPLOADED' ? null : source.imageUrl, imageSource: source.imageSource === 'UPLOADED' ? 'DEFAULT' : source.imageSource, sourceWishId: source.id, + showInAuthorFolder: source.showInAuthorFolder, folderId: source.folderId, additionalFolders: { connect: source.folderIds.filter((id) => id !== source.folderId).map((id) => ({ id })), diff --git a/apps/frontend/src/components/WishForm/WishForm.tsx b/apps/frontend/src/components/WishForm/WishForm.tsx index fcd7647..661a649 100644 --- a/apps/frontend/src/components/WishForm/WishForm.tsx +++ b/apps/frontend/src/components/WishForm/WishForm.tsx @@ -51,6 +51,7 @@ export function WishForm({ mode, initial, folders, authorName, defaultFolderId, comment: initial?.comment ?? '', folderIds: initial?.folderIds ?? (initial?.folderId ? [initial.folderId] : defaultFolderId ? [defaultFolderId] : []), + showInAuthorFolder: initial?.showInAuthorFolder ?? true, }, }); @@ -105,35 +106,41 @@ export function WishForm({ mode, initial, folders, authorName, defaultFolderId,
{t('folders.field')}

- {t('folders.alwaysVisible', { name: authorName })} + {t('folders.alwaysVisible')}

- {folders && folders.length > 0 && ( - ( -
- {folders.map(({ id, name }) => { - const ids = field.value ?? []; - return ( - - ); - })} -
- )} - /> - )} +
+ + {folders && folders.length > 0 && ( + { + const ids = field.value ?? []; + return ( + <> + {folders.map(({ id, name }) => ( + + ))} + + ); + }} + /> + )} +
diff --git a/apps/frontend/src/i18n/i18n.tsx b/apps/frontend/src/i18n/i18n.tsx index 1cc4861..20294db 100644 --- a/apps/frontend/src/i18n/i18n.tsx +++ b/apps/frontend/src/i18n/i18n.tsx @@ -62,7 +62,7 @@ const translations = { 'folders.emoji': 'Эмодзи', 'folders.image': 'Изображение', 'folders.field': 'В каких папках видно желание', - 'folders.alwaysVisible': 'Всегда видно во «Все» и в папке «{name}».', + 'folders.alwaysVisible': 'Желание всегда видно во «Все».', 'folders.invalidDetails': 'Проверьте название и описание папки.', 'folders.invalidEmoji': 'Введите эмодзи для обложки.', 'folders.invalidImage': 'Выберите файл JPEG, PNG, WebP или GIF размером до 8 МБ.', @@ -196,7 +196,7 @@ const translations = { 'folders.emoji': 'Emoji', 'folders.image': 'Image', 'folders.field': 'Show wish in folders', - 'folders.alwaysVisible': 'Always visible in “All” and “{name}”.', + 'folders.alwaysVisible': 'The wish always appears in “All”.', 'folders.invalidDetails': 'Check the folder name and description.', 'folders.invalidEmoji': 'Enter an emoji for the cover.', 'folders.invalidImage': 'Choose a JPEG, PNG, WebP, or GIF file up to 8 MB.', diff --git a/apps/frontend/src/pages/DashboardPage.tsx b/apps/frontend/src/pages/DashboardPage.tsx index ce2cc54..8b55d03 100644 --- a/apps/frontend/src/pages/DashboardPage.tsx +++ b/apps/frontend/src/pages/DashboardPage.tsx @@ -64,7 +64,7 @@ export function DashboardPage() { ? data?.folders.find(({ id }) => id === selection.id) : undefined; const folderWishes = data?.wishes.filter((wish) => - selectedAuthor ? wish.userId === selectedAuthor.id + selectedAuthor ? wish.userId === selectedAuthor.id && wish.showInAuthorFolder !== false : selectedFolder ? (wish.folderIds?.includes(selectedFolder.id) ?? wish.folderId === selectedFolder.id) : true, ); diff --git a/packages/shared/src/wish.schema.ts b/packages/shared/src/wish.schema.ts index f5b7e43..9a9e2c6 100644 --- a/packages/shared/src/wish.schema.ts +++ b/packages/shared/src/wish.schema.ts @@ -24,6 +24,7 @@ export const wishSchema = z.object({ sourceWishId: z.string().nullable(), folderId: z.string().nullable().optional(), folderIds: z.array(z.string()).optional(), + showInAuthorFolder: z.boolean().optional(), isNewForGuest: z.boolean().optional(), }); @@ -32,6 +33,7 @@ export type Wish = z.infer; export const createWishSchema = z.object({ folderId: z.string().cuid().nullable().optional(), folderIds: z.array(z.string().cuid()).optional(), + showInAuthorFolder: z.boolean().optional(), title: z.string().trim().min(1).max(200), price: z .union([ -- 2.54.0