maj
deploy / deploy (push) Successful in 33s

This commit is contained in:
Romain committed 2026-10-05 21:25:56 +02:00
1 parent 04b5005e3b
commit 51a320b31f
29 files changed
+1139 -7

No files matched your search

+8 -1
View File
@@ -1,5 +1,5 @@
import { locale, t } from '../i18n'
import { Check, Heart, ImagePlus, Loader2, Minus, Plus, Share2, Trash2, X } from 'lucide-react'
import { Check, Heart, ImagePlus, Loader2, MessagesSquare, Minus, Plus, Share2, Trash2, X } from 'lucide-react'
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
import { CRITERIA, DEFAULT_FILM_MINUTES, MEDIA_TYPES, STATUSES, TYPE_BY_VALUE } from '../lib/constants'
import { canonicalGenre, canonicalSubtype, genreLabel, genreSuggestions as defaultGenres, subtypeLabel, subtypeSuggestions } from '../lib/genres'
@@ -18,6 +18,7 @@ import SharePreview from './SharePreview'
import DatabaseSearch from './DatabaseSearch'
import EpisodeList from './EpisodeList'
import ItemHero, { type HeroAction } from './ItemHero'
import { useSocial } from './social/SocialProvider'
import { NewListForm } from './ListsView'
import Poster from './Poster'
import { RatingInput } from './Rating'
@@ -136,6 +137,7 @@ function Rewatches({ dates, onChange }: { dates: string[]; onChange: (d: string[
}
export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: Props) {
const social = useSocial()
const { add, update, remove, items, settings, lists, patchMany } = useMedia()
const [form, setForm] = useState<MediaInput>(() => {
if (!item) return EMPTY
@@ -597,6 +599,11 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
<Section title={t('form.review')}>
<textarea className="field min-h-32 resize-y" value={form.notes ?? ''} onChange={(e) => set('notes', e.target.value)} placeholder={t('form.reviewPh')} />
{form.externalId && social.enabled && (
<button type="button" onClick={() => social.openReviews(form.externalId!, form.title)} className="mt-3 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>
)}
</Section>
<div className="space-y-2 border-t border-line pt-6">
+9 -1
View File
@@ -1,8 +1,9 @@
import { Check, Loader2, Plus, Star } from 'lucide-react'
import { Check, Loader2, MessagesSquare, Plus, Star } from 'lucide-react'
import { useState } from 'react'
import { t } from '../../i18n'
import { genreLabel } from '../../lib/genres'
import { useScrollLock } from '../../lib/scrollLock'
import { useSocial } from './SocialProvider'
import { cx, formatDate, formatRating, normalizeText } from '../../lib/utils'
import { useMedia } from '../../store'
import type { MediaInput, MediaItem } from '../../types'
@@ -20,6 +21,7 @@ export interface PeekOwner {
/** Aperçu d'un titre de quelqu'un d'autre : sa note, son avis public, et ajout à ma liste « À voir ». */
export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; owner?: PeekOwner; onClose: () => void }) {
const { items, add, settings } = useMedia()
const social = useSocial()
const [busy, setBusy] = useState(false)
const [added, setAdded] = useState(false)
const owned = items.some(
@@ -107,6 +109,12 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
</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">
<MessagesSquare size={16} /> {t('reviews.seeAll')}
</button>
)}
{item.overview && <p className="mt-4 line-clamp-5 text-sm leading-relaxed text-ink-2">{item.overview}</p>}
<div className="mt-5 grid grid-cols-2 gap-2">
+127
View File
@@ -0,0 +1,127 @@
import { Loader2 } 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 Sheet from './Sheet'
const PAGE = 30
const FOLLOW_KINDS: NotificationKind[] = ['follow_request', 'follow_accepted', 'new_follower']
const VERB: Record<NotificationKind, () => string> = {
follow_request: () => t('notif.follow_request'),
follow_accepted: () => t('notif.follow_accepted'),
new_follower: () => t('notif.new_follower'),
reaction: () => t('notif.reaction'),
}
/** Liste des notifications (abonnements, demandes acceptées, réactions). Marque comme lues à l'ouverture. */
export default function Notifications({ onClose, onOpenProfile }: { onClose: () => void; onOpenProfile: (username: string) => void }) {
const [items, setItems] = useState<AppNotification[] | undefined>(undefined)
const [done, setDone] = useState(false)
const [loadingMore, setLoadingMore] = useState(false)
useEffect(() => {
let alive = true
void (async () => {
try {
const page = await listNotifications(0)
if (!alive) return
setItems(page)
setDone(page.length < PAGE)
} catch {
if (alive) {
setItems([])
setDone(true)
}
}
// Marque comme lu (feu et oubli) pour vider le badge
markNotificationsRead().catch(() => {})
})()
return () => {
alive = false
}
}, [])
const loadMore = async () => {
if (!items || loadingMore) return
setLoadingMore(true)
try {
const page = await listNotifications(items.length)
setItems((prev) => [...(prev ?? []), ...page])
setDone(page.length < PAGE)
} catch {
setDone(true)
} finally {
setLoadingMore(false)
}
}
return (
<Sheet title={t('notif.title')} label={t('notif.title')} onClose={onClose}>
{items === undefined ? (
<p className="flex items-center justify-center py-16 text-ink-3">
<Loader2 size={20} className="animate-spin" />
</p>
) : items.length === 0 ? (
<div className="px-4">
<EmptyState title={t('notif.empty')} />
</div>
) : (
<ul>
{items.map((n) => (
<Row key={n.id} n={n} onOpenProfile={onOpenProfile} />
))}
{!done && (
<li className="p-4">
<button onClick={loadMore} disabled={loadingMore} className="btn btn-ghost w-full">
{loadingMore ? <Loader2 size={15} className="animate-spin" /> : t('social.loadMore')}
</button>
</li>
)}
</ul>
)}
</Sheet>
)
}
function Row({ n, onOpenProfile }: { n: AppNotification; onOpenProfile: (username: string) => void }) {
const actor = n.actor
const actorName = actor?.display_name ?? t('notif.someone')
const unread = n.read_at === null
const username = actor?.username
const target = username != null && FOLLOW_KINDS.includes(n.kind) ? username : null
const inner = (
<>
{unread && <span className="size-2 shrink-0 rounded-full bg-accent-fill" aria-hidden="true" />}
<Avatar url={actor?.avatar_url ?? undefined} name={actorName} size={38} />
<span className="min-w-0 flex-1 text-sm leading-snug text-ink-2">
<b className="text-ink">{actorName}</b> {VERB[n.kind]()}
{n.kind === 'reaction' && (
<>
{n.emoji ? ` ${n.emoji}` : ''}
{n.title ? ` ${t('notif.on', { title: n.title })}` : ''}
</>
)}
</span>
<span className="shrink-0 text-xs text-ink-3">{formatDate(n.created_at)}</span>
</>
)
const base = cx('flex items-center gap-3 border-b border-line px-4 py-3 text-start', unread && 'bg-surface-2')
return (
<li>
{target != null ? (
<button onClick={() => onOpenProfile(target)} className={cx(base, 'w-full')}>
{inner}
</button>
) : (
<div className={base}>{inner}</div>
)}
</li>
)
}
+30 -3
View File
@@ -1,5 +1,6 @@
import { createContext, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
import { getFollowRequests, getMyProfile, type Profile, type ProfileCard } from '../../lib/cloud/social'
import { markNotificationsRead, unreadCount } from '../../lib/cloud/notifications'
import { useMedia } from '../../store'
import type { MediaItem } from '../../types'
import EditProfile from './EditProfile'
@@ -7,6 +8,8 @@ import FollowList from './FollowList'
import ItemPeek, { type PeekOwner } from './ItemPeek'
import PeopleSearch from './PeopleSearch'
import ProfileView from './ProfileView'
import TitleReviews from './TitleReviews'
import Notifications from './Notifications'
import { useOnResume } from '../../lib/onResume'
import WelcomeProfile, { RANDOM_USERNAME } from './WelcomeProfile'
@@ -20,6 +23,12 @@ interface SocialApi {
openSearch: () => void
openEdit: () => void
openFollowList: (profile: Profile, kind: 'followers' | 'following') => void
/** Tous les avis sur un titre (amis / autres) */
openReviews: (externalId: string, title: string) => void
/** Panneau des notifications */
openNotifications: () => void
/** Notifications non lues */
unread: number
peek: (item: MediaItem, owner?: PeekOwner) => void
/** Ouvre la fiche si elle est à moi, sinon l'aperçu */
openItem: (item: MediaItem, owner?: PeekOwner) => void
@@ -34,6 +43,9 @@ const SocialContext = createContext<SocialApi>({
openSearch: () => {},
openEdit: () => {},
openFollowList: () => {},
openReviews: () => {},
openNotifications: () => {},
unread: 0,
peek: () => {},
openItem: () => {},
})
@@ -45,6 +57,8 @@ type Overlay =
| { kind: 'search' }
| { kind: 'edit' }
| { kind: 'follows'; profile: Profile; list: 'followers' | 'following' }
| { kind: 'reviews'; externalId: string; title: string }
| { kind: 'notifications' }
/** 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 }) {
@@ -52,6 +66,7 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
const enabled = !!account
const [me, setMe] = useState<Profile | null>(null)
const [requests, setRequests] = useState<ProfileCard[]>([])
const [unread, setUnread] = useState(0)
const [stack, setStack] = useState<Overlay[]>([])
const [peeked, setPeeked] = useState<{ item: MediaItem; owner?: PeekOwner }>()
// « Plus tard » sur le choix du pseudo : redemandé au prochain lancement
@@ -74,9 +89,10 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
const refresh = useCallback(async () => {
if (!enabled || !navigator.onLine) return
try {
const [p, r] = await Promise.all([getMyProfile(), getFollowRequests()])
const [p, r, u] = await Promise.all([getMyProfile(), getFollowRequests(), unreadCount()])
setMe(p)
setRequests(r)
setUnread(u)
} catch {
/* hors-ligne / serveur pas encore à jour : le reste de l'app fonctionne */
}
@@ -125,10 +141,17 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
openSearch: () => push({ kind: 'search' }),
openEdit: () => push({ kind: 'edit' }),
openFollowList: (profile, list) => push({ kind: 'follows', profile, list }),
openReviews: (externalId, title) => push({ kind: 'reviews', externalId, title }),
openNotifications: () => {
setUnread(0)
void markNotificationsRead().catch(() => {})
push({ kind: 'notifications' })
},
unread,
peek: (item, owner) => setPeeked({ item, owner }),
openItem,
}),
[enabled, me, requests, refresh, push, openItem],
[enabled, me, requests, unread, refresh, push, openItem],
)
return (
@@ -142,8 +165,12 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
<PeopleSearch key={k} onClose={pop} />
) : o.kind === 'edit' ? (
<EditProfile key={k} onClose={pop} />
) : (
) : o.kind === 'follows' ? (
<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 })} />
) : (
<Notifications key={k} onClose={pop} onOpenProfile={(u) => push({ kind: 'profile', username: u })} />
),
)}
{children}
+131
View File
@@ -0,0 +1,131 @@
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 { useMedia } from '../../store'
import Avatar from './Avatar'
import Sheet from './Sheet'
/** Écran plein : tous les avis sur un même titre (amis / autres membres) avec réactions. */
export default function TitleReviews({ externalId, title, onClose, onOpenProfile }: { externalId: string; title: string; onClose: () => void; onOpenProfile: (username: string) => void }) {
const [data, setData] = useState<TitleReviewsData>()
const [error, setError] = useState(false)
useEffect(() => {
let alive = true
titleReviews(externalId)
.then((d) => alive && setData(d))
.catch(() => alive && setError(true))
return () => {
alive = false
}
}, [externalId])
const bothEmpty = !!data && data.friends.length === 0 && data.others.length === 0
return (
<Sheet title={title} label={t('reviews.title')} onClose={onClose}>
<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">
<Loader2 size={16} className="animate-spin" /> {t('social.loading')}
</p>
) : !data || error || bothEmpty ? (
<p className="px-4 py-16 text-center text-sm text-ink-3">{t('reviews.none')}</p>
) : (
<div className="grid grid-cols-1 gap-4 px-4 pt-4 sm:grid-cols-2">
<ReviewColumn heading={t('reviews.friends')} empty={t('reviews.noneFriends')} list={data.friends} onOpenProfile={onOpenProfile} />
<ReviewColumn heading={t('reviews.others')} empty={t('reviews.noneOthers')} list={data.others} onOpenProfile={onOpenProfile} />
</div>
)}
</Sheet>
)
}
function ReviewColumn({ heading, empty, list, onOpenProfile }: { heading: string; empty: string; list: TitleReview[]; onOpenProfile: (username: string) => void }) {
return (
<section>
<p className="eyebrow mb-2">{heading}</p>
{list.length === 0 ? (
<p className="text-sm text-ink-3">{empty}</p>
) : (
<div className="space-y-3">
{list.map((r) => (
<ReviewCard key={`${r.user_id}-${r.item_id}`} r={r} onOpenProfile={onOpenProfile} />
))}
</div>
)}
</section>
)
}
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">
<Avatar url={r.user.avatar_url ?? undefined} name={r.user.display_name} size={34} />
<button onClick={() => onOpenProfile(r.user.username)} className="min-w-0 flex-1 text-start">
<p className="truncate text-sm font-semibold">{r.user.display_name}</p>
<p className="truncate text-xs text-ink-3">@{r.user.username}</p>
</button>
{r.rating != null && (
<span className="flex shrink-0 items-center gap-0.5 text-sm font-semibold text-ink-2">
<Star size={12} className="fill-accent text-accent" />
{formatRating(r.rating, settings.ratingScale)}
</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>
)
})}
</div>
</article>
)
}