diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6397838 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +## 0.6.0 + +- Both signed-in users can rename, update the description of, and delete shared folders. Deleting a folder preserves its wishes and their other assignments. +- Both users’ fulfilled wishes move to the permanent Fulfilled folder on the dashboard. All and the other dashboard folders show active wishes. Existing `/completed` links open the permanent folder. +- A categorized emoji picker displays the selected emoji in the folder creation form and on the saved folder cover. diff --git a/README.md b/README.md index 76a1b72..a06ccd8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Family Wishlist -A small, private wishlist app for two users. The signed-in dashboard shows both users' active and fulfilled wishes, with filters for each author and shared folders. Each user also has a public profile at `/u/` with their own active and fulfilled wishes. +A small, private wishlist app for two users. The signed-in dashboard shows both users' active and fulfilled wishes, in separate views for active and fulfilled wishes. Active wishes can be filtered by author or shared folder. Each user also has a public profile at `/u/` with their own active and fulfilled wishes. - **Backend**: Node.js 20, Fastify 4, Prisma 5, PostgreSQL 16 - **Frontend**: React 18, Vite 5, Tailwind CSS, TanStack Query, React Hook Form + Zod @@ -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 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. +- Either signed-in user can create, rename, update the description of, or delete a shared folder. When creating a folder, choose an emoji from the category picker or upload an image. Deleting a folder removes its assignments and preserves its wishes. The wish author can assign active wishes to several shared folders and their own folder. All shows both users’ active wishes. Fulfilled wishes from both users automatically appear in the permanent Fulfilled folder. - 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. @@ -225,6 +225,8 @@ All responses are JSON. Authenticated endpoints require the `fw_auth` cookie. | POST | `/api/wishes/:id/archive` | owner | | | POST | `/api/wishes/:id/complete` | owner | | | POST | `/api/wishes/:id/restore` | owner | From archive or trash back to active. | +| PATCH | `/api/folders/:id` | signed in | Update a shared folder name or description. | +| DELETE | `/api/folders/:id` | signed in | Remove a shared folder and its assignments. Its wishes are retained. | | POST | `/api/wishes/:id/duplicate` | owner | Copy fulfilled wish into a new active one. | | POST | `/api/wishes/:id/image` | owner | Multipart image upload. | | POST | `/api/wishes/:id/image/refresh-og` | owner | Re-fetch OG image from link. | @@ -243,7 +245,7 @@ For create and update, `folderIds` accepts the selected shared folder IDs. An em Each package has its own version (`apps/backend/package.json` and `apps/frontend/package.json`). The app footer shows both: ``` -frontend v0.5.0 · backend v0.5.0 +frontend v0.6.0 · backend v0.6.0 ``` Bump them per semver on each change: diff --git a/apps/backend/package.json b/apps/backend/package.json index aef9aae..cbe4256 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -1,6 +1,6 @@ { "name": "@family-wishlist/backend", - "version": "0.5.0", + "version": "0.6.0", "private": true, "type": "module", "main": "dist/index.js", diff --git a/apps/backend/src/modules/wishes/dashboard.routes.ts b/apps/backend/src/modules/wishes/dashboard.routes.ts index 15d0c45..7a2d59f 100644 --- a/apps/backend/src/modules/wishes/dashboard.routes.ts +++ b/apps/backend/src/modules/wishes/dashboard.routes.ts @@ -1,12 +1,22 @@ import { randomUUID } from 'node:crypto'; +import { Prisma } from '@prisma/client'; import type { FastifyInstance } from 'fastify'; -import { createFolderSchema, NEW_BADGE_DAYS } from '@family-wishlist/shared'; +import { createFolderSchema, NEW_BADGE_DAYS, updateFolderSchema } from '@family-wishlist/shared'; import { usersRegistry } from '../../auth/users.registry.js'; import { MAX_UPLOAD_BYTES } from '../../plugins/multipart.js'; -import { UnauthorizedError, ValidationError } from '../../utils/errors.js'; +import { NotFoundError, UnauthorizedError, ValidationError } from '../../utils/errors.js'; import { deleteLocalImageIfAny, saveUploadedImage } from '../images/storage.service.js'; import { includeWishFolders, withFolderIds } from './wishes.service.js'; +const folderSelect = { id: true, name: true, description: true, emoji: true, imageUrl: true } as const; + +function rethrowFolderError(error: unknown): never { + if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === 'P2025') { + throw new NotFoundError('Folder'); + } + throw error; +} + const folderFields = ['name', 'description', 'emoji']; export default async function dashboardRoutes(app: FastifyInstance) { @@ -23,7 +33,7 @@ export default async function dashboardRoutes(app: FastifyInstance) { select: { id: true, displayName: true, avatarUrl: true }, }), app.prisma.wishFolder.findMany({ - select: { id: true, name: true, description: true, emoji: true, imageUrl: true }, + select: folderSelect, orderBy: [{ createdAt: 'asc' }, { id: 'asc' }], }), app.prisma.wish.findMany({ @@ -44,6 +54,35 @@ export default async function dashboardRoutes(app: FastifyInstance) { }; }); + app.patch<{ Params: { id: string } }>('/folders/:id', async (request) => { + const input = updateFolderSchema.parse(request.body); + try { + return await app.prisma.wishFolder.update({ + where: { id: request.params.id }, + data: { + name: input.name, + description: input.description === undefined ? undefined : input.description || null, + }, + select: folderSelect, + }); + } catch (error) { + rethrowFolderError(error); + } + }); + + app.delete<{ Params: { id: string } }>('/folders/:id', async (request, reply) => { + try { + const { imageUrl } = await app.prisma.wishFolder.delete({ + where: { id: request.params.id }, + select: { imageUrl: true }, + }); + await deleteLocalImageIfAny(imageUrl); + return reply.code(204).send(); + } catch (error) { + rethrowFolderError(error); + } + }); + app.post('/folders', async (request, reply) => { if (!request.isMultipart()) throw new ValidationError('Expected form data'); @@ -90,7 +129,7 @@ export default async function dashboardRoutes(app: FastifyInstance) { imageUrl, creatorId: request.user.id, }, - select: { id: true, name: true, description: true, emoji: true, imageUrl: true }, + select: folderSelect, }); reply.code(201); return folder; diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 23a7fea..a778c17 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@family-wishlist/frontend", - "version": "0.5.0", + "version": "0.6.0", "private": true, "type": "module", "scripts": { diff --git a/apps/frontend/src/components/Layout/Header.tsx b/apps/frontend/src/components/Layout/Header.tsx index 860a0e4..cf78285 100644 --- a/apps/frontend/src/components/Layout/Header.tsx +++ b/apps/frontend/src/components/Layout/Header.tsx @@ -1,5 +1,5 @@ import { Link, NavLink, useNavigate } from 'react-router-dom'; -import { Archive, CheckCircle2, Gift, House, LogOut, Trash2, UserCog, Users } from 'lucide-react'; +import { Archive, Gift, House, LogOut, Trash2, UserCog, Users } from 'lucide-react'; import type { ComponentType } from 'react'; import { useQuery } from '@tanstack/react-query'; import { Button } from '../ui/Button'; @@ -19,7 +19,6 @@ interface FriendProfile { const links = [ { to: '/', label: 'header.home', icon: House, end: true }, - { to: '/completed', label: 'header.fulfilled', icon: CheckCircle2 }, { to: '/archive', label: 'header.archive', icon: Archive }, { to: '/trash', label: 'header.trash', icon: Trash2 }, ] satisfies Array<{ diff --git a/apps/frontend/src/components/WishForm/EmojiPicker.tsx b/apps/frontend/src/components/WishForm/EmojiPicker.tsx new file mode 100644 index 0000000..69dcb16 --- /dev/null +++ b/apps/frontend/src/components/WishForm/EmojiPicker.tsx @@ -0,0 +1,76 @@ +import { useRef, useState } from 'react'; +import { ChevronDown, Smile } from 'lucide-react'; +import { useI18n } from '@/i18n/i18n'; +import { Button } from '../ui/Button'; + +const categories = [ + { label: 'emoji.faces', icon: '😀', symbols: '😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇 🙂 🙃 😉 😌 😍 🥰 😘 😋 😜 🤪 🤩 🤗 🤭 🤫 🤔 😎 🥳 😴 🤓 🫠 😺 😻 🙈 🙉 🙊 👍 🙌 👏 🫶 ✨' }, + { label: 'emoji.nature', icon: '🌿', symbols: '🌿 🌱 🌵 🌴 🌳 🌲 🍀 🍁 🍂 🌻 🌷 🌸 🌺 🌼 🌹 🪴 🪷 🐶 🐱 🐭 🐹 🐰 🦊 🐻 🐼 🐨 🐯 🦁 🐮 🐸 🦄 🦋 🐝 🐢 🐬 🐳 🐙 🐧 ☀️ 🌙 ⭐ 🌈 ❄️' }, + { label: 'emoji.food', icon: '🍎', symbols: '🍎 🍐 🍋 🍌 🍉 🍇 🍓 🫐 🍒 🍑 🥭 🍍 🥑 🥕 🌽 🍄 🥐 🥖 🧀 🍔 🍟 🍕 🌮 🥗 🍝 🍜 🍣 🍱 🍦 🍰 🎂 🧁 🍫 🍪 🍩 ☕ 🍵 🧋 🍷 🥂' }, + { label: 'emoji.activities', icon: '⚽', symbols: '⚽ 🏀 🏈 ⚾ 🎾 🏐 🏓 🏸 🥊 🏹 🛹 🛼 🛷 ⛸️ 🎿 🏆 🥇 🎯 🎮 🕹️ 🎲 🧩 ♟️ 🎨 🖌️ 🎭 🎤 🎧 🎸 🎹 🥁 🎬 📸 📚 🚴 🧘 🏊' }, + { label: 'emoji.travel', icon: '✈️', symbols: '✈️ 🚗 🚕 🚌 🚎 🚲 🛵 🏍️ 🚅 🚁 🚀 🛸 ⛵ 🚢 🗺️ 🧭 ⛰️ 🏔️ 🏕️ ⛺ 🏖️ 🏝️ 🏜️ 🏞️ 🗻 🌋 🌅 🌌 🏠 🏡 🏰 🗼 🗽 🎡 🎢 🛝' }, + { label: 'emoji.objects', icon: '🎁', symbols: '🎁 🎈 🎉 🎊 🪄 🎀 🛍️ 🛒 💎 💍 👑 👓 👟 👠 👗 👚 🧥 🧢 🎒 🧳 💻 📱 ⌚ 🖥️ 🔋 💡 🕯️ 🪞 🛋️ 🪑 🛏️ 🧸 🧶 🧵 🛠️ 🔑 📔 ✏️ 💌 🧴' }, + { label: 'emoji.symbols', icon: '❤️', symbols: '❤️ 🧡 💛 💚 💙 💜 🖤 🤍 🤎 🩷 🩵 🩶 💖 💝 💕 💫 💯 🔥 ✅ ✔️ ♻️ ♾️ ☮️ ☯️ 🎵 🎶 ➕ ❗ ❓ 💬 💭 💤' }, +] as const; + +export function EmojiPicker({ value, onChange }: { value: string; onChange: (emoji: string) => void }) { + const { t } = useI18n(); + const [open, setOpen] = useState(false); + const [active, setActive] = useState<(typeof categories)[number]>(categories[0]); + const trigger = useRef(null); + const grid = useRef(null); + + function close() { + setOpen(false); + trigger.current?.focus(); + } + + return ( +
{ + if (event.key === 'Escape' && open) { + event.preventDefault(); + event.stopPropagation(); + close(); + } + }}> + {t('folders.emoji')} + + {open && ( +
+
+ {categories.map((category) => ( + + ))} +
+
+ {active.symbols.split(' ').map((emoji) => ( + + ))} +
+
+ )} +
+ ); +} diff --git a/apps/frontend/src/components/WishForm/FolderForm.tsx b/apps/frontend/src/components/WishForm/FolderForm.tsx index 8e42264..db14de8 100644 --- a/apps/frontend/src/components/WishForm/FolderForm.tsx +++ b/apps/frontend/src/components/WishForm/FolderForm.tsx @@ -1,35 +1,41 @@ import { useState, type FormEvent } from 'react'; import { createFolderSchema, type WishFolder } from '@family-wishlist/shared'; import { FolderPlus } from 'lucide-react'; -import { useCreateFolder } from '@/features/wishes/wishes.hooks'; +import { useCreateFolder, useUpdateFolder } from '@/features/wishes/wishes.hooks'; import { useI18n } from '@/i18n/i18n'; import { Button } from '../ui/Button'; import { Input } from '../ui/Input'; import { Label } from '../ui/Label'; import { Textarea } from '../ui/Textarea'; +import { EmojiPicker } from './EmojiPicker'; const coverTypes = 'image/jpeg,image/png,image/webp,image/gif'; export function FolderForm({ onCancel, - onCreated, + onSaved, + folder, }: { onCancel: () => void; - onCreated: (folder: WishFolder) => void; + onSaved: (folder: WishFolder) => void; + folder?: WishFolder; }) { const { t } = useI18n(); const create = useCreateFolder(); + const update = useUpdateFolder(); + const pending = create.isPending || update.isPending; + const [emoji, setEmoji] = useState(''); const [coverType, setCoverType] = useState<'none' | 'emoji' | 'image'>('none'); const [error, setError] = useState(); async function submit(event: FormEvent) { event.preventDefault(); - if (create.isPending) return; + if (pending) return; const form = new FormData(event.currentTarget); const input = createFolderSchema.safeParse({ name: form.get('name'), description: form.get('description'), - emoji: form.get('emoji') ?? undefined, + emoji: coverType === 'emoji' ? emoji : undefined, }); const file = form.get('cover'); const cover = file instanceof File && file.size > 0 ? file : null; @@ -46,23 +52,26 @@ export function FolderForm({ } setError(undefined); try { - onCreated(await create.mutateAsync({ input: input.data, cover })); + const saved = folder + ? await update.mutateAsync({ id: folder.id, input: { name: input.data.name, description: input.data.description } }) + : await create.mutateAsync({ input: input.data, cover }); + onSaved(saved); } catch { setError(t('folders.saveError')); } } return ( -
+
- +
-