mirror of
https://github.com/sanidhyy/duolingo-clone.git
synced 2025-05-17 13:55:52 +08:00
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
|
|
import { FeedWrapper } from "@/components/feed-wrapper";
|
|
import { Promo } from "@/components/promo";
|
|
import { Quests } from "@/components/quests";
|
|
import { StickyWrapper } from "@/components/sticky-wrapper";
|
|
import { UserProgress } from "@/components/user-progress";
|
|
import {
|
|
getCourseProgress,
|
|
getLessonPercentage,
|
|
getUnits,
|
|
getUserProgress,
|
|
getUserSubscription,
|
|
} from "@/db/queries";
|
|
|
|
import { Header } from "./header";
|
|
import { Unit } from "./unit";
|
|
|
|
const LearnPage = async () => {
|
|
const userProgressData = getUserProgress();
|
|
const courseProgressData = getCourseProgress();
|
|
const lessonPercentageData = getLessonPercentage();
|
|
const unitsData = getUnits();
|
|
const userSubscriptionData = getUserSubscription();
|
|
|
|
const [
|
|
userProgress,
|
|
units,
|
|
courseProgress,
|
|
lessonPercentage,
|
|
userSubscription,
|
|
] = await Promise.all([
|
|
userProgressData,
|
|
unitsData,
|
|
courseProgressData,
|
|
lessonPercentageData,
|
|
userSubscriptionData,
|
|
]);
|
|
|
|
if (!courseProgress || !userProgress || !userProgress.activeCourse)
|
|
redirect("/courses");
|
|
|
|
const isPro = !!userSubscription?.isActive;
|
|
|
|
return (
|
|
<div className="flex flex-row-reverse gap-[48px] px-6">
|
|
<StickyWrapper>
|
|
<UserProgress
|
|
activeCourse={userProgress.activeCourse}
|
|
hearts={userProgress.hearts}
|
|
points={userProgress.points}
|
|
hasActiveSubscription={isPro}
|
|
/>
|
|
|
|
{!isPro && <Promo />}
|
|
<Quests points={userProgress.points} />
|
|
</StickyWrapper>
|
|
<FeedWrapper>
|
|
<Header title={userProgress.activeCourse.title} />
|
|
{units.map((unit) => (
|
|
<div key={unit.id} className="mb-10">
|
|
<Unit
|
|
id={unit.id}
|
|
order={unit.order}
|
|
description={unit.description}
|
|
title={unit.title}
|
|
lessons={unit.lessons}
|
|
activeLesson={courseProgress.activeLesson}
|
|
activeLessonPercentage={lessonPercentage}
|
|
/>
|
|
</div>
|
|
))}
|
|
</FeedWrapper>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default LearnPage;
|