Skip to content

Commit 18830c8

Browse files
committed
improve loader and loading
1 parent 6962019 commit 18830c8

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed

src/app/books/[id]/page.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,7 @@ export default function BookDetailPage() {
373373

374374
if (!_hasHydrated || !book) {
375375
return (
376-
<div
377-
className="min-h-screen flex items-center justify-center"
378-
style={{ backgroundColor: 'var(--background)' }}
379-
>
380-
<Loader size="lg" />
381-
</div>
376+
<Loader size="lg" fullScreen/>
382377
);
383378
}
384379

src/app/layout.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ export default function RootLayout({
1515
}) {
1616
return (
1717
<html lang="en">
18+
<head>
19+
{/* Theme initialization script - runs before React hydrates */}
20+
<script
21+
dangerouslySetInnerHTML={{
22+
__html: `
23+
(function() {
24+
try {
25+
const theme = localStorage.getItem('app-theme') || 'default';
26+
if (['default', 'dark', 'reading'].includes(theme)) {
27+
document.documentElement.setAttribute('data-theme', theme);
28+
}
29+
} catch (e) {}
30+
})();
31+
`,
32+
}}
33+
/>
34+
</head>
1835
<body className="flex flex-col min-h-screen">
1936
{/* SVG Filter for hand-drawn/pencil effect */}
2037
<svg style={{ position: 'absolute', width: 0, height: 0 }} aria-hidden="true">

src/app/loading.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import { Loader } from '@/components/ui/loader';
22

33
export default function Loading() {
4-
return (
5-
<div
6-
className="min-h-screen flex items-center justify-center"
7-
style={{ backgroundColor: 'var(--background)' }}
8-
>
9-
<Loader size="lg" />
10-
</div>
11-
);
4+
return <Loader size="lg" fullScreen />;
125
}

src/components/ui/loader.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface LoaderProps {
99
size?: LoaderSize;
1010
text?: string;
1111
className?: string;
12+
fullScreen?: boolean;
1213
}
1314

1415
const sizeMap: Record<LoaderSize, number> = {
@@ -17,32 +18,55 @@ const sizeMap: Record<LoaderSize, number> = {
1718
lg: 72,
1819
};
1920

20-
export function Loader({ size = 'md', text = 'Loading...', className }: LoaderProps) {
21+
export function Loader({
22+
size = 'md',
23+
text = 'Loading...',
24+
className,
25+
fullScreen = false
26+
}: LoaderProps) {
2127
const iconSize = sizeMap[size];
2228

23-
return (
29+
const content = (
2430
<div className={cn('flex flex-col items-center justify-center gap-3', className)}>
2531
<div
2632
className="animate-book-flip"
2733
style={{
2834
width: iconSize,
2935
height: iconSize,
36+
color: 'var(--foreground)',
3037
}}
3138
>
3239
<BookOpen
3340
style={{
3441
width: iconSize,
3542
height: iconSize,
36-
color: 'var(--foreground)',
3743
}}
3844
/>
3945
</div>
40-
<p
46+
<p
4147
className="text-sm font-medium animate-pulse"
42-
style={{ color: 'var(--muted-foreground)' }}
48+
style={{
49+
color: 'var(--muted-foreground)',
50+
}}
4351
>
4452
{text}
4553
</p>
4654
</div>
4755
);
56+
57+
if (fullScreen) {
58+
return (
59+
<div
60+
className="fixed inset-0 flex items-center justify-center z-50"
61+
style={{
62+
backgroundColor: 'var(--background)',
63+
color: 'var(--foreground)',
64+
}}
65+
>
66+
{content}
67+
</div>
68+
);
69+
}
70+
71+
return content;
4872
}

0 commit comments

Comments
 (0)