Démarrage plus léger : écrans rares chargés à la demande
- Stats, Réglages, Admin, Roulette, Calendrier, fiche personne, saisie manuelle et écrans sociaux (profil, recherche de membres, abonnés, avis, notifications, aperçu) chargés à la demande, puis préchargés dès que l'app est au repos : ils s'ouvrent ensuite sans attente - Carte de partage chargée au moment du partage - Fichier principal : 784 Ko → 620 Ko - Noms de fichiers exportés : bobinoo-… au lieu de kino-… Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
6 files changed
+95
-44
No files matched your search
+54
-25
@@ -1,26 +1,42 @@
|
|||||||
import { SocialProvider } from './components/social/SocialProvider'
|
import { preloadSocial, SocialProvider } from './components/social/SocialProvider'
|
||||||
import { ToastProvider } from './components/Toast'
|
import { ToastProvider } from './components/Toast'
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { lazy, Suspense, useCallback, useEffect, useState } from 'react'
|
||||||
import BottomNav, { type Tab } from './components/BottomNav'
|
import BottomNav, { type Tab } from './components/BottomNav'
|
||||||
import SideNav from './components/SideNav'
|
import SideNav from './components/SideNav'
|
||||||
import AddTitle from './components/title/AddTitle'
|
import AddTitle from './components/title/AddTitle'
|
||||||
import EditDetails from './components/title/EditDetails'
|
|
||||||
import TitleSheet from './components/title/TitleSheet'
|
import TitleSheet from './components/title/TitleSheet'
|
||||||
import PersonSheet from './components/person/PersonSheet'
|
|
||||||
import Roulette from './components/Roulette'
|
|
||||||
import CalendarView from './components/CalendarView'
|
|
||||||
import HomePage from './pages/HomePage'
|
import HomePage from './pages/HomePage'
|
||||||
import CatalogPage from './pages/CatalogPage'
|
import CatalogPage from './pages/CatalogPage'
|
||||||
import StatsPage from './pages/StatsPage'
|
|
||||||
import SettingsPage from './pages/SettingsPage'
|
|
||||||
import AdminPage from './pages/AdminPage'
|
|
||||||
import NotFoundPage from './pages/NotFoundPage'
|
|
||||||
import SyncIndicator from './components/SyncIndicator'
|
import SyncIndicator from './components/SyncIndicator'
|
||||||
import { useMedia } from './store'
|
import { useMedia } from './store'
|
||||||
import type { SearchResult } from './lib/catalogApi'
|
import type { SearchResult } from './lib/catalogApi'
|
||||||
import type { MediaItem } from './types'
|
import type { MediaItem } from './types'
|
||||||
import type { Completion } from './lib/seasons'
|
import type { Completion } from './lib/seasons'
|
||||||
|
|
||||||
|
// Écrans moins fréquents : chargés à la demande (démarrage plus léger), puis préchargés quand l'app est au repos
|
||||||
|
const loaders = {
|
||||||
|
EditDetails: () => import('./components/title/EditDetails'),
|
||||||
|
PersonSheet: () => import('./components/person/PersonSheet'),
|
||||||
|
Roulette: () => import('./components/Roulette'),
|
||||||
|
CalendarView: () => import('./components/CalendarView'),
|
||||||
|
StatsPage: () => import('./pages/StatsPage'),
|
||||||
|
SettingsPage: () => import('./pages/SettingsPage'),
|
||||||
|
AdminPage: () => import('./pages/AdminPage'),
|
||||||
|
NotFoundPage: () => import('./pages/NotFoundPage'),
|
||||||
|
}
|
||||||
|
const EditDetails = lazy(loaders.EditDetails)
|
||||||
|
const PersonSheet = lazy(loaders.PersonSheet)
|
||||||
|
const Roulette = lazy(loaders.Roulette)
|
||||||
|
const CalendarView = lazy(loaders.CalendarView)
|
||||||
|
const StatsPage = lazy(loaders.StatsPage)
|
||||||
|
const SettingsPage = lazy(loaders.SettingsPage)
|
||||||
|
const AdminPage = lazy(loaders.AdminPage)
|
||||||
|
const NotFoundPage = lazy(loaders.NotFoundPage)
|
||||||
|
function preloadScreens() {
|
||||||
|
for (const load of Object.values(loaders)) void load().catch(() => {})
|
||||||
|
preloadSocial()
|
||||||
|
}
|
||||||
|
|
||||||
const TABS: Tab[] = ['home', 'catalog', 'stats', 'settings']
|
const TABS: Tab[] = ['home', 'catalog', 'stats', 'settings']
|
||||||
// L'administration a sa propre route (#/admin), hors de la navigation principale
|
// L'administration a sa propre route (#/admin), hors de la navigation principale
|
||||||
type Route = Tab | 'admin' | 'notfound'
|
type Route = Tab | 'admin' | 'notfound'
|
||||||
@@ -56,6 +72,12 @@ export default function App() {
|
|||||||
const [roulette, setRoulette] = useState(false)
|
const [roulette, setRoulette] = useState(false)
|
||||||
const [calendar, setCalendar] = useState(false)
|
const [calendar, setCalendar] = useState(false)
|
||||||
|
|
||||||
|
// Les écrans chargés à la demande arrivent en arrière-plan une fois l'app affichée : ils s'ouvrent ensuite sans attente
|
||||||
|
useEffect(() => {
|
||||||
|
const idle = window.requestIdleCallback ?? ((cb: () => void) => window.setTimeout(cb, 1500))
|
||||||
|
idle(preloadScreens)
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onHash = () => setRoute(routeFromHash())
|
const onHash = () => setRoute(routeFromHash())
|
||||||
window.addEventListener('hashchange', onHash)
|
window.addEventListener('hashchange', onHash)
|
||||||
@@ -99,17 +121,21 @@ export default function App() {
|
|||||||
{error && <p className="mt-4 rounded-xl border border-accent p-3 text-sm text-ink">{error}</p>}
|
{error && <p className="mt-4 rounded-xl border border-accent p-3 text-sm text-ink">{error}</p>}
|
||||||
{route === 'home' && <HomePage onOpen={openItem} onAdd={openNew} onNavigate={go} onRoulette={() => setRoulette(true)} onCalendar={() => setCalendar(true)} />}
|
{route === 'home' && <HomePage onOpen={openItem} onAdd={openNew} onNavigate={go} onRoulette={() => setRoulette(true)} onCalendar={() => setCalendar(true)} />}
|
||||||
{route === 'catalog' && <CatalogPage onOpen={openItem} onAdd={openNew} />}
|
{route === 'catalog' && <CatalogPage onOpen={openItem} onAdd={openNew} />}
|
||||||
{route === 'stats' && <StatsPage onOpen={openItem} />}
|
<Suspense fallback={null}>
|
||||||
{route === 'settings' && <SettingsPage onOpenAdmin={() => go('admin')} />}
|
{route === 'stats' && <StatsPage onOpen={openItem} />}
|
||||||
{route === 'admin' && <AdminPage onBack={() => go('settings')} />}
|
{route === 'settings' && <SettingsPage onOpenAdmin={() => go('admin')} />}
|
||||||
{route === 'notfound' && <NotFoundPage onHome={() => go('home')} />}
|
{route === 'admin' && <AdminPage onBack={() => go('settings')} />}
|
||||||
|
{route === 'notfound' && <NotFoundPage onHome={() => go('home')} />}
|
||||||
|
</Suspense>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<BottomNav current={navTab} onChange={go} onAdd={openNew} />
|
<BottomNav current={navTab} onChange={go} onAdd={openNew} />
|
||||||
<SyncIndicator />
|
<SyncIndicator />
|
||||||
|
|
||||||
{roulette && <Roulette onClose={() => setRoulette(false)} onOpen={openItem} />}
|
<Suspense fallback={null}>
|
||||||
{calendar && <CalendarView onClose={() => setCalendar(false)} onOpen={openItem} />}
|
{roulette && <Roulette onClose={() => setRoulette(false)} onOpen={openItem} />}
|
||||||
|
{calendar && <CalendarView onClose={() => setCalendar(false)} onOpen={openItem} />}
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
{adding && (
|
{adding && (
|
||||||
<AddTitle
|
<AddTitle
|
||||||
@@ -134,18 +160,20 @@ export default function App() {
|
|||||||
onDone={backHome}
|
onDone={backHome}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<PersonSheet
|
<Suspense key={l.uid} fallback={null}>
|
||||||
key={l.uid}
|
<PersonSheet
|
||||||
personId={l.personId}
|
personId={l.personId}
|
||||||
name={l.name}
|
name={l.name}
|
||||||
photo={l.photo}
|
photo={l.photo}
|
||||||
onClose={() => closeLayer(l.uid)}
|
onClose={() => closeLayer(l.uid)}
|
||||||
onOpenItem={openItem}
|
onOpenItem={openItem}
|
||||||
onOpenSeed={openSeed}
|
onOpenSeed={openSeed}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
{manual !== null && (
|
{manual !== null && (
|
||||||
|
<Suspense fallback={null}>
|
||||||
<EditDetails
|
<EditDetails
|
||||||
initialTitle={manual}
|
initialTitle={manual}
|
||||||
onClose={() => setManual(null)}
|
onClose={() => setManual(null)}
|
||||||
@@ -155,6 +183,7 @@ export default function App() {
|
|||||||
openItem(item)
|
openItem(item)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</Suspense>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</SocialProvider>
|
</SocialProvider>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { t } from '../i18n'
|
|||||||
import { Loader2, Plus, Share2 } from 'lucide-react'
|
import { Loader2, Plus, Share2 } from 'lucide-react'
|
||||||
import { useState, type CSSProperties } from 'react'
|
import { useState, type CSSProperties } from 'react'
|
||||||
import { TOP_CATEGORIES } from '../lib/constants'
|
import { TOP_CATEGORIES } from '../lib/constants'
|
||||||
import { renderTopCard, slug } from '../lib/shareCard'
|
|
||||||
import { cx, formatRating } from '../lib/utils'
|
import { cx, formatRating } from '../lib/utils'
|
||||||
import { useMedia } from '../store'
|
import { useMedia } from '../store'
|
||||||
import type { MediaItem, TopCategory } from '../types'
|
import type { MediaItem, TopCategory } from '../types'
|
||||||
@@ -60,8 +59,9 @@ export default function TopFive({ onOpen }: { onOpen: (item: MediaItem) => void
|
|||||||
const share = async () => {
|
const share = async () => {
|
||||||
setSharing(true)
|
setSharing(true)
|
||||||
try {
|
try {
|
||||||
|
const { renderTopCard, slug } = await import('../lib/shareCard')
|
||||||
const blob = await renderTopCard(current.plural, [1, 2, 3, 4, 5].map((r) => byRank.get(r)))
|
const blob = await renderTopCard(current.plural, [1, 2, 3, 4, 5].map((r) => byRank.get(r)))
|
||||||
setPreview({ blob, filename: `kino-top5-${slug(current.plural)}.png`, title: t('top.shareTitle', { category: current.plural }) })
|
setPreview({ blob, filename: `bobinoo-top5-${slug(current.plural)}.png`, title: t('top.shareTitle', { category: current.plural }) })
|
||||||
} finally {
|
} finally {
|
||||||
setSharing(false)
|
setSharing(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
|
import { createContext, lazy, Suspense, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||||
import { getFollowRequests, getMyProfile, unreadNotifications, type Profile, type ProfileCard } from '../../lib/cloud/social'
|
import { getFollowRequests, getMyProfile, unreadNotifications, type Profile, type ProfileCard } from '../../lib/cloud/social'
|
||||||
import NotificationsSheet from './NotificationsSheet'
|
|
||||||
import { useMedia } from '../../store'
|
import { useMedia } from '../../store'
|
||||||
import type { MediaItem } from '../../types'
|
import type { MediaItem } from '../../types'
|
||||||
import EditProfile from './EditProfile'
|
import type { PeekOwner } from './ItemPeek'
|
||||||
import FollowList from './FollowList'
|
|
||||||
import ItemPeek, { type PeekOwner } from './ItemPeek'
|
|
||||||
import PeopleSearch from './PeopleSearch'
|
|
||||||
import ProfileView from './ProfileView'
|
|
||||||
import TitleReviews from './TitleReviews'
|
|
||||||
import { useOnResume } from '../../lib/onResume'
|
import { useOnResume } from '../../lib/onResume'
|
||||||
import WelcomeProfile, { RANDOM_USERNAME } from './WelcomeProfile'
|
import WelcomeProfile, { RANDOM_USERNAME } from './WelcomeProfile'
|
||||||
import { InvitePeople, SharedListSheet } from './SharedLists'
|
import { InvitePeople, SharedListSheet } from './SharedLists'
|
||||||
@@ -44,6 +38,27 @@ interface SocialApi {
|
|||||||
bumpShared: () => void
|
bumpShared: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Écrans sociaux chargés à la demande (préchargés par App au repos via preloadSocial)
|
||||||
|
const socialLoaders = {
|
||||||
|
NotificationsSheet: () => import('./NotificationsSheet'),
|
||||||
|
EditProfile: () => import('./EditProfile'),
|
||||||
|
FollowList: () => import('./FollowList'),
|
||||||
|
PeopleSearch: () => import('./PeopleSearch'),
|
||||||
|
ProfileView: () => import('./ProfileView'),
|
||||||
|
TitleReviews: () => import('./TitleReviews'),
|
||||||
|
ItemPeek: () => import('./ItemPeek'),
|
||||||
|
}
|
||||||
|
const NotificationsSheet = lazy(socialLoaders.NotificationsSheet)
|
||||||
|
const EditProfile = lazy(socialLoaders.EditProfile)
|
||||||
|
const FollowList = lazy(socialLoaders.FollowList)
|
||||||
|
const PeopleSearch = lazy(socialLoaders.PeopleSearch)
|
||||||
|
const ProfileView = lazy(socialLoaders.ProfileView)
|
||||||
|
const TitleReviews = lazy(socialLoaders.TitleReviews)
|
||||||
|
const ItemPeek = lazy(socialLoaders.ItemPeek)
|
||||||
|
export function preloadSocial() {
|
||||||
|
for (const load of Object.values(socialLoaders)) void load().catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
const SocialContext = createContext<SocialApi>({
|
const SocialContext = createContext<SocialApi>({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
me: null,
|
me: null,
|
||||||
@@ -221,8 +236,9 @@ export function SocialProvider({
|
|||||||
<SocialContext.Provider value={api}>
|
<SocialContext.Provider value={api}>
|
||||||
{/* Les écrans sociaux sont placés avant l'app : une fiche ouverte depuis un profil passe au-dessus */}
|
{/* Les écrans sociaux sont placés avant l'app : une fiche ouverte depuis un profil passe au-dessus */}
|
||||||
{enabled &&
|
{enabled &&
|
||||||
stack.map((o) =>
|
stack.map((o) => (
|
||||||
o.kind === 'profile' ? (
|
<Suspense key={o.uid} fallback={null}>
|
||||||
|
{o.kind === 'profile' ? (
|
||||||
<ProfileView key={o.uid} username={o.username} onClose={() => close(o.uid)} />
|
<ProfileView key={o.uid} username={o.username} onClose={() => close(o.uid)} />
|
||||||
) : o.kind === 'search' ? (
|
) : o.kind === 'search' ? (
|
||||||
<PeopleSearch key={o.uid} onClose={() => close(o.uid)} />
|
<PeopleSearch key={o.uid} onClose={() => close(o.uid)} />
|
||||||
@@ -238,11 +254,16 @@ export function SocialProvider({
|
|||||||
<NotificationsSheet key={o.uid} onClose={() => close(o.uid)} onSeen={() => setUnread(0)} />
|
<NotificationsSheet key={o.uid} onClose={() => close(o.uid)} onSeen={() => setUnread(0)} />
|
||||||
) : (
|
) : (
|
||||||
<InvitePeople key={o.uid} listId={o.listId} listName={o.listName} onClose={() => close(o.uid)} />
|
<InvitePeople key={o.uid} listId={o.listId} listName={o.listName} onClose={() => close(o.uid)} />
|
||||||
),
|
)}
|
||||||
)}
|
</Suspense>
|
||||||
|
))}
|
||||||
{children}
|
{children}
|
||||||
{enabled && me && RANDOM_USERNAME.test(me.username) && !welcomeLater && <WelcomeProfile onLater={later} />}
|
{enabled && me && RANDOM_USERNAME.test(me.username) && !welcomeLater && <WelcomeProfile onLater={later} />}
|
||||||
{enabled && peeked && <ItemPeek item={peeked.item} owner={peeked.owner} onClose={() => setPeeked(undefined)} />}
|
{enabled && peeked && (
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<ItemPeek item={peeked.item} owner={peeked.owner} onClose={() => setPeeked(undefined)} />
|
||||||
|
</Suspense>
|
||||||
|
)}
|
||||||
</SocialContext.Provider>
|
</SocialContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,6 @@ import { episodeCap, seasonPosition } from '../../lib/franchise'
|
|||||||
import { episodesPatch } from '../../lib/progress'
|
import { episodesPatch } from '../../lib/progress'
|
||||||
import { useScrollLock } from '../../lib/scrollLock'
|
import { useScrollLock } from '../../lib/scrollLock'
|
||||||
import { backdropSrcSet, tmdbSized } from '../../lib/tmdbImage'
|
import { backdropSrcSet, tmdbSized } from '../../lib/tmdbImage'
|
||||||
import { renderItemCard, slug } from '../../lib/shareCard'
|
|
||||||
import { cx, formatDate, formatDuration, formatRating, todayISO } from '../../lib/utils'
|
import { cx, formatDate, formatDuration, formatRating, todayISO } from '../../lib/utils'
|
||||||
import { GuestError, useMedia } from '../../store'
|
import { GuestError, useMedia } from '../../store'
|
||||||
import { allTags, cleanTag } from '../../lib/bulk'
|
import { allTags, cleanTag } from '../../lib/bulk'
|
||||||
@@ -295,8 +294,10 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
|
|||||||
if (settings.tmdbKey && item.externalId?.startsWith('tmdb:') && navigator.onLine) {
|
if (settings.tmdbKey && item.externalId?.startsWith('tmdb:') && navigator.onLine) {
|
||||||
credits = await getTmdbCredits(item.externalId, settings.tmdbKey).catch(() => undefined)
|
credits = await getTmdbCredits(item.externalId, settings.tmdbKey).catch(() => undefined)
|
||||||
}
|
}
|
||||||
|
// Carte de partage : module chargé seulement quand on partage
|
||||||
|
const { renderItemCard, slug } = await import('../../lib/shareCard')
|
||||||
const blob = await renderItemCard(item, credits)
|
const blob = await renderItemCard(item, credits)
|
||||||
setPreview({ blob, filename: `kino-${slug(item.title)}.png` })
|
setPreview({ blob, filename: `bobinoo-${slug(item.title)}.png` })
|
||||||
} catch {
|
} catch {
|
||||||
setToast(t('share.err.create'))
|
setToast(t('share.err.create'))
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
+1
-1
@@ -185,7 +185,7 @@ export function buildBackup(items: MediaItem[], settings: Settings, lists: Custo
|
|||||||
*/
|
*/
|
||||||
export async function exportBackup(items: MediaItem[], settings: Settings, lists: CustomList[] = []): Promise<'shared' | 'downloaded'> {
|
export async function exportBackup(items: MediaItem[], settings: Settings, lists: CustomList[] = []): Promise<'shared' | 'downloaded'> {
|
||||||
const json = JSON.stringify(buildBackup(items, settings, lists), null, 2)
|
const json = JSON.stringify(buildBackup(items, settings, lists), null, 2)
|
||||||
const filename = `kino-sauvegarde-${todayISO()}.json`
|
const filename = `bobinoo-sauvegarde-${todayISO()}.json`
|
||||||
const file = new File([json], filename, { type: 'application/json' })
|
const file = new File([json], filename, { type: 'application/json' })
|
||||||
|
|
||||||
const isTouch = window.matchMedia?.('(pointer: coarse)').matches
|
const isTouch = window.matchMedia?.('(pointer: coarse)').matches
|
||||||
|
|||||||
@@ -453,4 +453,4 @@ export const slug = (s: string) =>
|
|||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/[^a-z0-9]+/g, '-')
|
.replace(/[^a-z0-9]+/g, '-')
|
||||||
.replace(/^-|-$/g, '')
|
.replace(/^-|-$/g, '')
|
||||||
.slice(0, 40) || 'kino'
|
.slice(0, 40) || 'bobinoo'
|
||||||
Reference in new issue
Block a user