From 7851c24f7cbf9bf934730db96b8a3b5e58a01530 Mon Sep 17 00:00:00 2001 From: pablonification <19623037@std.stei.itb.ac.id> Date: Sun, 10 May 2026 00:57:46 +0800 Subject: [PATCH 1/8] fix: stabilize loading states --- src/App.tsx | 9 ++- src/components/ui/AppButton.tsx | 5 +- src/lib/asyncTimeout.ts | 21 ++++++ src/navigation/AppRouter.tsx | 20 ++++-- src/pages/AiHelperPage.css | 123 ++++++++++++++++++++++---------- src/pages/AiHelperPage.tsx | 60 ++++++++++++---- src/pages/ArchiveReviewPage.tsx | 5 +- src/pages/AuthPage.css | 5 ++ src/pages/AuthPage.tsx | 16 ++--- src/pages/ElderStudioTab.tsx | 9 +-- src/pages/HomePage.tsx | 2 +- src/pages/ResetPasswordPage.tsx | 7 +- src/pages/SoundArchiveTab.tsx | 14 ++-- src/pages/TranslatePage.css | 2 +- 14 files changed, 213 insertions(+), 85 deletions(-) create mode 100644 src/lib/asyncTimeout.ts diff --git a/src/App.tsx b/src/App.tsx index 2712454..26dab91 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,7 @@ import { BrowserRouter } from 'react-router-dom'; import { useEffect } from 'react'; import { AppRouter } from './navigation/AppRouter'; +import { withTimeout } from './lib/asyncTimeout'; import { supabase } from './lib/supabase'; import { removeKey, STORAGE_KEYS } from './lib/storage'; import { useAuthStore } from './stores/authStore'; @@ -18,7 +19,11 @@ export default function App() { const { data: { session: nextSession }, error, - } = await supabase.auth.getSession(); + } = await withTimeout( + supabase.auth.getSession(), + 8000, + 'Timed out while initialising session.', + ); if (error) { throw error; @@ -55,7 +60,7 @@ export default function App() { return ( - + diff --git a/src/components/ui/AppButton.tsx b/src/components/ui/AppButton.tsx index c624074..4b37eaf 100644 --- a/src/components/ui/AppButton.tsx +++ b/src/components/ui/AppButton.tsx @@ -1,5 +1,6 @@ -import { IonButton, IonSpinner } from '@ionic/react'; +import { IonButton } from '@ionic/react'; import type { ComponentProps } from 'react'; +import { AppSkeleton } from './AppSkeleton'; type IonButtonProps = ComponentProps; @@ -10,7 +11,7 @@ type AppButtonProps = IonButtonProps & { export function AppButton({ loading = false, disabled, children, ...props }: AppButtonProps) { return ( - {loading ? : children} + {loading ? : children} ); } diff --git a/src/lib/asyncTimeout.ts b/src/lib/asyncTimeout.ts new file mode 100644 index 0000000..86aa333 --- /dev/null +++ b/src/lib/asyncTimeout.ts @@ -0,0 +1,21 @@ +export const withTimeout = async ( + promise: PromiseLike, + timeoutMs: number, + message: string, +): Promise => { + let timeoutId: ReturnType | undefined; + + const timeout = new Promise((_, reject) => { + timeoutId = setTimeout(() => { + reject(new Error(message)); + }, timeoutMs); + }); + + try { + return await Promise.race([promise, timeout]); + } finally { + if (timeoutId) { + clearTimeout(timeoutId); + } + } +}; diff --git a/src/navigation/AppRouter.tsx b/src/navigation/AppRouter.tsx index 0e0744b..6879d10 100644 --- a/src/navigation/AppRouter.tsx +++ b/src/navigation/AppRouter.tsx @@ -5,6 +5,7 @@ import { Capacitor } from '@capacitor/core'; import { SplashScreen } from '@capacitor/splash-screen'; import { AppSplashScreen } from '../components/ui'; +import { withTimeout } from '../lib/asyncTimeout'; import { fetchOnboardingStatus } from '../lib/profile'; import { useAuthStore } from '../stores/authStore'; import { AuthPage } from '../pages/AuthPage'; @@ -112,13 +113,18 @@ export function AppRouter() { completed: current.completed, })); - void fetchOnboardingStatus({ - userId: session.user.id, - fallbackRole: - session.user.user_metadata?.role === 'elder' || session.user.user_metadata?.role === 'admin' - ? session.user.user_metadata.role - : 'learner', - }) + void withTimeout( + fetchOnboardingStatus({ + userId: session.user.id, + fallbackRole: + session.user.user_metadata?.role === 'elder' || + session.user.user_metadata?.role === 'admin' + ? session.user.user_metadata.role + : 'learner', + }), + 8000, + 'Timed out while resolving onboarding status.', + ) .then((status) => { if (!cancelled) { setOnboardingState({ isLoading: false, completed: status.completed }); diff --git a/src/pages/AiHelperPage.css b/src/pages/AiHelperPage.css index 8aa53b7..d3c7bf9 100644 --- a/src/pages/AiHelperPage.css +++ b/src/pages/AiHelperPage.css @@ -286,6 +286,7 @@ } .tavi-thread-drawer-backdrop { + animation: tavi-backdrop-in 180ms cubic-bezier(0.22, 1, 0.36, 1) both; background: rgba(26, 26, 26, 0.22); border: 0; cursor: pointer; @@ -295,6 +296,7 @@ } .tavi-thread-panel { + animation: tavi-drawer-in 220ms cubic-bezier(0.22, 1, 0.36, 1) both; background: #fff9e9; border-left: 1px solid rgba(203, 64, 60, 0.16); bottom: 0; @@ -309,6 +311,28 @@ width: 100%; } +@keyframes tavi-backdrop-in { + from { + opacity: 0; + } + + to { + opacity: 1; + } +} + +@keyframes tavi-drawer-in { + from { + opacity: 0.86; + transform: translateX(18px); + } + + to { + opacity: 1; + transform: translateX(0); + } +} + .tavi-thread-panel-header { align-items: flex-start; display: flex; @@ -398,6 +422,10 @@ padding: 10px; } +.tavi-thread-item--skeleton { + pointer-events: none; +} + .tavi-thread-item.is-active { background: rgba(203, 64, 60, 0.1); border-color: rgba(203, 64, 60, 0.36); @@ -451,10 +479,38 @@ } .tavi-chat-history-loading { - align-items: center; + display: grid; + gap: 12px; + padding: 24px 0 8px; +} + +.tavi-chat-skeleton-row { + align-items: flex-end; display: flex; - justify-content: center; - min-height: 180px; + gap: 8px; +} + +.tavi-chat-skeleton-row--user { + justify-content: flex-end; +} + +.tavi-chat-skeleton-bubble { + display: grid; + gap: 8px; + max-width: 72%; + padding: 14px; +} + +.tavi-chat-skeleton-bubble--tavi { + background: #f5c0be; + border-radius: 18px 18px 18px 4px; + width: min(250px, 72%); +} + +.tavi-chat-skeleton-bubble--user { + background: #cb403c; + border-radius: 18px 18px 4px; + width: min(190px, 62%); } .tavi-chat-greeting-title { @@ -490,11 +546,24 @@ } .tavi-bubble-row { + animation: tavi-message-enter 170ms cubic-bezier(0.22, 1, 0.36, 1) both; display: flex; gap: 8px; margin-bottom: 12px; } +@keyframes tavi-message-enter { + from { + opacity: 0; + transform: translateY(5px) scale(0.99); + } + + to { + opacity: 1; + transform: translateY(0) scale(1); + } +} + .tavi-bubble-row--user { flex-direction: row-reverse; } @@ -754,40 +823,10 @@ } .tavi-bubble-loading { - align-items: center; - display: flex; - gap: 5px; - height: 20px; - padding: 2px 4px; -} - -.tavi-bubble-loading span { - animation: tavi-dot-bounce 1.2s ease-in-out infinite; - background: #b0a99f; - border-radius: 50%; - display: block; - height: 7px; - width: 7px; -} - -.tavi-bubble-loading span:nth-child(2) { - animation-delay: 0.18s; -} -.tavi-bubble-loading span:nth-child(3) { - animation-delay: 0.36s; -} - -@keyframes tavi-dot-bounce { - 0%, - 80%, - 100% { - transform: translateY(0); - opacity: 0.4; - } - 40% { - transform: translateY(-6px); - opacity: 1; - } + display: grid; + gap: 8px; + min-width: 172px; + padding: 3px 0; } .tavi-chat-inputbar { @@ -1028,3 +1067,13 @@ .tavi-chat-inputbar-send:not(:disabled):active { transform: scale(0.9); } + +@media (prefers-reduced-motion: reduce) { + .tavi-intro-mascot, + .tavi-intro-aura, + .tavi-thread-drawer-backdrop, + .tavi-thread-panel, + .tavi-bubble-row { + animation: none; + } +} diff --git a/src/pages/AiHelperPage.tsx b/src/pages/AiHelperPage.tsx index 42d7037..1139f74 100644 --- a/src/pages/AiHelperPage.tsx +++ b/src/pages/AiHelperPage.tsx @@ -1,4 +1,4 @@ -import { IonAlert, IonSpinner, IonToast } from '@ionic/react'; +import { IonAlert, IonToast } from '@ionic/react'; import type { CSSProperties, ReactNode } from 'react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; @@ -31,6 +31,7 @@ import { } from '../lib/taviThreads'; import { useEdgeSwipeBack } from '../lib/useEdgeSwipeBack'; import { useAuthStore } from '../stores/authStore'; +import { AppSkeleton } from '../components/ui'; import './AiHelperPage.css'; @@ -333,10 +334,9 @@ function ChatBubble({
{message.loading ? ( -
- - - +
+ +
) : (
@@ -437,7 +437,7 @@ function ThreadDrawer({

History

@@ -446,7 +446,18 @@ function ThreadDrawer({
- {isLoading ?

Loading chats...

: null} + {isLoading + ? Array.from({ length: 4 }).map((_, index) => ( +
+ + +
+ + +
+
+ )) + : null} {!isLoading && threads.length === 0 ? (

No saved chats yet.

) : null} @@ -479,6 +490,33 @@ function ThreadDrawer({ ); } +function TaviChatSkeleton() { + return ( +
+
+ +
+ + +
+
+
+
+ +
+
+
+ +
+ + + +
+
+
+ ); +} + export function AiHelperPage() { const navigate = useNavigate(); const [searchParams, setSearchParams] = useSearchParams(); @@ -1289,11 +1327,7 @@ export function AiHelperPage() { onDidDismiss={() => setThreadPendingRename(null)} /> - {isThreadLoading && messages.length === 0 ? ( -
- -
- ) : null} + {isThreadLoading && messages.length === 0 ? : null} {!isThreadLoading && messages.length === 0 ? (
@@ -1406,7 +1440,7 @@ export function AiHelperPage() { aria-label="Send message" > {isSending ? ( - + ) : ( { + const { findSemaiDictionaryHints } = await import('../lib/semaiDictionary'); const nextHints = await Promise.all( reviewPagination.items.map(async (recording) => { const transcript = @@ -966,7 +967,7 @@ export function ArchiveReviewPage() { } > {loadingPlaybackRecordingId === recording.id ? ( - 'Loading...' + ) : ( <> - {loading - ? isSignUp - ? 'Creating account...' - : 'Logging in...' - : isSignUp - ? 'Get Started' - : 'Log In'} + {loading ? ( + + ) : isSignUp ? ( + 'Get Started' + ) : ( + 'Log In' + )} diff --git a/src/pages/ElderStudioTab.tsx b/src/pages/ElderStudioTab.tsx index 8c99091..d85c8fc 100644 --- a/src/pages/ElderStudioTab.tsx +++ b/src/pages/ElderStudioTab.tsx @@ -1,4 +1,4 @@ -import { IonIcon, IonSpinner, IonToast } from '@ionic/react'; +import { IonIcon, IonToast } from '@ionic/react'; import { addOutline, arrowBackOutline, @@ -26,6 +26,7 @@ import { } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; +import { AppSkeleton } from '../components/ui'; import { countPendingStudioReview, doesStudioRecordingNeedReview, @@ -1004,7 +1005,7 @@ export function ElderStudioTab() {

Studio

{isSyncing ? ( - + ) : ( )} @@ -1364,8 +1365,8 @@ export function ElderStudioTab() { > {isSaving ? ( <> - - Saving... + + ) : ( 'Save to Archive' diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index d876314..7425c37 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -375,6 +375,7 @@ function isLearnerOnlyRoute(pathname: string): boolean { function resolveLearnerTab(pathname: string): LearnerTab | null { if (pathname.startsWith('/home/landing')) return 'home'; if (pathname.startsWith('/home/garden')) return 'garden'; + if (pathname.startsWith('/home/translation')) return null; if (pathname.startsWith('/home/stories')) return 'story'; if (pathname.startsWith('/home/archive')) return null; if (pathname.startsWith('/home/ai')) return 'ai'; @@ -435,7 +436,6 @@ export function HomePage() { new URLSearchParams(location.search).get('chat') === '1'; const shouldShowTabMenu = - !isTranslateRoute && !location.pathname.startsWith('/home/profile/') && !isQuizRoute && !isStoryDetailRoute && diff --git a/src/pages/ResetPasswordPage.tsx b/src/pages/ResetPasswordPage.tsx index e2c7bf3..c105671 100644 --- a/src/pages/ResetPasswordPage.tsx +++ b/src/pages/ResetPasswordPage.tsx @@ -10,6 +10,7 @@ import { supabase } from '../lib/supabase'; import { useAuthStore } from '../stores/authStore'; import { toAuthErrorMessage } from '../utils/authErrors'; import { validatePassword } from '../utils/authValidation'; +import { AppSkeleton } from '../components/ui'; import './AuthPage.css'; @@ -164,7 +165,11 @@ export function ResetPasswordPage() {
diff --git a/src/pages/SoundArchiveTab.tsx b/src/pages/SoundArchiveTab.tsx index 07b4c60..eab029e 100644 --- a/src/pages/SoundArchiveTab.tsx +++ b/src/pages/SoundArchiveTab.tsx @@ -1,4 +1,4 @@ -import { IonIcon, IonSpinner, IonToast } from '@ionic/react'; +import { IonIcon, IonToast } from '@ionic/react'; import { arrowBackOutline, cloudDoneOutline, @@ -500,7 +500,7 @@ export function SoundArchiveTab() {

Sound Archive

{isSyncing ? ( - + ) : ( )} @@ -623,7 +623,7 @@ export function SoundArchiveTab() { disabled={Boolean(loadingPlaybackRecordingId)} > {loadingPlaybackRecordingId === recording.id ? ( - 'Loading...' + ) : ( <> {isGeneratingCover || isGeneratingBg ? ( <> - - Generating… + + ) : !generatedCoverUrl ? ( 'Generate Cover' @@ -783,8 +783,8 @@ export function SoundArchiveTab() { > {isPublishing ? ( <> - - Publishing… + + ) : ( 'Publish Story' diff --git a/src/pages/TranslatePage.css b/src/pages/TranslatePage.css index 8560aa4..ff7c227 100644 --- a/src/pages/TranslatePage.css +++ b/src/pages/TranslatePage.css @@ -71,7 +71,7 @@ .translate-panel { margin: 24px auto 0; max-width: 354px; - padding: 0 7px calc(var(--safe-area-bottom) + 28px); + padding: 0 7px calc(var(--safe-area-bottom) + 128px); } .translate-card { From 5ba5fceea8aaa6261488586102bef4a2fe3371e0 Mon Sep 17 00:00:00 2001 From: pablonification <19623037@std.stei.itb.ac.id> Date: Sun, 10 May 2026 00:58:24 +0800 Subject: [PATCH 2/8] feat: track story reading progress --- src/lib/storage.ts | 1 + src/lib/storyProgress.test.ts | 108 ++++++++++++++++++++++++++++++++++ src/lib/storyProgress.ts | 84 ++++++++++++++++++++++++++ src/pages/LandingPage.tsx | 95 ++++++++++++++++++------------ src/pages/StoryDetailPage.css | 19 ++++++ src/pages/StoryDetailPage.tsx | 85 +++++++++++++++++++++++--- src/pages/StoryPage.tsx | 12 +++- src/pages/StoryReadPage.css | 12 ++++ src/pages/StoryReadPage.tsx | 61 ++++++++++++++++--- 9 files changed, 421 insertions(+), 56 deletions(-) create mode 100644 src/lib/storyProgress.test.ts create mode 100644 src/lib/storyProgress.ts diff --git a/src/lib/storage.ts b/src/lib/storage.ts index f7395d9..5e28452 100644 --- a/src/lib/storage.ts +++ b/src/lib/storage.ts @@ -9,6 +9,7 @@ export const STORAGE_KEYS = { PENDING_SYNC: 'pending-sync', SETTINGS: 'settings', STREAK: 'streak', + STORY_PROGRESS: 'story-progress', AUTH_TRANSIENT_SESSION: 'auth-transient-session', } as const; diff --git a/src/lib/storyProgress.test.ts b/src/lib/storyProgress.test.ts new file mode 100644 index 0000000..0089a1b --- /dev/null +++ b/src/lib/storyProgress.test.ts @@ -0,0 +1,108 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import type { Story } from './storyData'; +import { + applyStoryProgress, + getLastReadStory, + saveStoryProgress, + type StoryProgressEntry, +} from './storyProgress'; + +vi.mock('@capacitor/preferences', () => { + const store = new Map(); + return { + Preferences: { + get: vi.fn(async ({ key }: { key: string }) => ({ value: store.get(key) ?? null })), + set: vi.fn(async ({ key, value }: { key: string; value: string }) => { + store.set(key, value); + }), + remove: vi.fn(async ({ key }: { key: string }) => { + store.delete(key); + }), + __store: store, + }, + }; +}); + +const story: Story = { + id: 'kancil', + title: 'Kancil & Buaya', + author: 'Cerite Rakyat', + cover: '/cover.png', + bg: '/bg.png', + duration: '15 min', + pages: 8, + genre: 'Fable', + synopsis: 'A story', + lastChapter: 'Satu Cerite', + lastPage: 0, + totalPages: 8, + progress: 0, + scenes: Array.from({ length: 8 }, (_, index) => ({ + image: `/scene-${index}.png`, + text: `Scene ${index + 1}`, + })), +}; + +describe('storyProgress', () => { + beforeEach(async () => { + const { Preferences } = await import('@capacitor/preferences'); + (Preferences as unknown as { __store: Map }).__store.clear(); + }); + + it('saves scene position as percentage progress', async () => { + const progress = await saveStoryProgress(story, 3); + + expect(progress).toMatchObject({ + storyId: 'kancil', + currentScene: 3, + lastPage: 4, + totalPages: 8, + progress: 50, + }); + }); + + it('applies stored progress without using catalog placeholder values', () => { + const progress: StoryProgressEntry = { + storyId: 'kancil', + currentScene: 4, + totalScenes: 8, + lastPage: 5, + totalPages: 8, + progress: 63, + lastChapter: 'Satu Cerite', + updatedAt: '2026-05-10T01:00:00.000Z', + }; + + expect(applyStoryProgress({ ...story, progress: 99 }, progress)).toMatchObject({ + progress: 63, + lastPage: 5, + totalPages: 8, + }); + }); + + it('selects the most recently updated story as last read', () => { + const older = { + storyId: 'kancil', + currentScene: 0, + totalScenes: 8, + lastPage: 1, + totalPages: 8, + progress: 13, + lastChapter: 'Satu Cerite', + updatedAt: '2026-05-10T01:00:00.000Z', + }; + const newer = { + ...older, + storyId: 'sunbe', + updatedAt: '2026-05-10T02:00:00.000Z', + }; + + expect( + getLastReadStory([{ ...story, id: 'sunbe', title: 'Sunbe & Fenyi' }, story], { + kancil: older, + sunbe: newer, + })?.id, + ).toBe('sunbe'); + }); +}); diff --git a/src/lib/storyProgress.ts b/src/lib/storyProgress.ts new file mode 100644 index 0000000..0d6d629 --- /dev/null +++ b/src/lib/storyProgress.ts @@ -0,0 +1,84 @@ +import { getJSON, setJSON, STORAGE_KEYS } from './storage'; +import type { Story } from './storyData'; + +export interface StoryProgressEntry { + storyId: string; + currentScene: number; + totalScenes: number; + progress: number; + lastPage: number; + totalPages: number; + lastChapter: string; + updatedAt: string; +} + +type StoryProgressMap = Record; + +const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value)); + +const getTotalScenes = (story: Story) => Math.max(1, story.scenes?.length ?? story.totalPages); + +export const getStoryProgress = async (): Promise => + getJSON(STORAGE_KEYS.STORY_PROGRESS, {}); + +export const getStoryProgressEntry = async ( + storyId: string, +): Promise => { + const progress = await getStoryProgress(); + return progress[storyId] ?? null; +}; + +export const saveStoryProgress = async ( + story: Story, + currentScene: number, +): Promise => { + const totalScenes = getTotalScenes(story); + const sceneIndex = clamp(currentScene, 0, totalScenes - 1); + const lastPage = sceneIndex + 1; + const entry: StoryProgressEntry = { + storyId: story.id, + currentScene: sceneIndex, + totalScenes, + progress: Math.round((lastPage / totalScenes) * 100), + lastPage, + totalPages: totalScenes, + lastChapter: story.lastChapter || 'Scene 1', + updatedAt: new Date().toISOString(), + }; + const progress = await getStoryProgress(); + await setJSON(STORAGE_KEYS.STORY_PROGRESS, { ...progress, [story.id]: entry }); + return entry; +}; + +export const applyStoryProgress = ( + story: Story, + progressEntry: StoryProgressEntry | null | undefined, +): Story => { + if (!progressEntry || progressEntry.storyId !== story.id) { + return { ...story, progress: 0, lastPage: 0 }; + } + + const totalPages = getTotalScenes(story); + const lastPage = clamp(progressEntry.lastPage, 1, totalPages); + return { + ...story, + lastChapter: progressEntry.lastChapter, + lastPage, + totalPages, + progress: clamp(progressEntry.progress, 0, 100), + }; +}; + +export const getLastReadStory = (stories: Story[], progress: StoryProgressMap): Story | null => { + const storyById = new Map(stories.map((story) => [story.id, story])); + const latest = Object.values(progress) + .filter((entry) => storyById.has(entry.storyId)) + .sort((first, second) => second.updatedAt.localeCompare(first.updatedAt))[0]; + + if (!latest) { + return null; + } + + const story = storyById.get(latest.storyId); + return story ? applyStoryProgress(story, latest) : null; +}; diff --git a/src/pages/LandingPage.tsx b/src/pages/LandingPage.tsx index edddb22..742bddf 100644 --- a/src/pages/LandingPage.tsx +++ b/src/pages/LandingPage.tsx @@ -3,11 +3,13 @@ import { useNavigate } from 'react-router-dom'; import { AppSkeleton } from '../components/ui'; import { LearningLanguageBadge } from '../components/LearningLanguageBadge'; +import { withTimeout } from '../lib/asyncTimeout'; import { triggerHapticFeedback } from '../lib/feedback'; import { DEFAULT_LEARNING_LANGUAGE, resolveLearningLanguage } from '../lib/learningLanguages'; import { addExploreEntry } from '../lib/navigationEntry'; import { fetchProfileDashboard } from '../lib/profile'; -import { STORIES } from '../lib/storyData'; +import { STORIES, type Story } from '../lib/storyData'; +import { getLastReadStory, getStoryProgress, type StoryProgressEntry } from '../lib/storyProgress'; import { useAuthStore } from '../stores/authStore'; import aiTaviCardImg from '../../assets/home-revised/ai-tavi.png'; @@ -76,9 +78,6 @@ const BOOKS = STORIES.slice(0, 4).map((story) => ({ img: story.cover, })); -const FEATURED_STORY = - [...STORIES].sort((first, second) => second.progress - first.progress)[0] ?? STORIES[0]; - function LandingPageSkeleton({ isElder }: { isElder: boolean }) { return (
@@ -266,6 +265,7 @@ function LearnerLanding({ leaderName, leaderAvatarSrc, leaderHasCustomPhoto, + lastReadStory, }: { firstName: string; onNavigate: (h: string) => void; @@ -273,6 +273,7 @@ function LearnerLanding({ leaderName: string; leaderAvatarSrc: string; leaderHasCustomPhoto: boolean; + lastReadStory: Story | null; }) { return (
@@ -295,43 +296,41 @@ function LearnerLanding({
-
-

Last Read

-
- -
+
+ {lastReadStory.title} + by {lastReadStory.author} + + +
+ ) : null} >({}); const meta = user?.user_metadata as Record | undefined; const fullName = meta?.full_name as string | undefined; @@ -454,10 +454,14 @@ export function LandingPage() { setIsProfileLoading(true); - void fetchProfileDashboard({ - userId: user.id, - fallbackRole: isElder ? 'elder' : 'learner', - }) + void withTimeout( + fetchProfileDashboard({ + userId: user.id, + fallbackRole: isElder ? 'elder' : 'learner', + }), + 8000, + 'Timed out while loading the landing profile.', + ) .then((dashboard) => { if (cancelled) return; @@ -484,6 +488,20 @@ export function LandingPage() { }; }, [firstName, isElder, meta?.avatar_url, meta?.full_name, user?.id]); + useEffect(() => { + let cancelled = false; + + void getStoryProgress().then((progress) => { + if (!cancelled) { + setStoryProgress(progress); + } + }); + + return () => { + cancelled = true; + }; + }, []); + const onNavigate = (href: string) => { triggerHapticFeedback('light'); navigate(href); @@ -493,6 +511,8 @@ export function LandingPage() { return ; } + const lastReadStory = getLastReadStory(STORIES, storyProgress); + return isElder ? ( ) : ( @@ -503,6 +523,7 @@ export function LandingPage() { leaderName={leaderName} leaderAvatarSrc={leaderAvatarSrc} leaderHasCustomPhoto={leaderHasCustomPhoto} + lastReadStory={lastReadStory} /> ); } diff --git a/src/pages/StoryDetailPage.css b/src/pages/StoryDetailPage.css index 6e1ccc6..4acad15 100644 --- a/src/pages/StoryDetailPage.css +++ b/src/pages/StoryDetailPage.css @@ -31,6 +31,11 @@ display: block; } +.story-detail-hero-blur--skeleton { + background: #e0d4c4; + filter: blur(5px); +} + /* Gradient fade from hero into cream background */ .story-detail-hero-fade { position: absolute; @@ -113,6 +118,10 @@ display: block; } +.story-detail-cover--skeleton { + background: var(--app-skeleton-base); +} + .story-detail-cover-meta { position: relative; z-index: 1; @@ -204,6 +213,16 @@ box-shadow: 0 4px 4px rgba(0, 0, 0, 0.1); } +.story-detail-skeleton-centered { + margin: 0 auto 10px; +} + +.story-detail-skeleton-copy { + display: grid; + gap: 9px; + padding-top: 14px; +} + .story-detail-progress-chapter { display: block; font-family: 'Satoshi', sans-serif; diff --git a/src/pages/StoryDetailPage.tsx b/src/pages/StoryDetailPage.tsx index f1718e8..2ac4410 100644 --- a/src/pages/StoryDetailPage.tsx +++ b/src/pages/StoryDetailPage.tsx @@ -1,5 +1,6 @@ import { useEffect, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; +import { AppSkeleton } from '../components/ui'; import { triggerHapticFeedback } from '../lib/feedback'; import { PUBLISHED_STORY_SELECT, @@ -8,6 +9,7 @@ import { } from '../lib/publishedStory'; import { supabase } from '../lib/supabase'; import { STORIES, type Story } from '../lib/storyData'; +import { applyStoryProgress, getStoryProgressEntry } from '../lib/storyProgress'; import './StoryDetailPage.css'; @@ -68,6 +70,60 @@ function GenreIcon() { // ── Page ───────────────────────────────────────────────────────────────────── +function StoryDetailSkeleton({ onBack }: { onBack: () => void }) { + return ( +
+