correcition
This commit is contained in:
1 parent
d723078d89
commit
1dde1311a3
15 files changed
+100
-55
No files matched your search
@@ -7,6 +7,7 @@ import { cachedMonth, isBrowsableMonth, loadMonth, RELEASE_CATEGORIES } from '..
|
||||
import { remotePosterToLocal } from '../lib/image'
|
||||
import { calendarEvents, loadReleases, refreshReleases } from '../lib/releases'
|
||||
import { readStorage } from '../lib/security'
|
||||
import { useScrollLock } from '../lib/scrollLock'
|
||||
import { cx, normalizeText, todayISO } from '../lib/utils'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaInput, MediaItem, MediaType } from '../types'
|
||||
@@ -107,13 +108,7 @@ export default function CalendarView({ onClose, onOpen }: { onClose: () => void;
|
||||
const [added, setAdded] = useState<Set<string>>(new Set())
|
||||
const request = useRef(0)
|
||||
|
||||
useEffect(() => {
|
||||
const prev = document.body.style.overflow
|
||||
document.body.style.overflow = 'hidden'
|
||||
return () => {
|
||||
document.body.style.overflow = prev
|
||||
}
|
||||
}, [])
|
||||
useScrollLock()
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { canonicalGenre, canonicalSubtype, genreLabel, genreSuggestions as defau
|
||||
import { fileToPosterDataURL } from '../lib/image'
|
||||
import { getTmdbCredits } from '../lib/catalogApi'
|
||||
import { renderItemCard, slug } from '../lib/shareCard'
|
||||
import { useScrollLock } from '../lib/scrollLock'
|
||||
import { cx, formatRating, todayISO } from '../lib/utils'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaInput, MediaItem, RatingScale, WatchStatus } from '../types'
|
||||
@@ -127,7 +128,7 @@ function Rewatches({ dates, onChange }: { dates: string[]; onChange: (d: string[
|
||||
}
|
||||
|
||||
export default function MediaForm({ item, onClose, onGoToSettings }: Props) {
|
||||
const { add, update, remove, items, settings, lists, account } = useMedia()
|
||||
const { add, update, remove, items, settings, lists } = useMedia()
|
||||
const [form, setForm] = useState<MediaInput>(() => {
|
||||
if (!item) return EMPTY
|
||||
const { id: _id, createdAt: _c, updatedAt: _u, ...rest } = item
|
||||
@@ -142,13 +143,7 @@ export default function MediaForm({ item, onClose, onGoToSettings }: Props) {
|
||||
const typeInfo = TYPE_BY_VALUE[form.type]
|
||||
|
||||
// Bloque le défilement de la page derrière la feuille
|
||||
useEffect(() => {
|
||||
const prev = document.body.style.overflow
|
||||
document.body.style.overflow = 'hidden'
|
||||
return () => {
|
||||
document.body.style.overflow = prev
|
||||
}
|
||||
}, [])
|
||||
useScrollLock()
|
||||
|
||||
const set = <K extends keyof MediaInput>(key: K, value: MediaInput[K]) => setForm((f) => ({ ...f, [key]: value }))
|
||||
|
||||
@@ -179,6 +174,11 @@ export default function MediaForm({ item, onClose, onGoToSettings }: Props) {
|
||||
const setStatus = (status: WatchStatus) =>
|
||||
setForm((f) => {
|
||||
const next = { ...f, status }
|
||||
// « À voir » : pas encore regardé, donc pas de dates
|
||||
if (status === 'a_voir') {
|
||||
next.startDate = undefined
|
||||
next.endDate = undefined
|
||||
}
|
||||
if (status === 'en_cours' && !f.startDate) next.startDate = todayISO()
|
||||
if (status === 'termine') {
|
||||
if (!f.endDate) next.endDate = todayISO()
|
||||
@@ -511,15 +511,6 @@ export default function MediaForm({ item, onClose, onGoToSettings }: Props) {
|
||||
|
||||
<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')} />
|
||||
{account && (
|
||||
<label className="mt-3 flex items-start gap-2.5 text-sm text-ink-2">
|
||||
<input type="checkbox" className="mt-0.5 size-4 accent-[var(--color-accent)]" checked={!!form.notesPublic} onChange={(e) => set('notesPublic', e.target.checked || undefined)} />
|
||||
<span>
|
||||
{t('form.reviewPublic')}
|
||||
<span className="block text-xs text-ink-3">{t('form.reviewPublicHint')}</span>
|
||||
</span>
|
||||
</label>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<div className="space-y-2 border-t border-line pt-6">
|
||||
|
||||
@@ -20,6 +20,7 @@ import type { MediaItem } from '../types'
|
||||
import { TypeBadge } from './Badges'
|
||||
import Poster from './Poster'
|
||||
import { RatingBadge } from './Rating'
|
||||
import { useScrollLock } from '../lib/scrollLock'
|
||||
|
||||
const CARD = 112 // largeur d'une affiche dans le rouleau (w-28)
|
||||
const GAP = 12
|
||||
@@ -68,13 +69,7 @@ export default function Roulette({ onClose, onOpen }: Props) {
|
||||
}
|
||||
|
||||
// Bloque le défilement derrière + mémorise les filtres
|
||||
useEffect(() => {
|
||||
const prev = document.body.style.overflow
|
||||
document.body.style.overflow = 'hidden'
|
||||
return () => {
|
||||
document.body.style.overflow = prev
|
||||
}
|
||||
}, [])
|
||||
useScrollLock()
|
||||
useEffect(() => saveFilters(filters), [filters])
|
||||
|
||||
// Changer les filtres efface le tirage en cours
|
||||
|
||||
@@ -14,7 +14,7 @@ interface Props {
|
||||
normalize?: (input: string) => string
|
||||
}
|
||||
|
||||
/** Saisie de tags libres avec suggestions tapables. */
|
||||
/** Saisie de tags libres ; des suggestions apparaissent quand on commence à taper. */
|
||||
export default function TagInput({ value, onChange, suggestions, placeholder, display = (v) => v, normalize = (v) => v }: Props) {
|
||||
const [text, setText] = useState('')
|
||||
|
||||
@@ -29,7 +29,9 @@ export default function TagInput({ value, onChange, suggestions, placeholder, di
|
||||
const filtered = useMemo(() => {
|
||||
const q = normalizeText(text)
|
||||
const taken = new Set(value.map((v) => normalizeText(display(v))))
|
||||
return suggestions.filter((s) => !taken.has(normalizeText(s)) && (!q || normalizeText(s).includes(q))).slice(0, 12)
|
||||
// Suggestions seulement pendant la saisie (pas de rangée de genres affichée en permanence)
|
||||
if (!q) return []
|
||||
return suggestions.filter((s) => !taken.has(normalizeText(s)) && normalizeText(s).includes(q)).slice(0, 12)
|
||||
}, [text, value, suggestions])
|
||||
|
||||
return (
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useMedia } from '../store'
|
||||
import type { TopCategory } from '../types'
|
||||
import { TypeBadge } from './Badges'
|
||||
import Poster from './Poster'
|
||||
import { useScrollLock } from '../lib/scrollLock'
|
||||
|
||||
interface Props {
|
||||
category: TopCategory
|
||||
@@ -29,13 +30,7 @@ export default function TopFiveEditor({ category: initialCategory, onClose }: Pr
|
||||
const catInfo = TOP_CATEGORIES.find((c) => c.value === category)!
|
||||
const byId = useMemo(() => new Map(items.map((i) => [i.id, i])), [items])
|
||||
|
||||
useEffect(() => {
|
||||
const prev = document.body.style.overflow
|
||||
document.body.style.overflow = 'hidden'
|
||||
return () => {
|
||||
document.body.style.overflow = prev
|
||||
}
|
||||
}, [])
|
||||
useScrollLock()
|
||||
|
||||
/** Changer de catégorie enregistre d'abord celle en cours. */
|
||||
const switchCategory = async (cat: TopCategory) => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Loader2, Star, UserPlus } from 'lucide-react'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { getFeed, type FeedEntry } from '../../lib/cloud/social'
|
||||
import { useOnResume } from '../../lib/onResume'
|
||||
import { timeAgo } from '../../lib/timeAgo'
|
||||
import { formatRating } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
@@ -34,6 +35,13 @@ export default function FriendsFeed() {
|
||||
useEffect(() => {
|
||||
if (social.enabled && navigator.onLine) void load()
|
||||
}, [social.enabled, load])
|
||||
// Retour sur l'app : on récupère ce que les abonnements ont ajouté entre-temps
|
||||
useOnResume(() => void load(), social.enabled)
|
||||
// Abonnement / désabonnement : le fil change aussi
|
||||
const followKey = `${social.me?.following ?? ''}`
|
||||
useEffect(() => {
|
||||
if (social.enabled && followKey && navigator.onLine) void load()
|
||||
}, [followKey, social.enabled, load])
|
||||
|
||||
if (!social.enabled) return null
|
||||
|
||||
@@ -86,7 +94,7 @@ export default function FriendsFeed() {
|
||||
{formatRating(e.item.rating, settings.ratingScale)}
|
||||
</span>
|
||||
)}
|
||||
{e.item.notes && e.item.notesPublic && <span>{t('feed.review')}</span>}
|
||||
{e.item.notes && <span>{t('feed.review')}</span>}
|
||||
<span>{timeAgo(e.createdAt)}</span>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Check, Loader2, Plus, Star } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { genreLabel } from '../../lib/genres'
|
||||
import { useScrollLock } from '../../lib/scrollLock'
|
||||
import { cx, formatDate, formatRating, normalizeText } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
import type { MediaInput, MediaItem } from '../../types'
|
||||
@@ -24,6 +25,8 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
|
||||
(i) => (item.externalId && i.externalId === item.externalId) || normalizeText(i.title) === normalizeText(item.title),
|
||||
)
|
||||
|
||||
useScrollLock()
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
|
||||
window.addEventListener('keydown', onKey)
|
||||
@@ -61,12 +64,12 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[60] flex items-end justify-center bg-black/70 sm:items-center sm:p-4" onClick={onClose}>
|
||||
<div className="fixed inset-0 z-[60] flex touch-none items-end justify-center overscroll-none bg-black/70 sm:items-center sm:p-4" onClick={onClose}>
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={item.title}
|
||||
className="sheet-in safe-bottom max-h-[88dvh] w-full max-w-md overflow-y-auto rounded-t-3xl border border-line-strong bg-surface p-5 sm:rounded-3xl"
|
||||
className="sheet-in safe-bottom max-h-[88dvh] w-full max-w-md touch-pan-y overflow-y-auto overscroll-contain rounded-t-3xl border border-line-strong bg-surface p-5 sm:rounded-3xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex gap-4">
|
||||
|
||||
@@ -21,6 +21,7 @@ export default function PersonRow({ person, actions }: { person: ProfileCard; ac
|
||||
await unfollow(person.id)
|
||||
setRelation('none')
|
||||
}
|
||||
void social.refresh()
|
||||
} catch {
|
||||
/* réseau : rien ne change */
|
||||
} finally {
|
||||
|
||||
@@ -108,6 +108,7 @@ export default function ProfileView({ username, onClose }: { username: string; o
|
||||
try {
|
||||
await follow(profile.id)
|
||||
await load()
|
||||
void social.refresh()
|
||||
} catch (e) {
|
||||
setToast((e as Error).message)
|
||||
} finally {
|
||||
@@ -122,6 +123,7 @@ export default function ProfileView({ username, onClose }: { username: string; o
|
||||
try {
|
||||
await unfollow(profile.id)
|
||||
await load()
|
||||
void social.refresh()
|
||||
} catch (e) {
|
||||
setToast((e as Error).message)
|
||||
} finally {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import { X } from 'lucide-react'
|
||||
import { useEffect, type ReactNode } from 'react'
|
||||
import { t } from '../../i18n'
|
||||
import { useScrollLock } from '../../lib/scrollLock'
|
||||
|
||||
/** É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 }) {
|
||||
useScrollLock()
|
||||
useEffect(() => {
|
||||
const prev = document.body.style.overflow
|
||||
document.body.style.overflow = 'hidden'
|
||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => {
|
||||
document.body.style.overflow = prev
|
||||
window.removeEventListener('keydown', onKey)
|
||||
}
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [onClose])
|
||||
return (
|
||||
<div className="sheet-in fixed inset-0 z-50 flex flex-col bg-bg" role="dialog" aria-modal="true" aria-label={label}>
|
||||
|
||||
@@ -7,6 +7,7 @@ import FollowList from './FollowList'
|
||||
import ItemPeek, { type PeekOwner } from './ItemPeek'
|
||||
import PeopleSearch from './PeopleSearch'
|
||||
import ProfileView from './ProfileView'
|
||||
import { useOnResume } from '../../lib/onResume'
|
||||
import WelcomeProfile, { RANDOM_USERNAME } from './WelcomeProfile'
|
||||
|
||||
interface SocialApi {
|
||||
@@ -84,6 +85,8 @@ export function SocialProvider({ children, onOpenOwnItem }: { children: ReactNod
|
||||
useEffect(() => {
|
||||
void refresh()
|
||||
}, [refresh])
|
||||
// Nouvelles demandes d'abonnement, compteurs… mis à jour au retour sur l'app
|
||||
useOnResume(() => void refresh(), enabled)
|
||||
|
||||
const push = useCallback((o: Overlay) => setStack((s) => [...s.slice(-8), o]), [])
|
||||
const pop = useCallback(() => setStack((s) => s.slice(0, -1)), [])
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
|
||||
/**
|
||||
* Relance `fn` quand l'app revient au premier plan (onglet réaffiché, PWA rouverte, réseau retrouvé),
|
||||
* au plus une fois toutes les `minGapMs`.
|
||||
*/
|
||||
export function useOnResume(fn: () => void, enabled = true, minGapMs = 20_000) {
|
||||
const last = useRef(Date.now())
|
||||
const cb = useRef(fn)
|
||||
cb.current = fn
|
||||
useEffect(() => {
|
||||
if (!enabled) return
|
||||
const run = () => {
|
||||
if (document.visibilityState !== 'visible' || !navigator.onLine) return
|
||||
if (Date.now() - last.current < minGapMs) return
|
||||
last.current = Date.now()
|
||||
cb.current()
|
||||
}
|
||||
document.addEventListener('visibilitychange', run)
|
||||
window.addEventListener('focus', run)
|
||||
window.addEventListener('online', run)
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', run)
|
||||
window.removeEventListener('focus', run)
|
||||
window.removeEventListener('online', run)
|
||||
}
|
||||
}, [enabled, minGapMs])
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { useEffect } from 'react'
|
||||
|
||||
/**
|
||||
* Bloque le défilement de la page derrière une fenêtre (fiche, profil, aperçu…).
|
||||
* Compteur partagé : avec plusieurs fenêtres empilées, la page ne se débloque qu'à la fermeture de la dernière.
|
||||
*/
|
||||
let locks = 0
|
||||
|
||||
function apply(on: boolean) {
|
||||
for (const el of [document.documentElement, document.body]) {
|
||||
el.style.overflow = on ? 'hidden' : ''
|
||||
el.style.overscrollBehavior = on ? 'none' : ''
|
||||
}
|
||||
}
|
||||
|
||||
export function useScrollLock() {
|
||||
useEffect(() => {
|
||||
if (locks++ === 0) apply(true)
|
||||
return () => {
|
||||
if (--locks === 0) apply(false)
|
||||
}
|
||||
}, [])
|
||||
}
|
||||
Reference in new issue
Block a user