1 parent
d700543eba
commit
9612a7bfb2
7 files changed
+174
-57
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { Check, Loader2, MessagesSquare, Plus, Star } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { genreLabel } from '../../lib/genres'
|
||||
import { useScrollLock } from '../../lib/scrollLock'
|
||||
import { titleReviews, type TitleReview } from '../../lib/cloud/reviews'
|
||||
import { useSocial } from './SocialProvider'
|
||||
import { cx, formatDate, formatRating, normalizeText } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
@@ -10,6 +11,7 @@ import type { MediaInput, MediaItem } from '../../types'
|
||||
import { StatusPill, TypeBadge } from '../Badges'
|
||||
import Poster from '../Poster'
|
||||
import Avatar from './Avatar'
|
||||
import Reactions from './Reactions'
|
||||
import { useEscape } from '../../lib/escape'
|
||||
|
||||
export interface PeekOwner {
|
||||
@@ -24,6 +26,23 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
|
||||
const social = useSocial()
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [added, setAdded] = useState(false)
|
||||
// Avis d'un autre membre : on récupère les réactions pour pouvoir réagir ici même
|
||||
const [review, setReview] = useState<TitleReview>()
|
||||
const canReact = !!owner && owner.username !== social.me?.username && !!item.notes && !!item.externalId
|
||||
useEffect(() => {
|
||||
if (!canReact) return
|
||||
let alive = true
|
||||
titleReviews(item.externalId!)
|
||||
.then((d) => {
|
||||
if (!alive) return
|
||||
const all = [...d.friends, ...d.others]
|
||||
setReview(all.find((r) => r.user.username === owner!.username))
|
||||
})
|
||||
.catch(() => {})
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [canReact, item.externalId, owner])
|
||||
const owned = items.some(
|
||||
(i) => (item.externalId && i.externalId === item.externalId) || normalizeText(i.title) === normalizeText(item.title),
|
||||
)
|
||||
@@ -106,11 +125,16 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
|
||||
{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>}
|
||||
{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} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{item.externalId && (
|
||||
<button onClick={() => social.openReviews(item.externalId!, item.title)} className="mt-4 flex w-full items-center justify-center gap-2 rounded-xl border border-line py-2.5 text-sm font-medium text-ink-2 transition-colors active:bg-surface-2">
|
||||
<button onClick={() => { onClose(); social.openReviews(item.externalId!, item.title) }} className="mt-4 flex w-full items-center justify-center gap-2 rounded-xl border border-line py-2.5 text-sm font-medium text-ink-2 transition-colors active:bg-surface-2">
|
||||
<MessagesSquare size={16} /> {t('reviews.seeAll')}
|
||||
</button>
|
||||
)}
|
||||
|
||||
@@ -62,7 +62,7 @@ export default function Notifications({ onClose, onOpenProfile, onOpenItem }: {
|
||||
}
|
||||
|
||||
return (
|
||||
<Sheet title={t('notif.title')} label={t('notif.title')} onClose={onClose}>
|
||||
<Sheet title={t('notif.title')} label={t('notif.title')} onClose={onClose} elevated>
|
||||
{items === undefined ? (
|
||||
<p className="flex items-center justify-center py-16 text-ink-3">
|
||||
<Loader2 size={20} className="animate-spin" />
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { useState } from 'react'
|
||||
import { REACTION_EMOJIS, reactToReview, unreactReview, type ReactionEmoji } from '../../lib/cloud/reviews'
|
||||
import { cx } from '../../lib/utils'
|
||||
|
||||
/** Barre de réactions (emoji) sur un avis. Une seule réaction par personne ; retoucher la sienne l'enlève. */
|
||||
export default function Reactions({
|
||||
authorId,
|
||||
itemId,
|
||||
reactions: initial,
|
||||
mine: initialMine,
|
||||
}: {
|
||||
authorId: string
|
||||
itemId: string
|
||||
reactions: Record<string, number>
|
||||
mine: string | null
|
||||
}) {
|
||||
const [reactions, setReactions] = useState<Record<string, number>>(initial)
|
||||
const [mine, setMine] = useState<string | null>(initialMine)
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
const toggle = async (emoji: ReactionEmoji) => {
|
||||
if (busy) return
|
||||
const prev = { reactions, mine }
|
||||
const next: Record<string, number> = { ...reactions }
|
||||
if (mine === emoji) {
|
||||
next[emoji] = Math.max(0, (next[emoji] ?? 0) - 1)
|
||||
setReactions(next)
|
||||
setMine(null)
|
||||
} else {
|
||||
if (mine) next[mine] = Math.max(0, (next[mine] ?? 0) - 1)
|
||||
next[emoji] = (next[emoji] ?? 0) + 1
|
||||
setReactions(next)
|
||||
setMine(emoji)
|
||||
}
|
||||
setBusy(true)
|
||||
try {
|
||||
if (prev.mine === emoji) await unreactReview(authorId, itemId)
|
||||
else await reactToReview(authorId, itemId, emoji)
|
||||
} catch {
|
||||
setReactions(prev.reactions)
|
||||
setMine(prev.mine)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{REACTION_EMOJIS.map((emoji) => {
|
||||
const count = reactions[emoji] ?? 0
|
||||
const on = mine === emoji
|
||||
return (
|
||||
<button
|
||||
key={emoji}
|
||||
type="button"
|
||||
onClick={() => void toggle(emoji)}
|
||||
disabled={busy}
|
||||
aria-pressed={on}
|
||||
className={cx(
|
||||
'inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-sm transition-colors active:scale-95 disabled:opacity-60',
|
||||
on ? 'border-accent bg-accent-fill/10 text-ink' : 'border-line text-ink-2',
|
||||
)}
|
||||
>
|
||||
<span>{emoji}</span>
|
||||
{count > 0 && <span className="text-xs font-medium">{count}</span>}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,13 +3,14 @@ import { type ReactNode } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { useScrollLock } from '../../lib/scrollLock'
|
||||
import { useEscape } from '../../lib/escape'
|
||||
import { cx } from '../../lib/utils'
|
||||
|
||||
/** Écran plein (profil, recherche…) avec en-tête et bouton fermer. */
|
||||
export default function Sheet({ title, onClose, right, children, label }: { title: ReactNode; onClose: () => void; right?: ReactNode; children: ReactNode; label: string }) {
|
||||
export default function Sheet({ title, onClose, right, children, label, elevated }: { title: ReactNode; onClose: () => void; right?: ReactNode; children: ReactNode; label: string; elevated?: boolean }) {
|
||||
useScrollLock()
|
||||
useEscape(onClose)
|
||||
return (
|
||||
<div className="sheet-in fixed inset-0 z-50 flex flex-col bg-bg" role="dialog" aria-modal="true" aria-label={label}>
|
||||
<div className={cx('sheet-in fixed inset-0 flex flex-col bg-bg', elevated ? 'z-[70]' : 'z-50')} role="dialog" aria-modal="true" aria-label={label}>
|
||||
<header className="safe-top border-b border-line">
|
||||
<div className="mx-auto flex max-w-2xl items-center gap-2 px-3 py-2.5">
|
||||
<button onClick={onClose} className="grid size-10 place-items-center rounded-full text-ink-2" aria-label={t('common.close')}>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Loader2, Star } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { REACTION_EMOJIS, reactToReview, titleReviews, unreactReview, type ReactionEmoji, type TitleReview, type TitleReviews as TitleReviewsData } from '../../lib/cloud/reviews'
|
||||
import { cx, formatRating } from '../../lib/utils'
|
||||
import { titleReviews, type TitleReview, type TitleReviews as TitleReviewsData } from '../../lib/cloud/reviews'
|
||||
import { formatRating } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
import Avatar from './Avatar'
|
||||
import Reactions from './Reactions'
|
||||
import Sheet from './Sheet'
|
||||
|
||||
/** Écran plein : tous les avis sur un même titre (amis / autres membres) avec réactions. */
|
||||
@@ -25,7 +26,7 @@ export default function TitleReviews({ externalId, title, onClose, onOpenProfile
|
||||
const bothEmpty = !!data && data.friends.length === 0 && data.others.length === 0
|
||||
|
||||
return (
|
||||
<Sheet title={title} label={t('reviews.title')} onClose={onClose}>
|
||||
<Sheet title={title} label={t('reviews.title')} onClose={onClose} elevated>
|
||||
<p className="eyebrow px-4 pt-4">{t('reviews.title')}</p>
|
||||
{data === undefined && !error ? (
|
||||
<p className="flex items-center justify-center gap-2 px-4 py-16 text-sm text-ink-3">
|
||||
@@ -62,36 +63,6 @@ function ReviewColumn({ heading, empty, list, onOpenProfile }: { heading: string
|
||||
|
||||
function ReviewCard({ r, onOpenProfile }: { r: TitleReview; onOpenProfile: (username: string) => void }) {
|
||||
const { settings } = useMedia()
|
||||
const [reactions, setReactions] = useState<Record<string, number>>(r.reactions)
|
||||
const [mine, setMine] = useState<string | null>(r.mine)
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
const toggle = async (emoji: ReactionEmoji) => {
|
||||
if (busy) return
|
||||
const prev = { reactions, mine }
|
||||
const next: Record<string, number> = { ...reactions }
|
||||
if (mine === emoji) {
|
||||
next[emoji] = Math.max(0, (next[emoji] ?? 0) - 1)
|
||||
setReactions(next)
|
||||
setMine(null)
|
||||
} else {
|
||||
if (mine) next[mine] = Math.max(0, (next[mine] ?? 0) - 1)
|
||||
next[emoji] = (next[emoji] ?? 0) + 1
|
||||
setReactions(next)
|
||||
setMine(emoji)
|
||||
}
|
||||
setBusy(true)
|
||||
try {
|
||||
if (prev.mine === emoji) await unreactReview(r.user_id, r.item_id)
|
||||
else await reactToReview(r.user_id, r.item_id, emoji)
|
||||
} catch {
|
||||
setReactions(prev.reactions)
|
||||
setMine(prev.mine)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="card p-3.5">
|
||||
<div className="flex items-center gap-2.5">
|
||||
@@ -107,24 +78,9 @@ function ReviewCard({ r, onOpenProfile }: { r: TitleReview; onOpenProfile: (user
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{r.notes && <p className="mt-2 line-clamp-6 whitespace-pre-line text-sm leading-relaxed text-ink-2">{r.notes}</p>}
|
||||
<div className="mt-3 flex flex-wrap gap-1.5">
|
||||
{REACTION_EMOJIS.map((emoji) => {
|
||||
const count = reactions[emoji] ?? 0
|
||||
const on = mine === emoji
|
||||
return (
|
||||
<button
|
||||
key={emoji}
|
||||
onClick={() => void toggle(emoji)}
|
||||
disabled={busy}
|
||||
aria-pressed={on}
|
||||
className={cx('inline-flex items-center gap-1 rounded-full border px-2 py-1 text-sm transition-colors disabled:opacity-60', on ? 'border-accent text-ink' : 'border-line text-ink-2')}
|
||||
>
|
||||
<span>{emoji}</span>
|
||||
{count > 0 && <span className="text-xs font-medium">{count}</span>}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
{r.notes && <p className="mt-2 whitespace-pre-line text-sm leading-relaxed text-ink-2">{r.notes}</p>}
|
||||
<div className="mt-3">
|
||||
<Reactions authorId={r.user_id} itemId={r.item_id} reactions={r.reactions} mine={r.mine} />
|
||||
</div>
|
||||
</article>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user