Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a2aaa5b5c | ||
|
|
3d2cdd4774 |
No files matched your search
@@ -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.
|
||||
@@ -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/<slug>` 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/<slug>` 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:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@family-wishlist/backend",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@family-wishlist/frontend",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -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<{
|
||||
|
||||
@@ -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<HTMLButtonElement>(null);
|
||||
const grid = useRef<HTMLDivElement>(null);
|
||||
|
||||
function close() {
|
||||
setOpen(false);
|
||||
trigger.current?.focus();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="field" onKeyDown={(event) => {
|
||||
if (event.key === 'Escape' && open) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
close();
|
||||
}
|
||||
}}>
|
||||
<span id="folder-emoji-label" className="field__label">{t('folders.emoji')}</span>
|
||||
<Button
|
||||
ref={trigger}
|
||||
variant="outline"
|
||||
className="justify-between"
|
||||
aria-labelledby="folder-emoji-label folder-emoji-value"
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? 'folder-emoji-panel' : undefined}
|
||||
onClick={() => setOpen(!open)}
|
||||
>
|
||||
<span id="folder-emoji-value" className="flex items-center gap-2">
|
||||
{value ? <span className="emoji-picker__symbol">{value}</span> : <><Smile className="h-4 w-4" aria-hidden />{t('emoji.choose')}</>}
|
||||
</span>
|
||||
<ChevronDown className="h-4 w-4" aria-hidden />
|
||||
</Button>
|
||||
{open && (
|
||||
<div id="folder-emoji-panel" className="emoji-picker">
|
||||
<div className="emoji-picker__categories" role="group" aria-label={t('emoji.categories')}>
|
||||
{categories.map((category) => (
|
||||
<Button key={category.label} variant="ghost" className="emoji-picker__category" size="icon"
|
||||
aria-label={t(category.label)} aria-pressed={category === active}
|
||||
onClick={() => { setActive(category); if (grid.current) grid.current.scrollTop = 0; }}
|
||||
>
|
||||
<span className="emoji-picker__symbol" aria-hidden="true">{category.icon}</span>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
<div ref={grid} className="emoji-picker__grid" role="group" aria-label={t(active.label)}>
|
||||
{active.symbols.split(' ').map((emoji) => (
|
||||
<Button key={emoji} variant="ghost" className="emoji-picker__option" size="icon"
|
||||
aria-pressed={emoji === value} onClick={() => { onChange(emoji); close(); }}
|
||||
>
|
||||
<span className="emoji-picker__symbol">{emoji}</span>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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<string>();
|
||||
|
||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||
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 (
|
||||
<form className="wish-folders__form" onSubmit={submit} aria-busy={create.isPending}>
|
||||
<form className="wish-folders__form" onSubmit={submit} aria-busy={pending}>
|
||||
<div className="field">
|
||||
<Label htmlFor="folder-name">{t('folders.name')}</Label>
|
||||
<Input id="folder-name" name="name" maxLength={80} autoFocus required />
|
||||
<Input id="folder-name" name="name" maxLength={80} defaultValue={folder?.name} autoFocus required />
|
||||
</div>
|
||||
<div className="field">
|
||||
<Label htmlFor="folder-description">{t('folders.description')}</Label>
|
||||
<Textarea id="folder-description" name="description" maxLength={500} rows={2} />
|
||||
<Textarea id="folder-description" name="description" maxLength={500} rows={2} defaultValue={folder?.description ?? undefined} />
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{!folder && <div className="grid items-start gap-3 sm:grid-cols-2">
|
||||
<div className="field">
|
||||
<Label htmlFor="folder-cover-type">{t('folders.cover')}</Label>
|
||||
<select
|
||||
@@ -80,10 +89,7 @@ export function FolderForm({
|
||||
</select>
|
||||
</div>
|
||||
{coverType === 'emoji' && (
|
||||
<div className="field">
|
||||
<Label htmlFor="folder-emoji">{t('folders.emoji')}</Label>
|
||||
<Input id="folder-emoji" name="emoji" placeholder="🎁" maxLength={32} required />
|
||||
</div>
|
||||
<EmojiPicker value={emoji} onChange={(value) => { setEmoji(value); setError(undefined); }} />
|
||||
)}
|
||||
{coverType === 'image' && (
|
||||
<div className="field">
|
||||
@@ -91,14 +97,14 @@ export function FolderForm({
|
||||
<Input id="folder-cover-file" name="cover" type="file" accept={coverTypes} required />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>}
|
||||
{error && <p role="alert" className="field__error">{error}</p>}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit" disabled={create.isPending}>
|
||||
<FolderPlus className="h-4 w-4" aria-hidden />
|
||||
{t('folders.create')}
|
||||
<Button type="submit" disabled={pending}>
|
||||
{!folder && <FolderPlus className="h-4 w-4" aria-hidden />}
|
||||
{t(folder ? 'common.save' : 'folders.create')}
|
||||
</Button>
|
||||
<Button variant="ghost" onClick={onCancel} disabled={create.isPending}>
|
||||
<Button variant="ghost" onClick={onCancel} disabled={pending}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import type {
|
||||
CreateFolderInput,
|
||||
CreateWishInput,
|
||||
UpdateFolderInput,
|
||||
UpdateWishInput,
|
||||
WishDashboard,
|
||||
WishFolder,
|
||||
@@ -61,6 +62,28 @@ export function useCreateFolder() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateFolder() {
|
||||
const client = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, input }: { id: string; input: UpdateFolderInput }) =>
|
||||
api.patch<WishFolder>(`/api/folders/${encodeURIComponent(id)}`, input),
|
||||
onSuccess: (folder) => {
|
||||
client.setQueryData<WishDashboard>(DASHBOARD_KEY, (current) =>
|
||||
current && { ...current, folders: current.folders.map((item) => item.id === folder.id ? folder : item) },
|
||||
);
|
||||
void client.invalidateQueries({ queryKey: DASHBOARD_KEY });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteFolder() {
|
||||
const client = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete<void>(`/api/folders/${encodeURIComponent(id)}`),
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: DASHBOARD_KEY }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateWish() {
|
||||
const client = useQueryClient();
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -50,11 +50,22 @@ const translations = {
|
||||
'dashboard.emptyTitle': 'Желаний пока нет',
|
||||
'dashboard.loadError': 'Не удалось загрузить список желаний.',
|
||||
'dashboard.retry': 'Повторить',
|
||||
'dashboard.hideCompleted': 'Скрыть исполненные',
|
||||
'dashboard.completedHidden': 'Исполненные желания скрыты',
|
||||
'folders.title': 'Папки желаний',
|
||||
'folders.all': 'Все',
|
||||
'folders.create': 'Создать папку',
|
||||
'folders.edit': 'Редактировать',
|
||||
'folders.delete': 'Удалить папку',
|
||||
'folders.deleteDescription': 'Папка будет удалена у обоих пользователей. Желания из неё сохранятся.',
|
||||
'folders.deleteError': 'Не удалось удалить папку. Попробуйте ещё раз.',
|
||||
'emoji.choose': 'Выбрать эмодзи',
|
||||
'emoji.categories': 'Категории эмодзи',
|
||||
'emoji.faces': 'Лица и жесты',
|
||||
'emoji.nature': 'Природа',
|
||||
'emoji.food': 'Еда и напитки',
|
||||
'emoji.activities': 'Занятия',
|
||||
'emoji.travel': 'Путешествия',
|
||||
'emoji.objects': 'Предметы',
|
||||
'emoji.symbols': 'Символы',
|
||||
'folders.name': 'Название',
|
||||
'folders.description': 'Описание (необязательно)',
|
||||
'folders.cover': 'Обложка',
|
||||
@@ -62,17 +73,15 @@ const translations = {
|
||||
'folders.emoji': 'Эмодзи',
|
||||
'folders.image': 'Изображение',
|
||||
'folders.field': 'В каких папках видно желание',
|
||||
'folders.alwaysVisible': 'Желание всегда видно во «Все».',
|
||||
'folders.alwaysVisible': 'Пока желание активно, оно видно во «Все». После исполнения оно появится в «Исполненных».',
|
||||
'folders.invalidDetails': 'Проверьте название и описание папки.',
|
||||
'folders.invalidEmoji': 'Введите эмодзи для обложки.',
|
||||
'folders.invalidEmoji': 'Выберите эмодзи для обложки.',
|
||||
'folders.invalidImage': 'Выберите файл JPEG, PNG, WebP или GIF размером до 8 МБ.',
|
||||
'folders.saveError': 'Не удалось создать папку. Попробуйте ещё раз.',
|
||||
'folders.saveError': 'Не удалось сохранить папку. Попробуйте ещё раз.',
|
||||
'archive.title': 'Архив',
|
||||
'archive.description': 'Отложенные желания. Их видите только вы, и их можно вернуть в активный список.',
|
||||
'archive.emptyTitle': 'Архив пуст',
|
||||
'archive.emptyText': 'Архивированные желания появятся здесь.',
|
||||
'completed.title': 'Исполненные',
|
||||
'completed.description': 'Желания, которые уже исполнились. Из любого можно создать новое.',
|
||||
'completed.emptyTitle': 'Исполненных желаний пока нет',
|
||||
'completed.emptyText': 'Когда желание исполнится, отметьте его, и оно появится здесь.',
|
||||
'trash.title': 'Корзина',
|
||||
@@ -184,11 +193,22 @@ 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',
|
||||
'folders.edit': 'Edit folder',
|
||||
'folders.delete': 'Delete folder',
|
||||
'folders.deleteDescription': 'This removes the folder for both users. Its wishes will remain.',
|
||||
'folders.deleteError': 'Could not delete the folder. Try again.',
|
||||
'emoji.choose': 'Choose an emoji',
|
||||
'emoji.categories': 'Emoji categories',
|
||||
'emoji.faces': 'Faces and gestures',
|
||||
'emoji.nature': 'Nature',
|
||||
'emoji.food': 'Food and drink',
|
||||
'emoji.activities': 'Activities',
|
||||
'emoji.travel': 'Travel',
|
||||
'emoji.objects': 'Objects',
|
||||
'emoji.symbols': 'Symbols',
|
||||
'folders.name': 'Name',
|
||||
'folders.description': 'Description (optional)',
|
||||
'folders.cover': 'Cover',
|
||||
@@ -196,17 +216,15 @@ const translations = {
|
||||
'folders.emoji': 'Emoji',
|
||||
'folders.image': 'Image',
|
||||
'folders.field': 'Show wish in folders',
|
||||
'folders.alwaysVisible': 'The wish always appears in “All”.',
|
||||
'folders.alwaysVisible': 'Active wishes appear in “All”. Once fulfilled, they move to “Fulfilled”.',
|
||||
'folders.invalidDetails': 'Check the folder name and description.',
|
||||
'folders.invalidEmoji': 'Enter an emoji for the cover.',
|
||||
'folders.invalidEmoji': 'Choose an emoji for the cover.',
|
||||
'folders.invalidImage': 'Choose a JPEG, PNG, WebP, or GIF file up to 8 MB.',
|
||||
'folders.saveError': "Couldn't create the folder. Try again.",
|
||||
'folders.saveError': "Couldn't save the folder. Try again.",
|
||||
'archive.title': 'Archive',
|
||||
'archive.description': 'Wishes you put aside. Only you see this. Restore them to your active list any time.',
|
||||
'archive.emptyTitle': 'Archive is empty',
|
||||
'archive.emptyText': 'Archived wishes will show up here.',
|
||||
'completed.title': 'Fulfilled',
|
||||
'completed.description': "Wishes you've received. You can create a new wish based on any of them.",
|
||||
'completed.emptyTitle': 'Nothing fulfilled yet',
|
||||
'completed.emptyText': 'When a wish comes true, mark it as fulfilled and it lands here.',
|
||||
'trash.title': 'Trash',
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { CheckCircle2 } from 'lucide-react';
|
||||
import { WishCard } from '@/components/WishCard/WishCard';
|
||||
import {
|
||||
useDeleteWish,
|
||||
useDuplicateWish,
|
||||
useWishes,
|
||||
} from '@/features/wishes/wishes.hooks';
|
||||
import { useI18n } from '@/i18n/i18n';
|
||||
|
||||
export function CompletedPage() {
|
||||
const { t } = useI18n();
|
||||
const { data, isLoading } = useWishes('completed');
|
||||
const duplicate = useDuplicateWish();
|
||||
const remove = useDeleteWish();
|
||||
|
||||
return (
|
||||
<div className="grid gap-6">
|
||||
<section className="page-section">
|
||||
<h1 className="page-section__title">{t('completed.title')}</h1>
|
||||
<p className="page-section__text">
|
||||
{t('completed.description')}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{isLoading && <div className="text-muted">{t('common.loading')}</div>}
|
||||
|
||||
{!isLoading && data && data.length === 0 && (
|
||||
<div className="empty-state">
|
||||
<CheckCircle2 className="empty-state__icon" />
|
||||
<h2 className="empty-state__title">{t('completed.emptyTitle')}</h2>
|
||||
<p className="empty-state__text">
|
||||
{t('completed.emptyText')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data && data.length > 0 && (
|
||||
<div className="grid gap-5 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{data.map((wish) => (
|
||||
<WishCard
|
||||
key={wish.id}
|
||||
wish={wish}
|
||||
view="owner"
|
||||
onDuplicate={() => duplicate.mutate(wish.id)}
|
||||
onDelete={() => remove.mutate(wish.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import { useRef, useState, type ReactNode } from 'react';
|
||||
import { Folder, FolderPlus, LayoutGrid, Plus, UserRound } from 'lucide-react';
|
||||
import type { Wish } from '@family-wishlist/shared';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { CheckCircle2, Folder, FolderPlus, LayoutGrid, Pencil, Plus, Trash2, UserRound } from 'lucide-react';
|
||||
import type { Wish, WishFolder } from '@family-wishlist/shared';
|
||||
import { Link, useSearchParams } from 'react-router-dom';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { WishCard } from '@/components/WishCard/WishCard';
|
||||
import { FolderForm } from '@/components/WishForm/FolderForm';
|
||||
import { WishForm } from '@/components/WishForm/WishForm';
|
||||
import {
|
||||
useArchiveWish,
|
||||
useCompleteWish,
|
||||
useDeleteFolder,
|
||||
useDeleteWish,
|
||||
useDuplicateWish,
|
||||
useWishDashboard,
|
||||
@@ -46,7 +48,10 @@ export function DashboardPage() {
|
||||
const { t } = useI18n();
|
||||
const { data, isPending, isError, refetch } = useWishDashboard();
|
||||
const [selection, setSelection] = useState<Selection>({ type: 'all' });
|
||||
const [hideCompleted, setHideCompleted] = useState(false);
|
||||
const [params, setParams] = useSearchParams();
|
||||
const showCompleted = params.get('folder') === 'completed';
|
||||
const [editingFolderId, setEditingFolderId] = useState<string>();
|
||||
const [folderToDelete, setFolderToDelete] = useState<WishFolder>();
|
||||
const [creatingFolder, setCreatingFolder] = useState(false);
|
||||
const [creatingWish, setCreatingWish] = useState(false);
|
||||
const [editing, setEditing] = useState<Wish | null>(null);
|
||||
@@ -54,25 +59,39 @@ export function DashboardPage() {
|
||||
const archive = useArchiveWish();
|
||||
const complete = useCompleteWish();
|
||||
const remove = useDeleteWish();
|
||||
const removeFolder = useDeleteFolder();
|
||||
const duplicate = useDuplicateWish();
|
||||
const user = useAuthStore((state) => state.user);
|
||||
|
||||
const selectedAuthor = selection.type === 'author'
|
||||
const selectedAuthor = !showCompleted && selection.type === 'author'
|
||||
? data?.authors.find(({ id }) => id === selection.id)
|
||||
: undefined;
|
||||
const selectedFolder = selection.type === 'folder'
|
||||
const selectedFolder = !showCompleted && selection.type === 'folder'
|
||||
? data?.folders.find(({ id }) => id === selection.id)
|
||||
: undefined;
|
||||
const folderWishes = data?.wishes.filter((wish) =>
|
||||
selectedAuthor ? wish.userId === selectedAuthor.id && wish.showInAuthorFolder !== false
|
||||
: 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');
|
||||
const wishes = data?.wishes.filter((wish) => {
|
||||
if (showCompleted) return wish.status === 'COMPLETED';
|
||||
if (wish.status !== 'ACTIVE') return false;
|
||||
if (selectedAuthor) return wish.userId === selectedAuthor.id && wish.showInAuthorFolder !== false;
|
||||
if (selectedFolder) return wish.folderIds?.includes(selectedFolder.id) ?? wish.folderId === selectedFolder.id;
|
||||
return true;
|
||||
});
|
||||
const canAddWish = !showCompleted && (!selectedAuthor || selectedAuthor.id === user?.id);
|
||||
const sectionTitle = showCompleted
|
||||
? t('header.fulfilled')
|
||||
: selectedAuthor?.displayName ?? selectedFolder?.name ?? t('folders.all');
|
||||
|
||||
function selectFolder(next: Selection) {
|
||||
setEditingFolderId(undefined);
|
||||
setSelection(next);
|
||||
if (showCompleted) setParams({});
|
||||
}
|
||||
|
||||
function closeDeleteDialog() {
|
||||
if (removeFolder.isPending) return;
|
||||
setFolderToDelete(undefined);
|
||||
removeFolder.reset();
|
||||
}
|
||||
|
||||
function closeFolderForm() {
|
||||
setCreatingFolder(false);
|
||||
@@ -103,7 +122,7 @@ export function DashboardPage() {
|
||||
ref={createFolderButton}
|
||||
variant="ghost"
|
||||
aria-expanded={creatingFolder}
|
||||
onClick={() => setCreatingFolder(true)}
|
||||
onClick={() => { setEditingFolderId(undefined); setCreatingFolder(true); }}
|
||||
>
|
||||
<FolderPlus className="h-4 w-4" aria-hidden />
|
||||
{t('folders.create')}
|
||||
@@ -113,8 +132,8 @@ export function DashboardPage() {
|
||||
<FolderButton
|
||||
label={t('folders.all')}
|
||||
cover={<LayoutGrid className="h-4 w-4" />}
|
||||
selected={!selectedAuthor && !selectedFolder}
|
||||
onClick={() => setSelection({ type: 'all' })}
|
||||
selected={!showCompleted && !selectedAuthor && !selectedFolder}
|
||||
onClick={() => selectFolder({ type: 'all' })}
|
||||
/>
|
||||
{data.authors.map((author) => (
|
||||
<FolderButton
|
||||
@@ -124,26 +143,33 @@ export function DashboardPage() {
|
||||
? <img src={author.avatarUrl} alt="" />
|
||||
: <UserRound className="h-4 w-4" />}
|
||||
selected={selectedAuthor?.id === author.id}
|
||||
onClick={() => setSelection({ type: 'author', id: author.id })}
|
||||
onClick={() => selectFolder({ type: 'author', id: author.id })}
|
||||
/>
|
||||
))}
|
||||
<FolderButton
|
||||
label={t('header.fulfilled')}
|
||||
cover={<CheckCircle2 className="h-4 w-4" />}
|
||||
selected={showCompleted}
|
||||
onClick={() => { setEditingFolderId(undefined); setParams({ folder: 'completed' }); }}
|
||||
/>
|
||||
{data.folders.map((folder) => (
|
||||
<FolderButton
|
||||
key={folder.id}
|
||||
label={folder.name}
|
||||
cover={folder.imageUrl
|
||||
? <img src={folder.imageUrl} alt="" loading="lazy" />
|
||||
: folder.emoji ?? <Folder className="h-4 w-4" />}
|
||||
: folder.emoji ? <span className="emoji-picker__symbol">{folder.emoji}</span>
|
||||
: <Folder className="h-4 w-4" />}
|
||||
selected={selectedFolder?.id === folder.id}
|
||||
onClick={() => setSelection({ type: 'folder', id: folder.id })}
|
||||
onClick={() => selectFolder({ type: 'folder', id: folder.id })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{creatingFolder && (
|
||||
<FolderForm
|
||||
onCancel={closeFolderForm}
|
||||
onCreated={(folder) => {
|
||||
setSelection({ type: 'folder', id: folder.id });
|
||||
onSaved={(folder) => {
|
||||
selectFolder({ type: 'folder', id: folder.id });
|
||||
closeFolderForm();
|
||||
}}
|
||||
/>
|
||||
@@ -180,14 +206,21 @@ export function DashboardPage() {
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2">
|
||||
<label className="wish-checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={hideCompleted}
|
||||
onChange={(event) => setHideCompleted(event.target.checked)}
|
||||
/>
|
||||
<span>{t('dashboard.hideCompleted')}</span>
|
||||
</label>
|
||||
{selectedFolder && (
|
||||
<>
|
||||
<Button variant="outline" onClick={() => {
|
||||
setCreatingFolder(false);
|
||||
setEditingFolderId(selectedFolder.id);
|
||||
}} aria-expanded={editingFolderId === selectedFolder.id}>
|
||||
<Pencil className="h-4 w-4" aria-hidden />
|
||||
{t('folders.edit')}
|
||||
</Button>
|
||||
<Button variant="ghost" onClick={() => setFolderToDelete(selectedFolder)}>
|
||||
<Trash2 className="h-4 w-4" aria-hidden />
|
||||
{t('folders.delete')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{canAddWish && (
|
||||
<Button onClick={() => setCreatingWish(true)}>
|
||||
<Plus className="h-4 w-4" aria-hidden />
|
||||
@@ -196,12 +229,21 @@ export function DashboardPage() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{selectedFolder && editingFolderId === selectedFolder.id && (
|
||||
<FolderForm
|
||||
key={selectedFolder.id}
|
||||
folder={selectedFolder}
|
||||
onCancel={() => setEditingFolderId(undefined)}
|
||||
onSaved={() => setEditingFolderId(undefined)}
|
||||
/>
|
||||
)}
|
||||
{wishes.length === 0 ? (
|
||||
<div className="empty-state">
|
||||
<img src="/empty-state.svg" alt="" className="empty-state__icon--image" />
|
||||
<h3 className="empty-state__title">
|
||||
{t(folderWishes?.length ? 'dashboard.completedHidden' : 'dashboard.emptyTitle')}
|
||||
{t(showCompleted ? 'completed.emptyTitle' : 'dashboard.emptyTitle')}
|
||||
</h3>
|
||||
{showCompleted && <p className="empty-state__text">{t('completed.emptyText')}</p>}
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid gap-5 sm:grid-cols-2 lg:grid-cols-3">
|
||||
@@ -231,6 +273,32 @@ export function DashboardPage() {
|
||||
</section>
|
||||
)}
|
||||
|
||||
{folderToDelete && (
|
||||
<Modal
|
||||
open
|
||||
onClose={closeDeleteDialog}
|
||||
title={`${t('folders.delete')} · ${folderToDelete.name}`}
|
||||
description={t('folders.deleteDescription')}
|
||||
footer={(
|
||||
<>
|
||||
<Button autoFocus variant="ghost" onClick={closeDeleteDialog} disabled={removeFolder.isPending}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button variant="danger" disabled={removeFolder.isPending} onClick={() => {
|
||||
removeFolder.mutate(folderToDelete.id, { onSuccess: () => {
|
||||
selectFolder({ type: 'all' });
|
||||
setFolderToDelete(undefined);
|
||||
createFolderButton.current?.focus();
|
||||
} });
|
||||
}}>
|
||||
{t('folders.delete')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
{removeFolder.isError && <p role="alert" className="field__error">{t('folders.deleteError')}</p>}
|
||||
</Modal>
|
||||
)}
|
||||
{creatingWish && user && (
|
||||
<WishForm
|
||||
mode="create"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Navigate, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { Navigate, useLocation, useNavigate, type Location } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { Gift, Loader2 } from 'lucide-react';
|
||||
@@ -19,7 +19,7 @@ export function LoginPage() {
|
||||
const { user, login } = useAuthStore();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const from = (location.state as { from?: { pathname: string } } | null)?.from?.pathname ?? '/';
|
||||
const from = (location.state as { from?: Pick<Location, 'pathname' | 'search' | 'hash'> } | null)?.from ?? '/';
|
||||
|
||||
const {
|
||||
register,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { createBrowserRouter, type RouterProviderProps } from 'react-router-dom';
|
||||
import { createBrowserRouter, Navigate, type RouterProviderProps } from 'react-router-dom';
|
||||
import { ProtectedRoute } from './components/Layout/ProtectedRoute';
|
||||
import { AppShell } from './components/Layout/AppShell';
|
||||
import { LoginPage } from './pages/LoginPage';
|
||||
import { DashboardPage } from './pages/DashboardPage';
|
||||
import { ArchivePage } from './pages/ArchivePage';
|
||||
import { CompletedPage } from './pages/CompletedPage';
|
||||
import { TrashPage } from './pages/TrashPage';
|
||||
import { ProfileSettingsPage } from './pages/ProfileSettingsPage';
|
||||
import { PublicProfilePage } from './pages/PublicProfilePage';
|
||||
@@ -22,7 +21,7 @@ export const router: RouterProviderProps['router'] = createBrowserRouter([
|
||||
children: [
|
||||
{ path: '/', element: <DashboardPage /> },
|
||||
{ path: '/archive', element: <ArchivePage /> },
|
||||
{ path: '/completed', element: <CompletedPage /> },
|
||||
{ path: '/completed', element: <Navigate to="/?folder=completed" replace /> },
|
||||
{ path: '/trash', element: <TrashPage /> },
|
||||
{ path: '/settings', element: <ProfileSettingsPage /> },
|
||||
],
|
||||
|
||||
@@ -152,6 +152,29 @@
|
||||
.wish-folders__form {
|
||||
@apply grid min-w-0 max-w-xl gap-4 rounded-md border border-border bg-surface p-4;
|
||||
}
|
||||
.emoji-picker {
|
||||
@apply grid gap-2 rounded-md border border-border bg-surface p-2;
|
||||
}
|
||||
.emoji-picker__categories {
|
||||
@apply grid grid-cols-7 gap-0.5 border-b border-border pb-2;
|
||||
}
|
||||
.emoji-picker__grid {
|
||||
@apply grid max-h-48 grid-cols-6 gap-1 overflow-y-auto overscroll-contain p-1;
|
||||
}
|
||||
.emoji-picker .emoji-picker__category,
|
||||
.emoji-picker .emoji-picker__option {
|
||||
@apply h-10 w-full min-w-0 px-0;
|
||||
}
|
||||
.emoji-picker [aria-pressed='true'] {
|
||||
@apply bg-primary/10 ring-1 ring-inset ring-primary;
|
||||
}
|
||||
.emoji-picker__symbol {
|
||||
font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
|
||||
@apply text-lg leading-none;
|
||||
}
|
||||
.emoji-picker__option .emoji-picker__symbol {
|
||||
@apply text-xl;
|
||||
}
|
||||
.wish-checkbox {
|
||||
@apply inline-flex min-h-9 min-w-0 cursor-pointer items-center gap-2 text-sm text-ink;
|
||||
overflow-wrap: anywhere;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@family-wishlist/shared",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -12,6 +12,10 @@ export const createFolderSchema = z.object({
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export const updateFolderSchema = createFolderSchema.pick({ name: true, description: true }).partial().strict();
|
||||
|
||||
export type UpdateFolderInput = z.infer<typeof updateFolderSchema>;
|
||||
|
||||
export type CreateFolderInput = z.infer<typeof createFolderSchema>;
|
||||
|
||||
export interface WishFolder {
|
||||
|
||||
Reference in new issue
Block a user