Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ code, pre, .font-mono {
}
}

/* Reading Mode page-flip transitions */
@keyframes flip-in-left {
from { opacity: 0; transform: translateX(40px); }
to { opacity: 1; transform: translateX(0); }
}
@keyframes flip-in-right {
from { opacity: 0; transform: translateX(-40px); }
to { opacity: 1; transform: translateX(0); }
}
.page-flip-left {
animation: flip-in-left 0.25s ease-out;
}
.page-flip-right {
animation: flip-in-right 0.25s ease-out;
}

/* Custom select dropdown styling */
select {
appearance: none;
Expand Down
37 changes: 22 additions & 15 deletions src/components/ReadingMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}

export function ReadingMode({
storylineId,

Check warning on line 22 in src/components/ReadingMode.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'storylineId' is defined but never used
storylineTitle,
chapters,
initialChapterIndex,
Expand All @@ -27,6 +27,7 @@
}: ReadingModeProps) {
const [currentIdx, setCurrentIdx] = useState(initialChapterIndex);
const [showToc, setShowToc] = useState(false);
const [flipDir, setFlipDir] = useState<"left" | "right" | null>(null);
const contentRef = useRef<HTMLDivElement>(null);
const { isMiniApp } = usePlatformDetection();

Expand All @@ -38,25 +39,29 @@
contentRef.current?.scrollTo(0, 0);
}, []);

const goPrev = useCallback(() => {
if (hasPrev) {
setCurrentIdx((i) => i - 1);
const navigate = useCallback((idx: number, dir: "left" | "right" | null) => {
setFlipDir(dir);
// Brief delay to trigger the CSS animation before content swap
requestAnimationFrame(() => {
setCurrentIdx(idx);
scrollToTop();
}
}, [hasPrev, scrollToTop]);
// Clear the animation class after transition completes
setTimeout(() => setFlipDir(null), 250);
});
}, [scrollToTop]);

const goPrev = useCallback(() => {
if (hasPrev) navigate(currentIdx - 1, "right");
}, [hasPrev, currentIdx, navigate]);

const goNext = useCallback(() => {
if (hasNext) {
setCurrentIdx((i) => i + 1);
scrollToTop();
}
}, [hasNext, scrollToTop]);
if (hasNext) navigate(currentIdx + 1, "left");
}, [hasNext, currentIdx, navigate]);

const goToChapter = useCallback((idx: number) => {
setCurrentIdx(idx);
setShowToc(false);
scrollToTop();
}, [scrollToTop]);
navigate(idx, idx > currentIdx ? "left" : "right");
}, [currentIdx, navigate]);

// Esc to close, arrow keys for navigation
useEffect(() => {
Expand Down Expand Up @@ -105,8 +110,10 @@
</div>

{/* Content area */}
<div ref={contentRef} className="flex-1 overflow-y-auto">
<div className="mx-auto max-w-[720px] px-6 py-8 sm:px-8 sm:py-12">
<div ref={contentRef} className="flex-1 overflow-y-auto overflow-x-hidden">
<div className={`mx-auto max-w-[720px] px-6 py-8 sm:px-8 sm:py-12 ${
flipDir === "left" ? "page-flip-left" : flipDir === "right" ? "page-flip-right" : ""
}`}>
{chapter?.content ? (
<StoryContent content={chapter.content} />
) : (
Expand Down
Loading