From 449d22666b63c927c50b765f74cfa4758161dcb4 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Oct 2026 15:32:12 +0000 Subject: [PATCH] =?UTF-8?q?Social=20:=20avis=20avec=20spoilers,=20commenta?= =?UTF-8?q?ires=20sous=20les=20avis,=20listes=20partag=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Spoilers : case « Contient des spoilers » dans l'éditeur d'avis (notesSpoiler, synchronisé avec la fiche) ; texte retiré de la page (pas seulement flouté) jusqu'à « Afficher le spoiler » dans les avis d'un titre et l'aperçu d'une fiche ; badge sur mon avis. - Commentaires sous les avis (≤ 500 car.) : fil avec auteur, date relative, suppression (auteur / auteur de l'avis / admin), compteur à côté des réactions, notification « review_comment » (préférence notifPrefs.comments), anti-spam 10/min côté SQL. - Listes partagées : section dans l'onglet Listes, invitations (notification + acceptation), membres, qui a ajouté quoi, quitter / retirer un membre / supprimer, ajout depuis la fiche et depuis la bibliothèque, ouverture d'un titre (ma fiche ou fiche du catalogue). - SQL : 20261009130000_review_spoilers_comments.sql et 20261009130100_shared_lists.sql (RLS, aucun accès direct aux tables, fonctions security definer + search_path vide). - Tout se masque sans compte ou si les migrations ne sont pas encore appliquées. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe --- src/App.tsx | 2 +- src/components/ListsView.tsx | 4 + src/components/social/CommentsSheet.tsx | 26 + src/components/social/ItemPeek.tsx | 8 +- src/components/social/Notifications.tsx | 137 +++- src/components/social/ReviewComments.tsx | 245 +++++++ src/components/social/ReviewText.tsx | 57 ++ src/components/social/SharedListPicker.tsx | 79 +++ src/components/social/SharedLists.tsx | 613 ++++++++++++++++++ src/components/social/SocialProvider.tsx | 85 ++- src/components/social/TitleReviews.tsx | 8 +- src/components/title/ReviewEditor.tsx | 30 +- src/components/title/TitleSheet.tsx | 35 +- src/i18n/locales/ar.ts | 73 +++ src/i18n/locales/de.ts | 65 ++ src/i18n/locales/en.ts | 65 ++ src/i18n/locales/es.ts | 65 ++ src/i18n/locales/fr.ts | 65 ++ src/i18n/locales/hi.ts | 65 ++ src/i18n/locales/id.ts | 65 ++ src/i18n/locales/it.ts | 65 ++ src/i18n/locales/ja.ts | 65 ++ src/i18n/locales/ko.ts | 65 ++ src/i18n/locales/nl.ts | 65 ++ src/i18n/locales/pl.ts | 69 ++ src/i18n/locales/pt.ts | 65 ++ src/i18n/locales/ru.ts | 69 ++ src/i18n/locales/th.ts | 65 ++ src/i18n/locales/tr.ts | 65 ++ src/i18n/locales/vi.ts | 65 ++ src/i18n/locales/zh.ts | 65 ++ src/lib/backup.ts | 3 +- src/lib/catalogApi.ts | 8 + src/lib/cloud/comments.ts | 96 +++ src/lib/cloud/notifications.ts | 17 +- src/lib/cloud/reviews.ts | 6 + src/lib/cloud/sharedLists.ts | 210 ++++++ src/pages/SettingsPage.tsx | 2 + src/types.ts | 6 + ...0261009130000_review_spoilers_comments.sql | 233 +++++++ .../20261009130100_shared_lists.sql | 418 ++++++++++++ 41 files changed, 3487 insertions(+), 27 deletions(-) create mode 100644 src/components/social/CommentsSheet.tsx create mode 100644 src/components/social/ReviewComments.tsx create mode 100644 src/components/social/ReviewText.tsx create mode 100644 src/components/social/SharedListPicker.tsx create mode 100644 src/components/social/SharedLists.tsx create mode 100644 src/lib/cloud/comments.ts create mode 100644 src/lib/cloud/sharedLists.ts create mode 100644 supabase/migrations/20261009130000_review_spoilers_comments.sql create mode 100644 supabase/migrations/20261009130100_shared_lists.sql diff --git a/src/App.tsx b/src/App.tsx index 01a12ce..682b14d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -67,7 +67,7 @@ export default function App() { } return ( - + setOpened({ seed })}>
diff --git a/src/components/ListsView.tsx b/src/components/ListsView.tsx index 37500aa..34c0e30 100644 --- a/src/components/ListsView.tsx +++ b/src/components/ListsView.tsx @@ -9,6 +9,7 @@ import ConfirmDialog from './ConfirmDialog' import { MediaCard } from './MediaCard' import Poster from './Poster' import { EmptyState } from './ui' +import { SharedListsSection } from './social/SharedLists' /** Mosaïque 2×2 des premières affiches d'une liste. */ function Mosaic({ items }: { items: MediaItem[] }) { @@ -228,6 +229,9 @@ export default function ListsView({ onOpen }: { onOpen: (item: MediaItem) => voi })}
)} + + {/* Listes partagées avec d'autres membres (compte requis ; masqué sinon) */} + ) } diff --git a/src/components/social/CommentsSheet.tsx b/src/components/social/CommentsSheet.tsx new file mode 100644 index 0000000..0e17f04 --- /dev/null +++ b/src/components/social/CommentsSheet.tsx @@ -0,0 +1,26 @@ +import { t } from '../../i18n' +import { useMedia } from '../../store' +import ReviewComments from './ReviewComments' +import ReviewText from './ReviewText' +import Sheet from './Sheet' + +/** Commentaires sous un de mes avis, en plein écran (ouvert depuis une notification). */ +export default function CommentsSheet({ authorId, itemId, title, onClose }: { authorId: string; itemId: string; title: string; onClose: () => void }) { + const { items } = useMedia() + // Mon avis tel qu'il est sur cet appareil (les commentaires viennent du serveur) + const mine = items.find((i) => i.id === itemId) + return ( + +
+ {mine?.notes && ( +
+

{t('form.review')}

+ +
+ )} +

{t('comments.title')}

+ +
+
+ ) +} diff --git a/src/components/social/ItemPeek.tsx b/src/components/social/ItemPeek.tsx index 5d4b2a5..8fec37e 100644 --- a/src/components/social/ItemPeek.tsx +++ b/src/components/social/ItemPeek.tsx @@ -13,6 +13,8 @@ import { StatusPill, TypeBadge } from '../Badges' import Poster from '../Poster' import Avatar from './Avatar' import Reactions from './Reactions' +import ReviewComments from './ReviewComments' +import ReviewText from './ReviewText' import { useEscape } from '../../lib/escape' export interface PeekOwner { @@ -126,10 +128,12 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow {item.endDate && item.status === 'termine' && {formatDate(item.endDate)}} {item.favorite && ♥ {t('form.favorite')}} - {item.notes &&

{item.notes}

} + {item.notes && } {canReact && review && (
- +
)} diff --git a/src/components/social/Notifications.tsx b/src/components/social/Notifications.tsx index de25875..8f604fe 100644 --- a/src/components/social/Notifications.tsx +++ b/src/components/social/Notifications.tsx @@ -1,10 +1,12 @@ -import { Loader2, Tv } from 'lucide-react' +import { Check, Loader2, MessageCircle, Tv, Users } from 'lucide-react' import { useEffect, useState } from 'react' import { t } from '../../i18n' import { listNotifications, markNotificationsRead, type AppNotification, type NotificationKind } from '../../lib/cloud/notifications' import { cx, formatDate } from '../../lib/utils' import { EmptyState } from '../ui' import Avatar from './Avatar' +import { respondToInvite } from '../../lib/cloud/sharedLists' +import { useSocial } from './SocialProvider' import Sheet from './Sheet' const PAGE = 30 @@ -18,10 +20,24 @@ const VERB: Record string> = { reaction: () => t('notif.reaction'), new_episode: () => '', new_season: () => '', + review_comment: () => t('notif.review_comment'), + shared_list_invite: () => t('notif.shared_list_invite'), } /** Liste des notifications (abonnements, réactions, nouveaux épisodes). Marque comme lues à l'ouverture. */ -export default function Notifications({ onClose, onOpenProfile, onOpenItem }: { onClose: () => void; onOpenProfile: (username: string) => void; onOpenItem: (itemId: string) => void }) { +export default function Notifications({ + onClose, + onOpenProfile, + onOpenItem, + onOpenComments, + onOpenSharedList, +}: { + onClose: () => void + onOpenProfile: (username: string) => void + onOpenItem: (itemId: string) => void + onOpenComments?: (itemId: string, title: string) => void + onOpenSharedList?: (listId: string) => void +}) { const [items, setItems] = useState(undefined) const [done, setDone] = useState(false) const [loadingMore, setLoadingMore] = useState(false) @@ -74,7 +90,7 @@ export default function Notifications({ onClose, onOpenProfile, onOpenItem }: { ) : (
    {items.map((n) => ( - + ))} {!done && (
  • @@ -89,7 +105,19 @@ export default function Notifications({ onClose, onOpenProfile, onOpenItem }: { ) } -function Row({ n, onOpenProfile, onOpenItem }: { n: AppNotification; onOpenProfile: (username: string) => void; onOpenItem: (itemId: string) => void }) { +function Row({ + n, + onOpenProfile, + onOpenItem, + onOpenComments, + onOpenSharedList, +}: { + n: AppNotification + onOpenProfile: (username: string) => void + onOpenItem: (itemId: string) => void + onOpenComments?: (itemId: string, title: string) => void + onOpenSharedList?: (listId: string) => void +}) { const unread = n.read_at === null const isEpisode = EPISODE_KINDS.includes(n.kind) const base = cx('flex items-center gap-3 border-b border-line px-4 py-3 text-start', unread && 'bg-surface-2') @@ -123,6 +151,11 @@ function Row({ n, onOpenProfile, onOpenItem }: { n: AppNotification; onOpenProfi ) } + // ── Commentaire sur mon avis / invitation à une liste partagée ── + if (n.kind === 'review_comment' || n.kind === 'shared_list_invite') { + return + } + // ── Abonnements / réactions ── const actor = n.actor const actorName = actor?.display_name ?? t('notif.someone') @@ -158,3 +191,99 @@ function Row({ n, onOpenProfile, onOpenItem }: { n: AppNotification; onOpenProfi
  • ) } + +function SocialRow({ + n, + base, + unread, + onOpenProfile, + onOpenComments, + onOpenSharedList, +}: { + n: AppNotification + base: string + unread: boolean + onOpenProfile: (username: string) => void + onOpenComments?: (itemId: string, title: string) => void + onOpenSharedList?: (listId: string) => void +}) { + const social = useSocial() + const [status, setStatus] = useState(n.invite_status) + const [busy, setBusy] = useState(false) + const actor = n.actor + const actorName = actor?.display_name ?? t('notif.someone') + const isInvite = n.kind === 'shared_list_invite' + + const respond = async (accept: boolean) => { + if (!n.item_id) return + setBusy(true) + try { + await respondToInvite(n.item_id, accept) + setStatus(accept ? 'accepted' : null) + social.bumpShared() + if (accept) onOpenSharedList?.(n.item_id) + } catch { + /* invitation expirée ou réseau : rien ne change */ + } finally { + setBusy(false) + } + } + + // Où mène un tap sur la ligne + const open = + !isInvite && n.item_id && onOpenComments + ? () => onOpenComments(n.item_id!, n.title ?? '') + : isInvite && status === 'accepted' && n.item_id && onOpenSharedList + ? () => onOpenSharedList(n.item_id!) + : null + + const text = ( + + {actorName} {VERB[n.kind]()} + {isInvite ? ( + n.title ? ( + <> + {' '} + {n.title} + + ) : ( + ` (${t('shared.expired')})` + ) + ) : n.title ? ( + ` ${t('notif.on', { title: n.title })}` + ) : ( + '' + )} + + ) + + return ( +
  • +
    + {unread &&
    +
  • + ) +} diff --git a/src/components/social/ReviewComments.tsx b/src/components/social/ReviewComments.tsx new file mode 100644 index 0000000..98620bc --- /dev/null +++ b/src/components/social/ReviewComments.tsx @@ -0,0 +1,245 @@ +import { Loader2, MessageCircle, Send, Trash2 } from 'lucide-react' +import { useEffect, useRef, useState, type ReactNode } from 'react' +import { t } from '../../i18n' +import { addReviewComment, COMMENT_MAX, CommentsUnavailable, deleteReviewComment, getReviewComments, type ReviewComment } from '../../lib/cloud/comments' +import { timeAgo } from '../../lib/timeAgo' +import { cx } from '../../lib/utils' +import Avatar from './Avatar' +import { useSocial } from './SocialProvider' + +/** + * Bouton « commentaires » (avec leur nombre) placé à côté des réactions, et fil de commentaires + * qui s'ouvre sous l'avis. `children` = les autres actions de la ligne (réactions). + */ +export default function ReviewComments({ + authorId, + itemId, + count: initialCount, + defaultOpen, + hidden, + children, +}: { + authorId: string + itemId: string + /** Nombre connu (sinon chargé à l'ouverture) */ + count?: number | null + defaultOpen?: boolean + /** Serveur sans les commentaires (migration pas encore appliquée) : seules les autres actions s'affichent */ + hidden?: boolean + children?: ReactNode +}) { + const social = useSocial() + const [open, setOpen] = useState(!!defaultOpen) + const [count, setCount] = useState(initialCount ?? undefined) + const [comments, setComments] = useState() + const [unavailable, setUnavailable] = useState(false) + const [loadError, setLoadError] = useState(false) + + // Fil chargé à l'ouverture (ou tout de suite si on ne connaît pas encore le nombre) + const shouldLoad = !hidden && (open || initialCount === undefined) + useEffect(() => { + if (!shouldLoad || comments || unavailable) return + let alive = true + getReviewComments(authorId, itemId) + .then((th) => { + if (!alive) return + setComments(th.comments) + setCount(th.comments.length) + }) + .catch((e) => { + if (!alive) return + if (e instanceof CommentsUnavailable) setUnavailable(true) + else setLoadError(true) + }) + return () => { + alive = false + } + }, [shouldLoad, comments, unavailable, authorId, itemId]) + + if (!social.enabled || hidden) return <>{children} + + return ( +
    +
    + {children} + {!unavailable && ( + + )} +
    + {open && !unavailable && ( + { + const c = await addReviewComment(authorId, itemId, body) + setComments((prev) => [...(prev ?? []), c]) + setCount((n) => (n ?? 0) + 1) + }} + onDelete={async (id) => { + await deleteReviewComment(id) + setComments((prev) => prev?.filter((c) => c.id !== id)) + setCount((n) => Math.max(0, (n ?? 1) - 1)) + }} + /> + )} +
    + ) +} + +function Thread({ + comments, + error, + onOpenProfile, + onAdd, + onDelete, +}: { + comments?: ReviewComment[] + error: boolean + onOpenProfile: (username: string) => void + onAdd: (body: string) => Promise + onDelete: (id: number) => Promise +}) { + const [text, setText] = useState('') + const [busy, setBusy] = useState(false) + const [err, setErr] = useState() + const [confirmId, setConfirmId] = useState() + const [deleting, setDeleting] = useState() + const area = useRef(null) + + const submit = async () => { + const body = text.trim() + if (!body || busy) return + setBusy(true) + setErr(undefined) + try { + await onAdd(body) + setText('') + if (area.current) area.current.style.height = '' + } catch (e) { + setErr((e as Error).message) + } finally { + setBusy(false) + } + } + + const remove = async (id: number) => { + setDeleting(id) + try { + await onDelete(id) + } catch (e) { + setErr((e as Error).message) + } finally { + setDeleting(undefined) + setConfirmId(undefined) + } + } + + return ( +
    + {comments === undefined ? ( + error ? ( +

    {t('comments.loadError')}

    + ) : ( +

    + {t('social.loading')} +

    + ) + ) : comments.length === 0 ? ( +

    {t('comments.none')}

    + ) : ( +
      + {comments.map((c) => ( +
    • + +
      +
      + + {timeAgo(c.createdAt)} + {c.canDelete && confirmId !== c.id && ( + + )} +
      +

      {c.body}

      + {confirmId === c.id && ( +
      + {t('comments.deleteConfirm')} + + +
      + )} +
      +
    • + ))} +
    + )} + +
    { + e.preventDefault() + void submit() + }} + > +