Skip to content

Commit a8d9f03

Browse files
authored
Merge pull request #153 from riyapetle/RiyaCommits2
fix: Correct Upload Notes quick action routing on dashboard
2 parents 0880900 + 870dbfc commit a8d9f03

7 files changed

Lines changed: 87 additions & 14 deletions

File tree

src/app/(auth)/layout.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ export default function AuthLayout({
44
children: React.ReactNode;
55
}) {
66
return (
7-
<html>
8-
<body>
9-
<div className="auth">{children}</div>
10-
</body>
11-
</html>
7+
<div className="auth">{children}</div>
128
);
139
}

src/app/(auth)/login/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export default function LoginPage() {
3535

3636
const result = await user.json();
3737

38+
if (!user.ok || !result.user) {
39+
setErr(result.message || result.error || 'Login failed. Please check your credentials.');
40+
return;
41+
}
42+
3843
if (result.user.firstTime) {
3944
router.push('/profile');
4045
} else {

src/app/dashboard/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function DashboardPage() {
4343
name: 'Upload Notes',
4444
brief: 'Convert handwritten pages into structured study guides.',
4545
action: 'sync',
46-
href: `/`,
46+
href: `/notes/upload`,
4747
icon: (
4848
<svg
4949
width="18"

src/app/ncert/[class]/[subject]/[chapter]/page.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ChapterContent, {
44
type ChapterContentData,
55
} from '@/components/ChapterContent';
6+
import ReadingProgressBar from '@/components/ReadingProgressBar';
67
import { ChapterPageSkeleton } from '@/components/Skeletons';
78
import authFetch from '@/lib/auth/authFetch';
89
import { useParams } from 'next/navigation';
@@ -61,9 +62,14 @@ export default function NcertChapterPage() {
6162
getChapter();
6263
}, [getChapter]);
6364

64-
if (isLoading) {
65-
return <ChapterPageSkeleton />;
66-
}
67-
68-
return <ChapterContent chapter={chapter} error={error} />;
65+
return (
66+
<>
67+
<ReadingProgressBar chapterSlug={params.chapter} isLoading={isLoading} />
68+
{isLoading ? (
69+
<ChapterPageSkeleton />
70+
) : (
71+
<ChapterContent chapter={chapter} error={error} />
72+
)}
73+
</>
74+
);
6975
}

src/app/ncert/[class]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ export default function Page() {
150150

151151
<a
152152
className="bg-white text-[14px] font-bold p-3 mt-4 text-center hover:bg-primary cursor-pointer hover:text-white transition-all duration-300"
153-
href={`/ncert/${user?.user?.class}/${val.id}`}
153+
href={`/ncert/${params.class}/${val.id}`}
154154
>
155-
VIER CURRICULAM
155+
VIEW CURRICULUM
156156
</a>
157157
</div>
158158
);

src/components/Button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Button({
1919
return (
2020
<button
2121
className={` ${color ? color : 'bg-primary'} ${textCol ? textCol : ' text-white'} ${additional ? additional : ''} ${hover ? hover : 'hover:bg-primary/60'} uppercase p-4 pl-8 pr-8 font-bold transition-all duration-300 cursor-pointer text-[14px]`}
22-
onClick={action}
22+
onClick={typeof action === 'function' ? action : undefined}
2323
>
2424
{text}
2525
</button>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use client';
2+
3+
import { useEffect, useState } from 'react';
4+
5+
interface ReadingProgressBarProps {
6+
chapterSlug: string;
7+
isLoading?: boolean;
8+
}
9+
10+
export default function ReadingProgressBar({ chapterSlug, isLoading = false }: ReadingProgressBarProps) {
11+
const [progress, setProgress] = useState(0);
12+
13+
useEffect(() => {
14+
if (typeof window === 'undefined') return;
15+
16+
const storageKey = `reading-progress-${chapterSlug}`;
17+
18+
// Restore scroll position ONLY when content has finished loading
19+
if (!isLoading) {
20+
const savedScroll = localStorage.getItem(storageKey);
21+
if (savedScroll !== null) {
22+
setTimeout(() => {
23+
window.scrollTo({ top: Number(savedScroll), behavior: 'smooth' });
24+
}, 100);
25+
}
26+
}
27+
28+
const handleScroll = () => {
29+
const scrollTop = window.scrollY;
30+
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
31+
32+
if (docHeight > 0) {
33+
const currentProgress = (scrollTop / docHeight) * 100;
34+
setProgress(Math.min(100, Math.max(0, currentProgress)));
35+
} else {
36+
setProgress(0);
37+
}
38+
};
39+
40+
// Save scroll position persistently
41+
const saveScroll = () => {
42+
if (!isLoading) {
43+
localStorage.setItem(storageKey, window.scrollY.toString());
44+
}
45+
};
46+
47+
window.addEventListener('scroll', handleScroll);
48+
window.addEventListener('beforeunload', saveScroll);
49+
handleScroll();
50+
51+
return () => {
52+
saveScroll();
53+
window.removeEventListener('scroll', handleScroll);
54+
window.removeEventListener('beforeunload', saveScroll);
55+
};
56+
}, [chapterSlug, isLoading]);
57+
58+
return (
59+
<div className="fixed top-0 left-0 w-full h-1.5 z-[100]">
60+
<div
61+
className="h-full bg-primary transition-all duration-150 ease-out"
62+
style={{ width: `${progress}%` }}
63+
/>
64+
</div>
65+
);
66+
}

0 commit comments

Comments
 (0)