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() + }} + > +