Fusion social (spoilers, commentaires, listes partagées) + raccordement à la modération
- Signalement des commentaires et des listes partagées : copie du contenu, aperçu admin et suppression branchés dans report_content / admin_reports / admin_report_action. - Un compte bloqué ne peut plus commenter mes avis (déclencheur), et ses commentaires sont masqués côté client. - La migration défis retire à la fois tags et episodeLog des fiches publiques. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
42 files changed
+3535
-35
No files matched your search
@@ -10,6 +10,7 @@ import { MediaCard } from './MediaCard'
|
||||
import Poster from './Poster'
|
||||
import { EmptyState } from './ui'
|
||||
import { useLibraryActions } from './library/useLibraryActions'
|
||||
import { SharedListsSection } from './social/SharedLists'
|
||||
|
||||
/** Mosaïque 2×2 des premières affiches d'une liste. */
|
||||
function Mosaic({ items }: { items: MediaItem[] }) {
|
||||
@@ -230,6 +231,9 @@ export default function ListsView({ onOpen }: { onOpen: (item: MediaItem) => voi
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Listes partagées avec d'autres membres (compte requis ; masqué sinon) */}
|
||||
<SharedListsSection />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<Sheet title={title || t('comments.title')} label={t('comments.title')} onClose={onClose} elevated>
|
||||
<div className="px-4 pt-4">
|
||||
{mine?.notes && (
|
||||
<article className="card mb-4 p-3.5">
|
||||
<p className="eyebrow">{t('form.review')}</p>
|
||||
<ReviewText text={mine.notes} spoiler={mine.notesSpoiler} revealed clamp />
|
||||
</article>
|
||||
)}
|
||||
<p className="eyebrow mb-1">{t('comments.title')}</p>
|
||||
<ReviewComments authorId={authorId} itemId={itemId} defaultOpen />
|
||||
</div>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import Poster from '../Poster'
|
||||
import ReportButton from '../moderation/ReportButton'
|
||||
import Avatar from './Avatar'
|
||||
import Reactions from './Reactions'
|
||||
import ReviewComments from './ReviewComments'
|
||||
import ReviewText from './ReviewText'
|
||||
import { useEscape } from '../../lib/escape'
|
||||
|
||||
export interface PeekOwner {
|
||||
@@ -128,10 +130,12 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
|
||||
{item.endDate && item.status === 'termine' && <span>{formatDate(item.endDate)}</span>}
|
||||
{item.favorite && <span className="text-accent">♥ {t('form.favorite')}</span>}
|
||||
</div>
|
||||
{item.notes && <p className="mt-3 whitespace-pre-line text-sm leading-relaxed text-ink-2">{item.notes}</p>}
|
||||
{item.notes && <ReviewText text={item.notes} spoiler={item.notesSpoiler} className="mt-3" />}
|
||||
{canReact && review && (
|
||||
<div className="mt-3 border-t border-line pt-3">
|
||||
<Reactions authorId={review.user_id} itemId={review.item_id} reactions={review.reactions} mine={review.mine} />
|
||||
<ReviewComments authorId={review.user_id} itemId={review.item_id} count={review.comments} hidden={review.comments === null}>
|
||||
<Reactions authorId={review.user_id} itemId={review.item_id} reactions={review.reactions} mine={review.mine} />
|
||||
</ReviewComments>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -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<NotificationKind, () => 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<AppNotification[] | undefined>(undefined)
|
||||
const [done, setDone] = useState(false)
|
||||
const [loadingMore, setLoadingMore] = useState(false)
|
||||
@@ -74,7 +90,7 @@ export default function Notifications({ onClose, onOpenProfile, onOpenItem }: {
|
||||
) : (
|
||||
<ul>
|
||||
{items.map((n) => (
|
||||
<Row key={n.id} n={n} onOpenProfile={onOpenProfile} onOpenItem={onOpenItem} />
|
||||
<Row key={n.id} n={n} onOpenProfile={onOpenProfile} onOpenItem={onOpenItem} onOpenComments={onOpenComments} onOpenSharedList={onOpenSharedList} />
|
||||
))}
|
||||
{!done && (
|
||||
<li className="p-4">
|
||||
@@ -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 <SocialRow n={n} base={base} unread={unread} onOpenProfile={onOpenProfile} onOpenComments={onOpenComments} onOpenSharedList={onOpenSharedList} />
|
||||
}
|
||||
|
||||
// ── 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
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
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 = (
|
||||
<span className="min-w-0 flex-1 text-sm leading-snug text-ink-2">
|
||||
<b className="text-ink">{actorName}</b> {VERB[n.kind]()}
|
||||
{isInvite ? (
|
||||
n.title ? (
|
||||
<>
|
||||
{' '}
|
||||
<b className="text-ink">{n.title}</b>
|
||||
</>
|
||||
) : (
|
||||
` (${t('shared.expired')})`
|
||||
)
|
||||
) : n.title ? (
|
||||
` ${t('notif.on', { title: n.title })}`
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
|
||||
return (
|
||||
<li>
|
||||
<div className={cx(base, 'flex-wrap')}>
|
||||
{unread && <span className="size-2 shrink-0 rounded-full bg-accent-fill" aria-hidden="true" />}
|
||||
<button type="button" onClick={() => actor && onOpenProfile(actor.username)} className="shrink-0" aria-label={actorName} disabled={!actor}>
|
||||
<Avatar url={actor?.avatar_url ?? undefined} name={actorName} size={38} />
|
||||
</button>
|
||||
{open ? (
|
||||
<button type="button" onClick={open} className="flex min-w-0 flex-1 items-center gap-2 text-start">
|
||||
{isInvite ? <Users size={14} className="shrink-0 text-accent" aria-hidden="true" /> : <MessageCircle size={14} className="shrink-0 text-accent" aria-hidden="true" />}
|
||||
{text}
|
||||
</button>
|
||||
) : (
|
||||
text
|
||||
)}
|
||||
<span className="shrink-0 text-xs text-ink-3">{formatDate(n.created_at)}</span>
|
||||
{isInvite && status === 'pending' && n.title && (
|
||||
<div className="flex w-full justify-end gap-2 ps-[3.25rem]">
|
||||
<button type="button" onClick={() => void respond(false)} disabled={busy} className="btn btn-ghost px-3.5 py-1.5 text-sm">
|
||||
{t('shared.decline')}
|
||||
</button>
|
||||
<button type="button" onClick={() => void respond(true)} disabled={busy} className="btn btn-primary px-3.5 py-1.5 text-sm">
|
||||
{busy ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} />} {t('shared.accept')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
import { Loader2, MessageCircle, Send, Trash2 } from 'lucide-react'
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { useBlocked } from '../../lib/cloud/moderation'
|
||||
import ReportButton from '../moderation/ReportButton'
|
||||
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 { isBlocked } = useBlocked(social.enabled)
|
||||
const [open, setOpen] = useState(!!defaultOpen)
|
||||
const [count, setCount] = useState(initialCount ?? undefined)
|
||||
const [comments, setComments] = useState<ReviewComment[]>()
|
||||
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 (
|
||||
<div>
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{children}
|
||||
{!unavailable && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
aria-expanded={open}
|
||||
aria-label={t('comments.toggle', { count: count ?? 0 })}
|
||||
className={cx(
|
||||
'inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-sm transition-colors active:scale-95',
|
||||
open ? 'border-ink/60 text-ink' : 'border-line text-ink-2',
|
||||
)}
|
||||
>
|
||||
<MessageCircle size={15} aria-hidden="true" />
|
||||
{(count ?? 0) > 0 && <span className="text-xs font-medium">{count}</span>}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{open && !unavailable && (
|
||||
<Thread
|
||||
comments={comments?.filter((c) => !isBlocked(c.user.id))}
|
||||
error={loadError}
|
||||
onOpenProfile={social.openProfile}
|
||||
onAdd={async (body) => {
|
||||
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))
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Thread({
|
||||
comments,
|
||||
error,
|
||||
onOpenProfile,
|
||||
onAdd,
|
||||
onDelete,
|
||||
}: {
|
||||
comments?: ReviewComment[]
|
||||
error: boolean
|
||||
onOpenProfile: (username: string) => void
|
||||
onAdd: (body: string) => Promise<void>
|
||||
onDelete: (id: number) => Promise<void>
|
||||
}) {
|
||||
const [text, setText] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [err, setErr] = useState<string>()
|
||||
const [confirmId, setConfirmId] = useState<number>()
|
||||
const [deleting, setDeleting] = useState<number>()
|
||||
const area = useRef<HTMLTextAreaElement>(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 (
|
||||
<div className="mt-3 border-t border-line pt-3">
|
||||
{comments === undefined ? (
|
||||
error ? (
|
||||
<p className="text-xs text-ink-3">{t('comments.loadError')}</p>
|
||||
) : (
|
||||
<p className="flex items-center gap-2 text-xs text-ink-3">
|
||||
<Loader2 size={13} className="animate-spin" /> {t('social.loading')}
|
||||
</p>
|
||||
)
|
||||
) : comments.length === 0 ? (
|
||||
<p className="text-xs text-ink-3">{t('comments.none')}</p>
|
||||
) : (
|
||||
<ul className="space-y-3">
|
||||
{comments.map((c) => (
|
||||
<li key={c.id} className="flex gap-2.5">
|
||||
<button type="button" onClick={() => onOpenProfile(c.user.username)} className="shrink-0" aria-label={c.user.displayName}>
|
||||
<Avatar url={c.user.avatarUrl} name={c.user.displayName} size={28} />
|
||||
</button>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<button type="button" onClick={() => onOpenProfile(c.user.username)} className="min-w-0 truncate text-start text-[13px] font-semibold text-ink">
|
||||
{c.user.displayName}
|
||||
</button>
|
||||
<span className="shrink-0 text-[11px] text-ink-3">{timeAgo(c.createdAt)}</span>
|
||||
{c.canDelete && confirmId !== c.id && (
|
||||
<button type="button" onClick={() => setConfirmId(c.id)} className="ms-auto grid size-7 shrink-0 place-items-center rounded-full text-ink-3" aria-label={t('comments.delete')}>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
)}
|
||||
{!c.mine && <ReportButton target={{ type: 'comment', id: String(c.id), userId: c.user.id }} className={cx('size-7', !(c.canDelete && confirmId !== c.id) && 'ms-auto')} size={14} />}
|
||||
</div>
|
||||
<p className="whitespace-pre-line break-words text-sm leading-relaxed text-ink-2">{c.body}</p>
|
||||
{confirmId === c.id && (
|
||||
<div className="mt-1.5 flex items-center gap-2 text-xs">
|
||||
<span className="text-ink-3">{t('comments.deleteConfirm')}</span>
|
||||
<button type="button" onClick={() => void remove(c.id)} disabled={deleting === c.id} className="rounded-full bg-accent-fill px-2.5 py-1 font-semibold text-on-accent disabled:opacity-60">
|
||||
{deleting === c.id ? <Loader2 size={12} className="animate-spin" /> : t('common.delete')}
|
||||
</button>
|
||||
<button type="button" onClick={() => setConfirmId(undefined)} className="rounded-full border border-line px-2.5 py-1 text-ink-2">
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
<form
|
||||
className="mt-3 flex items-end gap-2"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
void submit()
|
||||
}}
|
||||
>
|
||||
<label className="min-w-0 flex-1">
|
||||
<span className="sr-only">{t('comments.placeholder')}</span>
|
||||
<textarea
|
||||
ref={area}
|
||||
rows={1}
|
||||
value={text}
|
||||
maxLength={COMMENT_MAX}
|
||||
onChange={(e) => {
|
||||
setText(e.target.value)
|
||||
// Le champ grandit avec le texte (jusqu'à ~6 lignes)
|
||||
e.target.style.height = 'auto'
|
||||
e.target.style.height = `${Math.min(e.target.scrollHeight, 160)}px`
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault()
|
||||
void submit()
|
||||
}
|
||||
}}
|
||||
placeholder={t('comments.placeholder')}
|
||||
className="field block resize-none py-2 text-sm leading-snug"
|
||||
/>
|
||||
</label>
|
||||
<button type="submit" disabled={busy || !text.trim()} className="btn btn-primary size-10 shrink-0 p-0" aria-label={t('comments.send')}>
|
||||
{busy ? <Loader2 size={16} className="animate-spin" /> : <Send size={16} className="rtl:-scale-x-100" />}
|
||||
</button>
|
||||
</form>
|
||||
{text.length > COMMENT_MAX - 100 && (
|
||||
<p className={cx('mt-1 text-end text-[11px]', text.length >= COMMENT_MAX ? 'text-accent' : 'text-ink-3')}>
|
||||
{text.length}/{COMMENT_MAX}
|
||||
</p>
|
||||
)}
|
||||
{err && (
|
||||
<p role="alert" className="mt-1.5 text-xs text-accent">
|
||||
{err}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { EyeOff } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { cx } from '../../lib/utils'
|
||||
|
||||
/**
|
||||
* Texte d'un avis. Avec spoilers : le texte n'est PAS dans la page tant qu'on n'a pas tapé
|
||||
* « Afficher le spoiler » (pas seulement flouté : rien à lire pour un lecteur d'écran ni à copier).
|
||||
*/
|
||||
export default function ReviewText({
|
||||
text,
|
||||
spoiler,
|
||||
className,
|
||||
clamp,
|
||||
revealed,
|
||||
}: {
|
||||
text: string
|
||||
spoiler?: boolean
|
||||
className?: string
|
||||
clamp?: boolean
|
||||
/** Déjà dévoilé (mon propre avis) : seul le badge « Spoiler » reste */
|
||||
revealed?: boolean
|
||||
}) {
|
||||
const [shown, setShown] = useState(!spoiler || !!revealed)
|
||||
|
||||
if (!shown) {
|
||||
return (
|
||||
<div className={cx('relative mt-2 overflow-hidden rounded-xl border border-line bg-surface-2 px-3.5 py-3', className)}>
|
||||
{/* Fausses lignes floutées : purement décoratives */}
|
||||
<div aria-hidden="true" className="space-y-2 blur-[3px]">
|
||||
<span className="block h-2.5 w-11/12 rounded-full bg-ink-3/40" />
|
||||
<span className="block h-2.5 w-4/5 rounded-full bg-ink-3/40" />
|
||||
<span className="block h-2.5 w-3/5 rounded-full bg-ink-3/40" />
|
||||
</div>
|
||||
<div className="absolute inset-0 flex flex-wrap items-center justify-center gap-x-3 gap-y-1.5 px-3">
|
||||
<span className="flex items-center gap-1.5 text-xs font-semibold text-ink-2">
|
||||
<EyeOff size={14} className="text-accent" aria-hidden="true" /> {t('spoiler.warning')}
|
||||
</span>
|
||||
<button type="button" onClick={() => setShown(true)} className="rounded-full border border-line-strong bg-surface px-3 py-1 text-xs font-semibold text-ink active:scale-95">
|
||||
{t('spoiler.show')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cx('mt-2', className)}>
|
||||
{spoiler && (
|
||||
<span className="mb-1.5 inline-flex items-center gap-1 rounded-full border border-accent/50 px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide text-accent">
|
||||
<EyeOff size={11} aria-hidden="true" /> {t('spoiler.badge')}
|
||||
</span>
|
||||
)}
|
||||
<p className={cx('whitespace-pre-line break-words text-sm leading-relaxed text-ink-2', clamp && 'line-clamp-6')}>{text}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { Check, Loader2, Users } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { getTmdbPosterUrl } from '../../lib/catalogApi'
|
||||
import { addSharedListItem, getSharedLists, removeSharedListItem, snapshotOf, type SharedListCard } from '../../lib/cloud/sharedLists'
|
||||
import { cx } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
import type { MediaItem } from '../../types'
|
||||
import { useSocial } from './SocialProvider'
|
||||
|
||||
/**
|
||||
* « Ajouter à une liste » côté listes partagées, dans la fiche d'un titre.
|
||||
* N'apparaît que si j'ai au moins une liste partagée (et si le serveur les gère déjà).
|
||||
*/
|
||||
export default function SharedListPicker({ snapshot, posterFallback }: { snapshot: Pick<MediaItem, 'externalId' | 'title' | 'type' | 'year' | 'poster'>; posterFallback?: string }) {
|
||||
const social = useSocial()
|
||||
const { settings } = useMedia()
|
||||
const [lists, setLists] = useState<SharedListCard[]>()
|
||||
const [busy, setBusy] = useState<string>()
|
||||
const [err, setErr] = useState<string>()
|
||||
const externalId = snapshot.externalId
|
||||
|
||||
useEffect(() => {
|
||||
if (!social.enabled || !externalId) return
|
||||
let alive = true
|
||||
getSharedLists(externalId)
|
||||
.then((d) => alive && setLists(d.lists))
|
||||
.catch(() => alive && setLists([]))
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [social.enabled, externalId, social.sharedTick])
|
||||
|
||||
if (!social.enabled || !lists?.length) return null
|
||||
|
||||
const toggle = async (l: SharedListCard) => {
|
||||
const snap = snapshotOf(snapshot, posterFallback)
|
||||
if (!snap) return
|
||||
setBusy(l.id)
|
||||
setErr(undefined)
|
||||
try {
|
||||
if (l.has) await removeSharedListItem(l.id, snap.externalId)
|
||||
else {
|
||||
// L'affiche gardée hors-ligne (copie locale) ne se partage pas : on reprend l'adresse TMDB
|
||||
if (!snap.poster && snap.externalId.startsWith('tmdb:') && settings.tmdbKey && navigator.onLine) {
|
||||
snap.poster = await getTmdbPosterUrl(snap.externalId, settings.tmdbKey).catch(() => undefined)
|
||||
}
|
||||
await addSharedListItem(l.id, snap)
|
||||
}
|
||||
setLists((prev) => prev?.map((x) => (x.id === l.id ? { ...x, has: !l.has, count: x.count + (l.has ? -1 : 1) } : x)))
|
||||
social.bumpShared()
|
||||
} catch (e) {
|
||||
setErr((e as Error).message)
|
||||
} finally {
|
||||
setBusy(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="mx-4 mt-8 border-t border-line pt-5" aria-labelledby="shared-picker-title">
|
||||
<h3 id="shared-picker-title" className="eyebrow mb-3 flex items-center gap-1.5 text-ink-2">
|
||||
<Users size={13} aria-hidden="true" /> {t('shared.addTo')}
|
||||
</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{lists.map((l) => (
|
||||
<button key={l.id} onClick={() => void toggle(l)} disabled={busy === l.id} aria-pressed={l.has} className={cx('chip', l.has && 'chip-on')}>
|
||||
{busy === l.id ? <Loader2 size={14} className="animate-spin" /> : l.has ? <Check size={14} /> : <Users size={14} />}
|
||||
{l.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{err && (
|
||||
<p role="alert" className="mt-2 text-xs text-accent">
|
||||
{err}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,616 @@
|
||||
import { Check, Loader2, LogOut, Pencil, Plus, Search, Trash2, UserPlus, Users, X } from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { locale, t } from '../../i18n'
|
||||
import {
|
||||
addSharedListItem,
|
||||
createSharedList,
|
||||
deleteSharedList,
|
||||
getSharedList,
|
||||
getSharedLists,
|
||||
inviteCandidates,
|
||||
inviteToSharedList,
|
||||
leaveSharedList,
|
||||
removeSharedListItem,
|
||||
removeSharedListMember,
|
||||
renameSharedList,
|
||||
respondToInvite,
|
||||
SHARED_LIST_NAME_MAX,
|
||||
SharedListsUnavailable,
|
||||
snapshotOf,
|
||||
type SharedList,
|
||||
type SharedListCard,
|
||||
type SharedListInvite,
|
||||
type SharedListItem,
|
||||
} from '../../lib/cloud/sharedLists'
|
||||
import type { ProfileCard } from '../../lib/cloud/social'
|
||||
import { TYPE_BY_VALUE } from '../../lib/constants'
|
||||
import { cx, normalizeText } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
import { TypeBadge } from '../Badges'
|
||||
import ConfirmDialog from '../ConfirmDialog'
|
||||
import Poster from '../Poster'
|
||||
import { EmptyState } from '../ui'
|
||||
import ReportButton from '../moderation/ReportButton'
|
||||
import Avatar from './Avatar'
|
||||
import PersonRow from './PersonRow'
|
||||
import Sheet from './Sheet'
|
||||
import { useSocial } from './SocialProvider'
|
||||
|
||||
/** Mosaïque 2×2 des dernières affiches d'une liste partagée. */
|
||||
function PosterMosaic({ posters }: { posters: string[] }) {
|
||||
return (
|
||||
<div className="relative grid grid-cols-2 gap-0.5 overflow-hidden rounded-xl border border-line bg-surface-2">
|
||||
{[0, 1, 2, 3].map((i) =>
|
||||
posters[i] ? (
|
||||
<img key={i} src={posters[i]} alt="" loading="lazy" className="aspect-[2/3] w-full object-cover" />
|
||||
) : (
|
||||
<div key={i} className="aspect-[2/3] w-full bg-surface-2" />
|
||||
),
|
||||
)}
|
||||
<span className="absolute bottom-1.5 end-1.5 grid size-7 place-items-center rounded-full bg-bg/85 text-ink" aria-hidden="true">
|
||||
<Users size={14} />
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Champ « nom de liste » + bouton (création, renommage). */
|
||||
function NameForm({ initial = '', submitLabel, onSubmit, onCancel, autoFocus }: { initial?: string; submitLabel: string; onSubmit: (name: string) => Promise<void>; onCancel?: () => void; autoFocus?: boolean }) {
|
||||
const [name, setName] = useState(initial)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [err, setErr] = useState<string>()
|
||||
const submit = async () => {
|
||||
if (!name.trim() || busy) return
|
||||
setBusy(true)
|
||||
setErr(undefined)
|
||||
try {
|
||||
await onSubmit(name.trim())
|
||||
setName('')
|
||||
} catch (e) {
|
||||
setErr((e as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="field"
|
||||
value={name}
|
||||
maxLength={SHARED_LIST_NAME_MAX}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
void submit()
|
||||
}
|
||||
if (e.key === 'Escape' && onCancel) {
|
||||
e.stopPropagation()
|
||||
onCancel()
|
||||
}
|
||||
}}
|
||||
placeholder={t('shared.namePh')}
|
||||
autoFocus={autoFocus}
|
||||
enterKeyHint="done"
|
||||
aria-label={t('shared.namePh')}
|
||||
/>
|
||||
<button type="button" onClick={() => void submit()} disabled={!name.trim() || busy} className="btn btn-light shrink-0 px-4 text-sm">
|
||||
{busy ? <Loader2 size={15} className="animate-spin" /> : submitLabel}
|
||||
</button>
|
||||
</div>
|
||||
{err && (
|
||||
<p role="alert" className="mt-1.5 text-xs text-accent">
|
||||
{err}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ════════════════════════ Section « Listes partagées » (onglet Listes) ════════════════════════
|
||||
|
||||
export function SharedListsSection() {
|
||||
const social = useSocial()
|
||||
const [data, setData] = useState<{ lists: SharedListCard[]; invites: SharedListInvite[] }>()
|
||||
const [unavailable, setUnavailable] = useState(false)
|
||||
const [creating, setCreating] = useState(false)
|
||||
const [busyInvite, setBusyInvite] = useState<string>()
|
||||
|
||||
useEffect(() => {
|
||||
if (!social.enabled) return
|
||||
let alive = true
|
||||
getSharedLists()
|
||||
.then((d) => alive && setData(d))
|
||||
.catch((e) => {
|
||||
if (!alive) return
|
||||
if (e instanceof SharedListsUnavailable) setUnavailable(true)
|
||||
else setData((prev) => prev ?? { lists: [], invites: [] })
|
||||
})
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [social.enabled, social.sharedTick])
|
||||
|
||||
// Sans compte, ou serveur pas encore à jour : la section n'existe pas
|
||||
if (!social.enabled || unavailable) return null
|
||||
|
||||
const respond = async (inv: SharedListInvite, accept: boolean) => {
|
||||
setBusyInvite(inv.id)
|
||||
try {
|
||||
await respondToInvite(inv.id, accept)
|
||||
social.bumpShared()
|
||||
if (accept) social.openSharedList(inv.id)
|
||||
} catch {
|
||||
/* l'invitation reste affichée */
|
||||
} finally {
|
||||
setBusyInvite(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="mt-10 border-t border-line pt-6" aria-labelledby="shared-lists-title">
|
||||
<div className="mb-1 flex items-center justify-between gap-3">
|
||||
<h2 id="shared-lists-title" className="flex items-center gap-2 text-lg">
|
||||
<Users size={18} className="text-accent" aria-hidden="true" /> {t('shared.title')}
|
||||
</h2>
|
||||
</div>
|
||||
<p className="mb-4 text-sm text-ink-3">{t('shared.hint')}</p>
|
||||
|
||||
{creating ? (
|
||||
<div className="mb-5">
|
||||
<NameForm
|
||||
autoFocus
|
||||
submitLabel={t('lists.create')}
|
||||
onCancel={() => setCreating(false)}
|
||||
onSubmit={async (name) => {
|
||||
const id = await createSharedList(name)
|
||||
setCreating(false)
|
||||
social.bumpShared()
|
||||
social.openSharedList(id)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<button onClick={() => setCreating(true)} className="chip mb-5">
|
||||
<Plus size={14} /> {t('shared.new')}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Invitations reçues */}
|
||||
{data && data.invites.length > 0 && (
|
||||
<ul className="mb-6 space-y-2">
|
||||
{data.invites.map((inv) => (
|
||||
<li key={inv.id} className="card p-3.5 sm:flex sm:items-center sm:gap-3">
|
||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<Avatar url={inv.owner?.avatarUrl} name={inv.owner?.displayName ?? '?'} size={36} />
|
||||
<p className="min-w-0 flex-1 text-sm leading-snug text-ink-2">
|
||||
<b className="text-ink">{inv.owner?.displayName ?? t('notif.someone')}</b> {t('shared.invitesYou')} <b className="text-ink">{inv.name}</b>
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-3 flex shrink-0 justify-end gap-2 sm:mt-0">
|
||||
<button onClick={() => void respond(inv, false)} disabled={busyInvite === inv.id} className="btn btn-ghost px-3.5 py-1.5 text-sm">
|
||||
{t('shared.decline')}
|
||||
</button>
|
||||
<button onClick={() => void respond(inv, true)} disabled={busyInvite === inv.id} className="btn btn-primary px-3.5 py-1.5 text-sm">
|
||||
{busyInvite === inv.id ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} />} {t('shared.accept')}
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{data === undefined ? (
|
||||
<p className="flex items-center gap-2 text-sm text-ink-3">
|
||||
<Loader2 size={14} className="animate-spin" /> {t('social.loading')}
|
||||
</p>
|
||||
) : data.lists.length === 0 ? (
|
||||
<p className="rounded-2xl border border-dashed border-line-strong p-4 text-sm text-ink-3">{t('shared.none')}</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-2 gap-x-3.5 gap-y-6 sm:grid-cols-3 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-8">
|
||||
{data.lists.map((l) => (
|
||||
<button key={l.id} onClick={() => social.openSharedList(l.id)} className="text-start">
|
||||
<PosterMosaic posters={l.posters} />
|
||||
<p className="mt-2 truncate text-sm font-semibold">{l.name}</p>
|
||||
<p className="truncate text-xs text-ink-3">
|
||||
{t('account.nTitles', { count: l.count })} · {t('shared.nMembers', { count: l.members })}
|
||||
</p>
|
||||
{!l.isOwner && l.owner && <p className="truncate text-[11px] text-ink-3">{t('shared.by', { name: l.owner.displayName })}</p>}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
// ════════════════════════ Une liste partagée (plein écran) ════════════════════════
|
||||
|
||||
export function SharedListSheet({ id, onClose }: { id: string; onClose: () => void }) {
|
||||
const social = useSocial()
|
||||
const [list, setList] = useState<SharedList | null>()
|
||||
const [error, setError] = useState<string>()
|
||||
const [renaming, setRenaming] = useState(false)
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [confirm, setConfirm] = useState<'delete' | 'leave' | null>(null)
|
||||
const [busyKey, setBusyKey] = useState<string>()
|
||||
const [reload, setReload] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
getSharedList(id)
|
||||
.then((l) => alive && setList(l))
|
||||
.catch((e) => alive && (setError((e as Error).message), setList(null)))
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [id, reload, social.sharedTick])
|
||||
|
||||
const refresh = () => setReload((n) => n + 1)
|
||||
|
||||
const act = async (key: string, fn: () => Promise<unknown>) => {
|
||||
setBusyKey(key)
|
||||
setError(undefined)
|
||||
try {
|
||||
await fn()
|
||||
refresh()
|
||||
social.bumpShared()
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
} finally {
|
||||
setBusyKey(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
const accepted = list?.members.filter((m) => m.status === 'accepted') ?? []
|
||||
const ownerId = list?.members.find((m) => m.isOwner)?.id
|
||||
const pending = list?.members.filter((m) => m.status === 'pending') ?? []
|
||||
|
||||
return (
|
||||
<Sheet title={list?.name ?? t('shared.title')} label={list?.name ?? t('shared.title')} onClose={onClose} wide>
|
||||
{list === undefined ? (
|
||||
<p className="flex items-center justify-center py-16 text-ink-3">
|
||||
<Loader2 size={20} className="animate-spin" />
|
||||
</p>
|
||||
) : list === null ? (
|
||||
<div className="px-4">
|
||||
<EmptyState title={t('shared.notFound')} text={error} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="px-4 pt-5 lg:px-8">
|
||||
{/* Nom + compteurs */}
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
{renaming ? (
|
||||
<div className="flex-1">
|
||||
<NameForm
|
||||
autoFocus
|
||||
initial={list.name}
|
||||
submitLabel="OK"
|
||||
onCancel={() => setRenaming(false)}
|
||||
onSubmit={async (name) => {
|
||||
await renameSharedList(list.id, name)
|
||||
setRenaming(false)
|
||||
refresh()
|
||||
social.bumpShared()
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="min-w-0">
|
||||
<p className="eyebrow flex items-center gap-1.5">
|
||||
<Users size={12} aria-hidden="true" /> {t('shared.badge')}
|
||||
</p>
|
||||
<h2 className="mt-1 text-2xl leading-tight">{list.name}</h2>
|
||||
<p className="mt-1 text-sm text-ink-3">
|
||||
{t('account.nTitles', { count: list.items.length })} · {t('shared.nMembers', { count: accepted.length })}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{!list.isOwner && ownerId && <ReportButton target={{ type: 'list', id: list.id, userId: ownerId }} className="size-10" />}
|
||||
{list.isOwner && !renaming && (
|
||||
<button onClick={() => setRenaming(true)} className="grid size-10 shrink-0 place-items-center rounded-full border border-line text-ink-2" aria-label={t('lists.rename')}>
|
||||
<Pencil size={16} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Membres */}
|
||||
<section className="mt-5" aria-label={t('shared.members')}>
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
<span className="eyebrow">{t('shared.members')}</span>
|
||||
{list.isOwner && (
|
||||
<button onClick={() => social.openInvite(list.id, list.name)} className="chip py-1 text-xs">
|
||||
<UserPlus size={13} /> {t('shared.invite')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<ul className="no-scrollbar -mx-4 flex gap-4 overflow-x-auto px-4 pb-1 lg:mx-0 lg:flex-wrap lg:px-0">
|
||||
{[...accepted, ...pending].map((m) => (
|
||||
<li key={m.id} className="relative w-16 shrink-0 text-center">
|
||||
<button onClick={() => social.openProfile(m.username)} className="block w-full" aria-label={m.displayName}>
|
||||
<Avatar url={m.avatarUrl} name={m.displayName} size={52} className={cx('mx-auto', m.status === 'pending' && 'opacity-50')} />
|
||||
<span className="mt-1.5 block truncate text-[11px] font-medium text-ink-2">{m.displayName}</span>
|
||||
<span className="block truncate text-[10px] text-ink-3">{m.isOwner ? t('shared.owner') : m.status === 'pending' ? t('shared.pending') : ' '}</span>
|
||||
</button>
|
||||
{list.isOwner && !m.isOwner && (
|
||||
<button
|
||||
onClick={() => void act(`m:${m.id}`, () => removeSharedListMember(list.id, m.id))}
|
||||
disabled={busyKey === `m:${m.id}`}
|
||||
className="absolute -top-1 end-0 grid size-6 place-items-center rounded-full border border-line-strong bg-surface text-ink-2"
|
||||
aria-label={t('shared.removeMember', { name: m.displayName })}
|
||||
>
|
||||
{busyKey === `m:${m.id}` ? <Loader2 size={11} className="animate-spin" /> : <X size={12} />}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
{error && (
|
||||
<p role="alert" className="mt-3 text-sm text-accent">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Titres */}
|
||||
<div className="mt-6 flex flex-wrap items-center gap-2">
|
||||
<button onClick={() => setEditing((v) => !v)} className={cx('chip', editing && 'chip-on')}>
|
||||
{editing ? <Check size={14} /> : <Plus size={14} />}
|
||||
{editing ? t('lists.done') : t('lists.addRemove')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{editing && <LibraryPicker list={list} onChanged={refresh} />}
|
||||
|
||||
{list.items.length === 0 ? (
|
||||
<div className="mt-4">
|
||||
<EmptyState title={t('lists.emptyTitle')} text={t('shared.emptyText')} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="mt-5 grid grid-cols-2 gap-x-3.5 gap-y-6 sm:grid-cols-3 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-8">
|
||||
{list.items.map((it) => (
|
||||
<SharedItemCard
|
||||
key={it.externalId}
|
||||
item={it}
|
||||
editing={editing}
|
||||
busy={busyKey === `i:${it.externalId}`}
|
||||
onOpen={() => social.openTitle(it)}
|
||||
onRemove={() => void act(`i:${it.externalId}`, () => removeSharedListItem(list.id, it.externalId))}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Quitter / supprimer */}
|
||||
<div className="mt-10 border-t border-line pt-5">
|
||||
{list.isOwner ? (
|
||||
<button onClick={() => setConfirm('delete')} className="flex items-center gap-2 text-sm font-medium text-accent">
|
||||
<Trash2 size={16} /> {t('shared.delete')}
|
||||
</button>
|
||||
) : (
|
||||
<button onClick={() => setConfirm('leave')} className="flex items-center gap-2 text-sm font-medium text-accent">
|
||||
<LogOut size={16} className="rtl:-scale-x-100" /> {t('shared.leave')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirm !== null}
|
||||
title={t('confirm.title')}
|
||||
message={list ? (confirm === 'delete' ? t('shared.deleteConfirm', { name: list.name }) : t('shared.leaveConfirm', { name: list.name })) : undefined}
|
||||
confirmLabel={confirm === 'delete' ? t('common.delete') : t('shared.leaveShort')}
|
||||
onCancel={() => setConfirm(null)}
|
||||
onConfirm={async () => {
|
||||
if (!list) return
|
||||
const kind = confirm
|
||||
setConfirm(null)
|
||||
try {
|
||||
if (kind === 'delete') await deleteSharedList(list.id)
|
||||
else await leaveSharedList(list.id)
|
||||
social.bumpShared()
|
||||
onClose()
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
|
||||
function SharedItemCard({ item, editing, busy, onOpen, onRemove }: { item: SharedListItem; editing: boolean; busy: boolean; onOpen: () => void; onRemove: () => void }) {
|
||||
return (
|
||||
<div className="relative">
|
||||
<button onClick={onOpen} className="block w-full text-start">
|
||||
<Poster src={item.poster} title={item.title} />
|
||||
<p className="mt-2 line-clamp-2 text-sm font-semibold leading-snug">{item.title}</p>
|
||||
<p className="mt-0.5 text-xs text-ink-3">{[item.year, TYPE_BY_VALUE[item.type].label].filter(Boolean).join(' · ')}</p>
|
||||
</button>
|
||||
{item.addedBy && (
|
||||
<p className="mt-1 flex items-center gap-1.5 text-[11px] text-ink-3">
|
||||
<Avatar url={item.addedBy.avatarUrl} name={item.addedBy.displayName} size={16} />
|
||||
<span className="truncate">{t('shared.addedBy', { name: item.addedBy.displayName })}</span>
|
||||
</p>
|
||||
)}
|
||||
{editing && (
|
||||
<button
|
||||
onClick={onRemove}
|
||||
disabled={busy}
|
||||
className="absolute end-1.5 top-1.5 grid size-8 place-items-center rounded-full border border-line-strong bg-bg/90 text-ink"
|
||||
aria-label={t('shared.removeTitle', { title: item.title })}
|
||||
>
|
||||
{busy ? <Loader2 size={14} className="animate-spin" /> : <X size={15} />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Ajouter / retirer des titres de ma bibliothèque (ceux qui ont une référence TMDB / AniList). */
|
||||
function LibraryPicker({ list, onChanged }: { list: SharedList; onChanged: () => void }) {
|
||||
const { items } = useMedia()
|
||||
const social = useSocial()
|
||||
const [query, setQuery] = useState('')
|
||||
const [busy, setBusy] = useState<string>()
|
||||
const [err, setErr] = useState<string>()
|
||||
const inList = useMemo(() => new Set(list.items.map((i) => i.externalId)), [list.items])
|
||||
|
||||
const candidates = useMemo(() => {
|
||||
const q = normalizeText(query)
|
||||
return items
|
||||
.filter((i) => i.externalId && (!q || normalizeText(`${i.title} ${i.originalTitle ?? ''}`).includes(q)))
|
||||
.sort((a, b) => a.title.localeCompare(b.title, locale()))
|
||||
.slice(0, 60)
|
||||
}, [items, query])
|
||||
|
||||
const toggle = async (item: (typeof items)[number]) => {
|
||||
const snap = snapshotOf(item)
|
||||
if (!snap) return
|
||||
setBusy(item.id)
|
||||
setErr(undefined)
|
||||
try {
|
||||
if (inList.has(snap.externalId)) await removeSharedListItem(list.id, snap.externalId)
|
||||
else await addSharedListItem(list.id, snap)
|
||||
onChanged()
|
||||
social.bumpShared()
|
||||
} catch (e) {
|
||||
setErr((e as Error).message)
|
||||
} finally {
|
||||
setBusy(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-4 rounded-2xl border border-line p-3">
|
||||
<div className="relative mb-2">
|
||||
<Search size={17} className="pointer-events-none absolute start-3.5 top-1/2 -translate-y-1/2 text-ink-3" />
|
||||
<input type="search" value={query} onChange={(e) => setQuery(e.target.value)} placeholder={t('lists.searchLibrary')} className="field ps-10" aria-label={t('lists.searchLibrary')} />
|
||||
</div>
|
||||
{err && (
|
||||
<p role="alert" className="mb-2 text-xs text-accent">
|
||||
{err}
|
||||
</p>
|
||||
)}
|
||||
<ul className="max-h-80 divide-y divide-line overflow-y-auto overscroll-contain">
|
||||
{candidates.map((item) => {
|
||||
const on = inList.has(item.externalId!)
|
||||
return (
|
||||
<li key={item.id}>
|
||||
<button onClick={() => void toggle(item)} disabled={busy === item.id} className="flex w-full items-center gap-3 py-2.5 text-start">
|
||||
<div className="w-9 shrink-0">
|
||||
<Poster src={item.poster} title={item.title} />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-medium">{item.title}</p>
|
||||
<div className="mt-1">
|
||||
<TypeBadge item={item} />
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={cx(
|
||||
'grid size-7 shrink-0 place-items-center rounded-full border',
|
||||
on ? 'border-accent-fill bg-accent-fill text-on-accent' : 'border-line-strong text-transparent',
|
||||
)}
|
||||
>
|
||||
{busy === item.id ? <Loader2 size={13} className="animate-spin text-ink-3" /> : <Check size={14} strokeWidth={3} />}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
{candidates.length === 0 && <li className="py-4 text-center text-sm text-ink-3">{t('shared.noCandidates')}</li>}
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ════════════════════════ Inviter des membres ════════════════════════
|
||||
|
||||
export function InvitePeople({ listId, listName, onClose }: { listId: string; listName: string; onClose: () => void }) {
|
||||
const social = useSocial()
|
||||
const [q, setQ] = useState('')
|
||||
const [people, setPeople] = useState<ProfileCard[]>()
|
||||
const [invited, setInvited] = useState<Set<string>>(new Set())
|
||||
const [busy, setBusy] = useState<string>()
|
||||
const [err, setErr] = useState<string>()
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
const timer = setTimeout(
|
||||
() => {
|
||||
inviteCandidates(listId, q)
|
||||
.then((r) => alive && setPeople(r))
|
||||
.catch((e) => alive && (setPeople([]), setErr((e as Error).message)))
|
||||
},
|
||||
q ? 250 : 0,
|
||||
)
|
||||
return () => {
|
||||
alive = false
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [listId, q])
|
||||
|
||||
const invite = async (p: ProfileCard) => {
|
||||
setBusy(p.id)
|
||||
setErr(undefined)
|
||||
try {
|
||||
await inviteToSharedList(listId, p.id)
|
||||
setInvited((s) => new Set(s).add(p.id))
|
||||
social.bumpShared()
|
||||
} catch (e) {
|
||||
setErr((e as Error).message)
|
||||
} finally {
|
||||
setBusy(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Sheet title={t('shared.inviteTitle')} label={t('shared.inviteTitle')} onClose={onClose}>
|
||||
<div className="px-4 pt-4">
|
||||
<p className="text-sm text-ink-3">{t('shared.inviteHint', { name: listName })}</p>
|
||||
<div className="relative mt-3">
|
||||
<Search size={17} className="pointer-events-none absolute start-3.5 top-1/2 -translate-y-1/2 text-ink-3" />
|
||||
<input type="search" value={q} onChange={(e) => setQ(e.target.value)} placeholder={t('shared.searchPeople')} className="field ps-10" autoFocus aria-label={t('shared.searchPeople')} />
|
||||
</div>
|
||||
{err && (
|
||||
<p role="alert" className="mt-2 text-xs text-accent">
|
||||
{err}
|
||||
</p>
|
||||
)}
|
||||
{people === undefined ? (
|
||||
<p className="flex justify-center py-10 text-ink-3">
|
||||
<Loader2 size={18} className="animate-spin" />
|
||||
</p>
|
||||
) : people.length === 0 ? (
|
||||
<p className="py-10 text-center text-sm text-ink-3">{t('shared.noPeople')}</p>
|
||||
) : (
|
||||
<div className="mt-2 divide-y divide-line">
|
||||
{people.map((p) => (
|
||||
<PersonRow
|
||||
key={p.id}
|
||||
person={p}
|
||||
actions={
|
||||
<button
|
||||
onClick={() => void invite(p)}
|
||||
disabled={busy === p.id || invited.has(p.id)}
|
||||
className={cx(
|
||||
'flex h-8 shrink-0 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95',
|
||||
invited.has(p.id) ? 'border border-line-strong text-ink-2' : 'bg-accent-fill text-on-accent',
|
||||
)}
|
||||
>
|
||||
{busy === p.id ? <Loader2 size={13} className="animate-spin" /> : invited.has(p.id) ? <Check size={13} /> : <UserPlus size={13} />}
|
||||
{invited.has(p.id) ? t('shared.invited') : t('shared.inviteShort')}
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
@@ -12,6 +12,11 @@ import TitleReviews from './TitleReviews'
|
||||
import Notifications from './Notifications'
|
||||
import { useOnResume } from '../../lib/onResume'
|
||||
import WelcomeProfile, { RANDOM_USERNAME } from './WelcomeProfile'
|
||||
import CommentsSheet from './CommentsSheet'
|
||||
import { InvitePeople, SharedListSheet } from './SharedLists'
|
||||
import { getAniListById, type SearchResult } from '../../lib/catalogApi'
|
||||
import { TYPE_BY_VALUE } from '../../lib/constants'
|
||||
import type { SharedListItem } from '../../lib/cloud/sharedLists'
|
||||
|
||||
interface SocialApi {
|
||||
/** Réseau disponible (compte connecté) */
|
||||
@@ -32,6 +37,17 @@ interface SocialApi {
|
||||
peek: (item: MediaItem, owner?: PeekOwner) => void
|
||||
/** Ouvre la fiche si elle est à moi, sinon l'aperçu */
|
||||
openItem: (item: MediaItem, owner?: PeekOwner) => void
|
||||
/** Fil de commentaires d'un avis, en plein écran (depuis une notification) */
|
||||
openComments: (authorId: string, itemId: string, title: string) => void
|
||||
/** Liste partagée */
|
||||
openSharedList: (id: string) => void
|
||||
/** Inviter des membres dans une liste partagée */
|
||||
openInvite: (listId: string, listName: string) => void
|
||||
/** Fiche d'un titre d'une liste partagée : la mienne si je l'ai, sinon la fiche du catalogue (ajout possible) */
|
||||
openTitle: (title: SharedListItem) => void
|
||||
/** Change à chaque modification des listes partagées (pour recharger les écrans qui les affichent) */
|
||||
sharedTick: number
|
||||
bumpShared: () => void
|
||||
}
|
||||
|
||||
const SocialContext = createContext<SocialApi>({
|
||||
@@ -48,6 +64,12 @@ const SocialContext = createContext<SocialApi>({
|
||||
unread: 0,
|
||||
peek: () => {},
|
||||
openItem: () => {},
|
||||
openComments: () => {},
|
||||
openSharedList: () => {},
|
||||
openInvite: () => {},
|
||||
openTitle: () => {},
|
||||
sharedTick: 0,
|
||||
bumpShared: () => {},
|
||||
})
|
||||
|
||||
export const useSocial = () => useContext(SocialContext)
|
||||
@@ -59,9 +81,21 @@ type Overlay =
|
||||
| { kind: 'follows'; profile: Profile; list: 'followers' | 'following' }
|
||||
| { kind: 'reviews'; externalId: string; title: string }
|
||||
| { kind: 'notifications' }
|
||||
| { kind: 'comments'; authorId: string; itemId: string; title: string }
|
||||
| { kind: 'sharedList'; id: string }
|
||||
| { kind: 'invite'; listId: string; listName: string }
|
||||
|
||||
/** Profils, recherche et aperçus : affichés par-dessus l'app, empilés (le bouton fermer revient au précédent). */
|
||||
export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNode; onOpenOwnItem: (item: MediaItem) => void }) {
|
||||
export function SocialProvider({
|
||||
children,
|
||||
onOpenOwnItem,
|
||||
onOpenSeed,
|
||||
}: {
|
||||
children: ReactNode
|
||||
onOpenOwnItem: (item: MediaItem) => void
|
||||
/** Ouvre la fiche d'un titre pas encore dans ma bibliothèque */
|
||||
onOpenSeed?: (seed: SearchResult) => void
|
||||
}) {
|
||||
const { account, items } = useMedia()
|
||||
const enabled = !!account
|
||||
const [me, setMe] = useState<Profile | null>(null)
|
||||
@@ -69,6 +103,8 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
|
||||
const [unread, setUnread] = useState(0)
|
||||
const [stack, setStack] = useState<Overlay[]>([])
|
||||
const [peeked, setPeeked] = useState<{ item: MediaItem; owner?: PeekOwner }>()
|
||||
const [sharedTick, setSharedTick] = useState(0)
|
||||
const bumpShared = useCallback(() => setSharedTick((n) => n + 1), [])
|
||||
// « Plus tard » sur le choix du pseudo : redemandé au prochain lancement
|
||||
const [welcomeLater, setWelcomeLater] = useState(() => {
|
||||
try {
|
||||
@@ -131,6 +167,30 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
|
||||
[items, me?.username, onOpenOwnItem],
|
||||
)
|
||||
|
||||
const openTitle = useCallback(
|
||||
async (s: SharedListItem) => {
|
||||
const local = items.find((i) => i.externalId === s.externalId)
|
||||
if (local) return onOpenOwnItem(local)
|
||||
const anilist = s.externalId.startsWith('anilist:')
|
||||
// AniList : fiche complète si possible (sinon l'instantané de la liste suffit pour l'ouvrir)
|
||||
const full = anilist && navigator.onLine ? await getAniListById(s.externalId).catch(() => null) : null
|
||||
onOpenSeed?.(
|
||||
full ?? {
|
||||
source: anilist ? 'anilist' : 'tmdb',
|
||||
externalId: s.externalId,
|
||||
title: s.title,
|
||||
year: s.year,
|
||||
thumb: s.poster,
|
||||
posterUrl: s.poster,
|
||||
kindLabel: TYPE_BY_VALUE[s.type].label,
|
||||
typeGuess: s.type,
|
||||
prefill: anilist ? { title: s.title, year: s.year, type: s.type, externalId: s.externalId, genres: [] } : undefined,
|
||||
},
|
||||
)
|
||||
},
|
||||
[items, onOpenOwnItem, onOpenSeed],
|
||||
)
|
||||
|
||||
const api = useMemo<SocialApi>(
|
||||
() => ({
|
||||
enabled,
|
||||
@@ -150,8 +210,14 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
|
||||
unread,
|
||||
peek: (item, owner) => setPeeked({ item, owner }),
|
||||
openItem,
|
||||
openComments: (authorId, itemId, title) => push({ kind: 'comments', authorId, itemId, title }),
|
||||
openSharedList: (id) => push({ kind: 'sharedList', id }),
|
||||
openInvite: (listId, listName) => push({ kind: 'invite', listId, listName }),
|
||||
openTitle: (s) => void openTitle(s),
|
||||
sharedTick,
|
||||
bumpShared,
|
||||
}),
|
||||
[enabled, me, requests, unread, refresh, push, openItem],
|
||||
[enabled, me, requests, unread, refresh, push, openItem, openTitle, sharedTick, bumpShared],
|
||||
)
|
||||
|
||||
return (
|
||||
@@ -169,6 +235,12 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
|
||||
<FollowList key={k} profile={o.profile} initial={o.list} onClose={pop} />
|
||||
) : o.kind === 'reviews' ? (
|
||||
<TitleReviews key={k} externalId={o.externalId} title={o.title} onClose={pop} onOpenProfile={(u) => push({ kind: 'profile', username: u })} />
|
||||
) : o.kind === 'comments' ? (
|
||||
<CommentsSheet key={k} authorId={o.authorId} itemId={o.itemId} title={o.title} onClose={pop} />
|
||||
) : o.kind === 'sharedList' ? (
|
||||
<SharedListSheet key={k} id={o.id} onClose={pop} />
|
||||
) : o.kind === 'invite' ? (
|
||||
<InvitePeople key={k} listId={o.listId} listName={o.listName} onClose={pop} />
|
||||
) : (
|
||||
<Notifications
|
||||
key={k}
|
||||
@@ -181,6 +253,15 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
|
||||
onOpenOwnItem(it)
|
||||
}
|
||||
}}
|
||||
onOpenComments={(itemId, title) => {
|
||||
if (!me) return
|
||||
pop()
|
||||
push({ kind: 'comments', authorId: me.id, itemId, title })
|
||||
}}
|
||||
onOpenSharedList={(id) => {
|
||||
pop()
|
||||
push({ kind: 'sharedList', id })
|
||||
}}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
|
||||
@@ -8,6 +8,8 @@ import { useMedia } from '../../store'
|
||||
import ReportButton from '../moderation/ReportButton'
|
||||
import Avatar from './Avatar'
|
||||
import Reactions from './Reactions'
|
||||
import ReviewComments from './ReviewComments'
|
||||
import ReviewText from './ReviewText'
|
||||
import Sheet from './Sheet'
|
||||
|
||||
/** Écran plein : tous les avis sur un même titre (amis / autres membres) avec réactions. */
|
||||
@@ -85,9 +87,11 @@ function ReviewCard({ r, onOpenProfile }: { r: TitleReview; onOpenProfile: (user
|
||||
)}
|
||||
<ReportButton target={{ type: 'review', id: r.item_id, userId: r.user_id }} className="-me-1.5" size={16} />
|
||||
</div>
|
||||
{r.notes && <p className="mt-2 whitespace-pre-line text-sm leading-relaxed text-ink-2">{r.notes}</p>}
|
||||
{r.notes && <ReviewText text={r.notes} spoiler={r.spoiler} />}
|
||||
<div className="mt-3">
|
||||
<Reactions authorId={r.user_id} itemId={r.item_id} reactions={r.reactions} mine={r.mine} />
|
||||
<ReviewComments authorId={r.user_id} itemId={r.item_id} count={r.comments} hidden={r.comments === null}>
|
||||
<Reactions authorId={r.user_id} itemId={r.item_id} reactions={r.reactions} mine={r.mine} />
|
||||
</ReviewComments>
|
||||
</div>
|
||||
</article>
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { X } from 'lucide-react'
|
||||
import { EyeOff, X } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { useBackToClose } from '../../lib/backNav'
|
||||
@@ -6,11 +6,24 @@ import { useEscape } from '../../lib/escape'
|
||||
import { LIMITS } from '../../lib/security'
|
||||
|
||||
/** Écriture de mon avis, en plein écran pour avoir la place d'écrire. */
|
||||
export default function ReviewEditor({ title, initial, onSave, onClose }: { title: string; initial: string; onSave: (notes: string) => void; onClose: () => void }) {
|
||||
export default function ReviewEditor({
|
||||
title,
|
||||
initial,
|
||||
initialSpoiler = false,
|
||||
onSave,
|
||||
onClose,
|
||||
}: {
|
||||
title: string
|
||||
initial: string
|
||||
initialSpoiler?: boolean
|
||||
onSave: (notes: string, spoiler: boolean) => void
|
||||
onClose: () => void
|
||||
}) {
|
||||
const [text, setText] = useState(initial)
|
||||
const [spoiler, setSpoiler] = useState(initialSpoiler)
|
||||
useEscape(onClose)
|
||||
useBackToClose(onClose)
|
||||
const changed = text.trim() !== initial.trim()
|
||||
const changed = text.trim() !== initial.trim() || (spoiler !== initialSpoiler && !!text.trim())
|
||||
return (
|
||||
<div className="sheet sheet-in z-[60]" role="dialog" aria-modal="true" aria-label={t('form.review')}>
|
||||
<header className="safe-top border-b border-line">
|
||||
@@ -19,7 +32,7 @@ export default function ReviewEditor({ title, initial, onSave, onClose }: { titl
|
||||
<X size={22} />
|
||||
</button>
|
||||
<h2 className="min-w-0 flex-1 truncate text-center text-base font-semibold">{title}</h2>
|
||||
<button onClick={() => onSave(text.trim())} disabled={!changed} className="btn btn-light px-4 py-2 text-sm">
|
||||
<button onClick={() => onSave(text.trim(), spoiler && !!text.trim())} disabled={!changed} className="btn btn-light px-4 py-2 text-sm">
|
||||
{t('common.save')}
|
||||
</button>
|
||||
</div>
|
||||
@@ -35,6 +48,15 @@ export default function ReviewEditor({ title, initial, onSave, onClose }: { titl
|
||||
maxLength={LIMITS.notes}
|
||||
autoFocus
|
||||
/>
|
||||
<label className="mt-3 flex cursor-pointer items-start gap-3 rounded-xl border border-line px-3.5 py-3">
|
||||
<input type="checkbox" checked={spoiler} onChange={(e) => setSpoiler(e.target.checked)} className="mt-0.5 size-4 shrink-0 accent-accent-fill" />
|
||||
<span className="min-w-0">
|
||||
<span className="flex items-center gap-1.5 text-sm font-medium text-ink">
|
||||
<EyeOff size={14} className="text-accent" aria-hidden="true" /> {t('spoiler.checkbox')}
|
||||
</span>
|
||||
<span className="mt-0.5 block text-xs text-ink-3">{t('spoiler.checkboxHint')}</span>
|
||||
</span>
|
||||
</label>
|
||||
<p className="mt-2 text-xs text-ink-3">{t('title.reviewPublicHint')}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -29,6 +29,8 @@ import SharePreview from '../SharePreview'
|
||||
import EditDetails from './EditDetails'
|
||||
import ReviewEditor from './ReviewEditor'
|
||||
import WhereToWatch from './WhereToWatch'
|
||||
import ReviewComments from '../social/ReviewComments'
|
||||
import SharedListPicker from '../social/SharedListPicker'
|
||||
|
||||
/** Suivi « vide » d'un titre qu'on ajoute. */
|
||||
const BLANK: Pick<MediaInput, 'criteria' | 'episodesWatched' | 'genres'> = { criteria: {}, episodesWatched: 0, genres: [] }
|
||||
@@ -466,12 +468,23 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
|
||||
{/* Mon avis */}
|
||||
<section className="mx-4 mt-4">
|
||||
{item?.notes ? (
|
||||
<button onClick={() => setReviewing(true)} className="card block w-full p-4 text-left">
|
||||
<span className="eyebrow flex items-center justify-between">
|
||||
{t('form.review')} <Pencil size={13} />
|
||||
</span>
|
||||
<p className="mt-2 line-clamp-6 whitespace-pre-line text-sm leading-relaxed text-ink">{item.notes}</p>
|
||||
</button>
|
||||
<div className="card p-4">
|
||||
<button onClick={() => setReviewing(true)} className="block w-full text-start">
|
||||
<span className="eyebrow flex items-center justify-between">
|
||||
<span className="flex items-center gap-2">
|
||||
{t('form.review')}
|
||||
{item.notesSpoiler && <span className="rounded-full border border-accent/50 px-1.5 py-px text-[10px] text-accent">{t('spoiler.badge')}</span>}
|
||||
</span>
|
||||
<Pencil size={13} />
|
||||
</span>
|
||||
<p className="mt-2 line-clamp-6 whitespace-pre-line text-sm leading-relaxed text-ink">{item.notes}</p>
|
||||
</button>
|
||||
{social.enabled && social.me && (
|
||||
<div className="mt-3 border-t border-line pt-3">
|
||||
<ReviewComments key={item.id} authorId={social.me.id} itemId={item.id} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<button onClick={() => setReviewing(true)} disabled={busy} className="flex w-full items-center gap-2 rounded-2xl border border-dashed border-line-strong px-4 py-3.5 text-left text-sm text-ink-2">
|
||||
<Pencil size={16} className="text-accent" /> {t('title.writeReview')}
|
||||
@@ -527,6 +540,11 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
|
||||
|
||||
{/* Mon suivi : dates, plateforme, listes, revisionnages */}
|
||||
{item && <Tracking item={item} lists={lists} tagSuggestions={allTags(items)} onChange={changeTracking} />}
|
||||
|
||||
{/* Listes partagées avec d'autres membres (titre de ma bibliothèque ou pas encore ajouté) */}
|
||||
{externalId && social.enabled && (
|
||||
<SharedListPicker snapshot={{ externalId, title, type, year: data.year, poster: item?.poster ?? poster }} posterFallback={seed?.posterUrl} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -556,11 +574,12 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
|
||||
<ReviewEditor
|
||||
title={title}
|
||||
initial={item?.notes ?? ''}
|
||||
initialSpoiler={!!item?.notesSpoiler}
|
||||
onClose={() => setReviewing(false)}
|
||||
onSave={async (notes) => {
|
||||
onSave={async (notes, spoiler) => {
|
||||
setReviewing(false)
|
||||
// Écrire un avis sur un titre pas encore ajouté le marque comme vu
|
||||
await save({ notes: notes || undefined, ...(item ? {} : { status: 'termine' as const, endDate: todayISO() }) })
|
||||
await save({ notes: notes || undefined, notesSpoiler: (notes && spoiler) || undefined, ...(item ? {} : { status: 'termine' as const, endDate: todayISO() }) })
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user