Skip to content

Commit 0ed1f7f

Browse files
committed
fixed bugs (mainly pinned)
1 parent c89e219 commit 0ed1f7f

File tree

12 files changed

+213
-77
lines changed

12 files changed

+213
-77
lines changed

src/app/api/user-papers/route.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ export async function POST(req: Request) {
1919
subject: { $in: subjects },
2020
});
2121

22+
console.log("Fetched user papers:", usersPapers);
23+
2224
const transformedPapers = usersPapers.reduce<TransformedPaper[]>(
2325
(acc, paper) => {
2426
const existing = acc.find((item) => item.subject === paper.subject);
2527

2628
if (existing) {
27-
existing.slots.push(paper.slot);
28-
} else {
29-
acc.push({ subject: paper.subject, slots: [paper.slot] });
30-
}
31-
if (existing) {
32-
existing.slots.push(paper.slot);
29+
if (!existing.slots.includes(paper.slot)) {
30+
existing.slots.push(paper.slot);
31+
}
3332
} else {
3433
acc.push({ subject: paper.subject, slots: [paper.slot] });
3534
}

src/app/pinned/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ const Pinned = () => {
1414
<SearchBar type="pinned" />
1515
</div>
1616
</div>
17-
<PinnedPapersCarousel carouselType="users" />
17+
<div className="min-h-[20vh]">
18+
<PinnedPapersCarousel carouselType="users" />
19+
</div>
1820
<div className="mt-6 flex w-full items-center justify-center">
19-
<p>You can pin upto 8 Subjects</p>
21+
<p>You can pin upto 8 Subjects here</p>
2022
</div>
2123
</div>
2224
);

src/components/CatalogueContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SideBar from "../components/SideBar";
1313
import Error from "./Error";
1414
import { Filter } from "lucide-react";
1515
import { Sheet, SheetContent, SheetTrigger } from "./ui/sheet";
16-
import { StarIcon } from "lucide-react";
16+
import { Pin } from "lucide-react";
1717
import { StoredSubjects } from "@/interface";
1818

1919
export async function downloadFile(url: string, filename: string) {
@@ -342,7 +342,7 @@ const CatalogueContent = () => {
342342
</div>
343343
<div className="mt-7">
344344
<button onClick={handlePinToggle}>
345-
<StarIcon
345+
<Pin
346346
className={`h-7 w-7 ${pinned ? "fill-[#A78BFA]" : ""} stroke-white`}
347347
/>
348348
</button>

src/components/FloatingNavbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { usePathname } from "next/navigation";
44
import Link from "next/link";
5-
import { StarIcon, UploadIcon } from "lucide-react";
5+
import { Pin, UploadIcon } from "lucide-react";
66
import ModeToggle from "./toggle-theme";
77

88
interface Props {
@@ -29,7 +29,7 @@ export default function FloatingNavbar({ onNavigate }: Props) {
2929

3030
<Link href="/pinned" onClick={onNavigate}>
3131
<div className="flex items-center gap-2 rounded-full border border-[#3A3745] px-4 py-2 text-sm font-semibold text-white transition hover:bg-[#1A1823]">
32-
<StarIcon className="h-4 w-4" />
32+
<Pin className="h-4 w-4" />
3333
<span>Pinned Subjects</span>
3434
</div>
3535
</Link>

src/components/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default function Footer() {
106106
<h3 className="font-jost text-xl font-semibold">Our Projects</h3>
107107
<Link href="https://papers.codechefvit.com">Papers</Link>
108108
<Link href="https://contactify.codechefvit.com">Contactify</Link>
109-
<Link href="https://ffcs.codechefvit.com">FFCS Combogen</Link>
109+
<Link href="https://ffcs.codechefvit.com">FFCS-inator</Link>
110110
</div>
111111

112112
{/* Suggestions */}

src/components/Navbar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Link from "next/link";
66
import { usePathname } from "next/navigation";
77
import ccLogo from "../assets/codechef_logo.svg";
88
import ModeToggle from "@/components/toggle-theme";
9-
import { ArrowDownLeftIcon, StarIcon } from "lucide-react";
9+
import { ArrowDownLeftIcon, Pin } from "lucide-react";
1010
import NavDropdownButton from "./NavDropdownButton";
1111
import FloatingNavbar from "./FloatingNavbar";
1212
import PWAInstallButton from "./ui/PWAInstallButton";
@@ -55,10 +55,10 @@ function Navbar() {
5555
Papers
5656
</Link>
5757

58-
<div className="hidden md:flex">
58+
<div className="mt-3 hidden md:flex">
5959
<Link href="/pinned">
6060
<div className="ml-2 flex items-center gap-2 rounded-full border border-[#3A3745] px-4 py-2 text-sm font-semibold text-white transition hover:bg-[#1A1823]">
61-
<StarIcon className="h-4 w-4" />
61+
<Pin className="h-4 w-4" />
6262
Pinned Subjects
6363
</div>
6464
</Link>
@@ -70,7 +70,7 @@ function Navbar() {
7070
<ModeToggle />
7171
</div>
7272

73-
<div className="hidden md:block max-w-[200px]">
73+
<div className="hidden max-w-[200px] md:block">
7474
<PWAInstallButton />
7575
</div>
7676

src/components/PapersCarousel.tsx

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,38 @@ function PapersCarousel() {
9797
))}
9898
</CarouselItem>
9999
) : (
100-
chunkedPapers.map((paperGroup, index) => (
101-
<CarouselItem
102-
key={`carousel-item-${index}`}
103-
className={`grid ${
104-
chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
105-
} gap-4 lg:auto-rows-fr`}
106-
>
107-
{paperGroup.map((paper, subIndex) => (
108-
<div key={subIndex} className="h-full">
109-
<UpcomingPaper
110-
subject={paper.subject}
111-
slots={paper.slots}
112-
/>
113-
</div>
114-
))}
115-
</CarouselItem>
116-
))
100+
chunkedPapers.map((paperGroup, index) => {
101+
const placeholdersNeeded = chunkSize - paperGroup.length;
102+
103+
return (
104+
<CarouselItem
105+
key={`carousel-item-${index}`}
106+
className={`grid ${
107+
chunkSize === 4
108+
? "grid-cols-2 grid-rows-2"
109+
: "grid-cols-4 grid-rows-2"
110+
} gap-4 lg:auto-rows-fr`}
111+
>
112+
{paperGroup.map((paper, subIndex) => (
113+
<div key={subIndex} className="h-full">
114+
<UpcomingPaper
115+
subject={paper.subject}
116+
slots={paper.slots}
117+
/>
118+
</div>
119+
))}
120+
121+
{Array.from({ length: placeholdersNeeded }).map(
122+
(_, placeholderIndex) => (
123+
<div
124+
key={`placeholder-${placeholderIndex}`}
125+
className="invisible h-full"
126+
></div>
127+
),
128+
)}
129+
</CarouselItem>
130+
);
131+
})
117132
)}
118133
</CarouselContent>
119134
</Carousel>

src/components/PinButton.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { Star, StarOff } from "lucide-react";
3+
import { Pin, PinOff } from "lucide-react";
44

55
export default function PinButton({
66
isPinned,
@@ -16,11 +16,7 @@ export default function PinButton({
1616
isPinned ? "bg-purple-700 text-white" : "bg-[#2B2B30] text-white/80"
1717
} transition hover:bg-purple-600`}
1818
>
19-
{isPinned ? (
20-
<Star className="h-4 w-4" />
21-
) : (
22-
<StarOff className="h-4 w-4" />
23-
)}
19+
{isPinned ? <Pin className="h-4 w-4" /> : <PinOff className="h-4 w-4" />}
2420
<span className="hidden sm:inline">{isPinned ? "Pinned" : "Pin"}</span>
2521
</button>
2622
);

src/components/PinnedPapersCarousel.tsx

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
CarouselNext,
1313
CarouselPrevious,
1414
} from "@/components/ui/carousel";
15+
import { Skeleton } from "./ui/skeleton";
1516
import AddPapers from "./AddPapers";
1617
import Autoplay from "embla-carousel-autoplay";
1718
import { chunkArray } from "@/util/utils";
@@ -53,10 +54,15 @@ function PinnedPapersCarousel({
5354
localStorage.getItem("userSubjects") ?? "[]",
5455
) as StoredSubjects;
5556

57+
console.log("Fetching papers for subjects:", storedSubjects);
58+
5659
const response = await axios.post<{ subject: string; slots: string[] }[]>(
5760
"/api/user-papers",
5861
storedSubjects,
5962
);
63+
64+
console.log("Fetched papers:", response.data);
65+
6066
const fetchedPapers = response.data;
6167

6268
const fetchedSubjectsSet = new Set(
@@ -99,10 +105,6 @@ function PinnedPapersCarousel({
99105
};
100106
}, []);
101107

102-
if (isLoading) {
103-
return <Loader prop="m-10" />;
104-
}
105-
106108
const plugins = [Autoplay({ delay: 8000, stopOnInteraction: true })];
107109

108110
return (
@@ -116,36 +118,68 @@ function PinnedPapersCarousel({
116118
plugins={plugins}
117119
className="w-full"
118120
>
119-
<div className="relative mt-4 flex justify-end gap-4">
121+
<div
122+
className={`relative mt-4 flex justify-end gap-4 ${displayPapers.length > 0 ? "block" : "hidden"}`}
123+
>
120124
<CarouselPrevious className="relative" />
121125
<CarouselNext className="relative" />
122126
</div>
123127
<CarouselContent>
124-
{chunkedPapers.map((paperGroup, index) => {
125-
const isLastChunk = index === chunkedPapers.length - 1;
126-
127-
return (
128-
<CarouselItem
129-
key={`carousel-item-${index}`}
130-
className="grid grid-cols-2 grid-rows-2 gap-4 md:grid-cols-4 lg:auto-rows-fr"
131-
>
132-
{paperGroup.map((paper, subIndex) => (
133-
<div key={subIndex} className="h-full">
134-
<UpcomingPaper
135-
subject={paper.subject}
136-
slots={paper.slots}
137-
/>
128+
{isLoading ? (
129+
<CarouselItem
130+
className={`grid ${
131+
chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
132+
} gap-4 lg:auto-rows-fr`}
133+
>
134+
{Array.from({ length: chunkSize }).map((_, idx) => (
135+
<div
136+
key={idx}
137+
className="cursor-pointer rounded-sm border-2 border-[#734DFF] bg-[#FFFFFF] text-black shadow-lg transition duration-150 ease-in-out hover:bg-[#EFEAFF] dark:border-[#36266D] dark:bg-[#171720] dark:text-white hover:dark:bg-[#262635]"
138+
>
139+
<div className="border-b-2 border-[#453D60] p-2">
140+
<Skeleton className="h-6 w-24 rounded-md" />
138141
</div>
139-
))}
140-
141-
{isLastChunk && displayPapers.length < 8 && (
142-
<div className="h-full">
143-
<AddPapers />
142+
<div className="flex flex-col justify-between p-4">
143+
<Skeleton className="mb-4 h-6 w-32 rounded-md" />
144+
<div className="flex gap-2">
145+
<Skeleton className="h-7 w-16 rounded-full" />
146+
<Skeleton className="h-7 w-16 rounded-full" />
147+
</div>
144148
</div>
145-
)}
146-
</CarouselItem>
147-
);
148-
})}
149+
</div>
150+
))}
151+
</CarouselItem>
152+
) : (
153+
chunkedPapers.map((paperGroup, index) => {
154+
const isLastChunk = index === chunkedPapers.length - 1;
155+
156+
return (
157+
<CarouselItem
158+
key={`carousel-item-${index}`}
159+
className={`grid ${
160+
chunkSize === 4
161+
? "grid-cols-2 grid-rows-2"
162+
: "grid-cols-4"
163+
} gap-4 lg:auto-rows-fr`}
164+
>
165+
{paperGroup.map((paper, subIndex) => (
166+
<div key={subIndex} className="h-full">
167+
<UpcomingPaper
168+
subject={paper.subject}
169+
slots={paper.slots}
170+
/>
171+
</div>
172+
))}
173+
174+
{isLastChunk && displayPapers.length < 8 && (
175+
<div className="h-full">
176+
<AddPapers />
177+
</div>
178+
)}
179+
</CarouselItem>
180+
);
181+
})
182+
)}
149183
</CarouselContent>
150184
</Carousel>
151185
</div>

0 commit comments

Comments
 (0)