Skip to content

Commit

Permalink
Merge pull request #458 from claushaas/dev
Browse files Browse the repository at this point in the history
update lesson activity pages on member area
  • Loading branch information
claushaas authored Jan 19, 2025
2 parents efaa182 + 3dcba4c commit 03ca696
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v22.12.0
v22.13.0
49 changes: 48 additions & 1 deletion app/components/entities-cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ type LessonEntityCardPropierties = ClassCardPropierties & {
}> | undefined;
};

type LessonWithoutSuspenseEntityCardProperties = ClassCardPropierties & {
readonly activity: {
saved: boolean | undefined;
completed: boolean | undefined;
favorited: boolean | undefined;
} | undefined;
};

export function AdminEntityCard({course, to}: ClassCardPropierties) {
return (
<motion.div
Expand Down Expand Up @@ -141,7 +149,7 @@ export function LessonEntityCard({course, to, activity}: LessonEntityCardPropier
<p className='text-mauve-5 text-xs text-ellipsis line-clamp-3'>{course.description}</p>
<Suspense fallback={<YemSpinner/>}>
<Await resolve={activity}>
{activity => activity?.data && (
{activity => activity && (
<div className='flex justify-end'>
<div className='flex gap-3 items-center w-fit p-1 bg-mauvea-10 rounded-xl'>
{activity.data.completed ? <SolidCheckCircleIcon className='size-4 stroke-purple-11 fill-purple-11'/> : <CheckCircleIcon className='size-4'/>}
Expand All @@ -158,3 +166,42 @@ export function LessonEntityCard({course, to, activity}: LessonEntityCardPropier
</motion.div>
);
}

export function LessonWithoutSuspenseEntityCard({course: lesson, to, activity}: LessonWithoutSuspenseEntityCardProperties) {
return (
<motion.div
whileHover={{
scale: 1.05,
transition: {duration: 0.5},
}}
className='portrait:w-48 w-72 portrait:h-80 h-48 relative rounded-xl shadow-sm shadow-mauve-11 dark:shadow-mauvedark-3 flex-shrink-0'
>
<Image
className='absolute top-0 left-0 w-full h-full rounded-xl -z-10'
src={buildImgSource(`${lesson.thumbnailUrl}`)}
cdn='cloudflare_images'
layout='constrained'
width={320}
height={320}
alt={lesson.name as string}
/>
<Link to={to}>
<div className='absolute top-0 left-0 h-full w-full rounded-xl bg-mauvea-10 py-2 px-3 flex flex-col justify-between'>
<h2 className='text-mauve-3 text-sm drop-shadow-md'>
{lesson.name}
</h2>
<div>
<p className='text-mauve-5 text-xs text-ellipsis line-clamp-3'>{lesson.description}</p>
<div className='flex justify-end'>
<div className='flex gap-3 items-center w-fit p-1 bg-mauvea-10 rounded-xl'>
{activity?.completed ? <SolidCheckCircleIcon className='size-4 stroke-purple-11 fill-purple-11'/> : <CheckCircleIcon className='size-4'/>}
{activity?.saved ? <SolidBookmarkIcon className='size-4 stroke-purple-11 fill-purple-11'/> : <BookmarkIcon className='size-4'/>}
{activity?.favorited ? <SolidHeartIcon className='size-4 stroke-purple-11 fill-purple-11'/> : <HeartIcon className='size-4'/>}
</div>
</div>
</div>
</div>
</Link>
</motion.div>
);
}
13 changes: 7 additions & 6 deletions app/routes/profile.completed-lessons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {type LoaderFunctionArgs, useLoaderData, type MetaArgs} from 'react-router';
import {LessonEntityCard} from '~/components/entities-cards';
import {LessonActivityService} from '~/services/lesson-activity.service.server';
import {LessonWithoutSuspenseEntityCard} from '~/components/entities-cards';
import {LessonService} from '~/services/lesson.service.server';
import {type TypeUserSession} from '~/types/user-session.type';
import {getUserSession} from '~/utils/session.server';
Expand All @@ -18,11 +17,13 @@ export const loader = async ({request}: LoaderFunctionArgs) => {

const completedLessons = await new LessonService().getCompletedLessonsByUser(userData);

const lessonActivityService = new LessonActivityService();

const completedLessonsWithActivity = completedLessons.data.map(lesson => ({
...lesson,
activity: lessonActivityService.getLessonActivityForUser(lesson.lessonSlug, userData.id),
activity: {
completed: true,
saved: lesson.lesson.savedBy[0]?.isSaved ?? false,
favorited: lesson.lesson.favoritedBy[0]?.isFavorited ?? false,
},
}));

return {
Expand Down Expand Up @@ -50,7 +51,7 @@ export default function CompletedLessons() {

<div className='flex gap-4 my-4 flex-wrap'>
{completedLessonsWithActivity?.map(lesson => (
<LessonEntityCard key={lesson.id} course={lesson.lesson} to={lesson.link} activity={lesson.activity}/>
<LessonWithoutSuspenseEntityCard key={lesson.id} course={lesson.lesson} to={lesson.link} activity={lesson.activity}/>
))}
</div>
</div>
Expand Down
13 changes: 7 additions & 6 deletions app/routes/profile.favorited-lessons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {type LoaderFunctionArgs, useLoaderData, type MetaArgs} from 'react-router';
import {LessonEntityCard} from '~/components/entities-cards';
import {LessonActivityService} from '~/services/lesson-activity.service.server';
import {LessonWithoutSuspenseEntityCard} from '~/components/entities-cards';
import {LessonService} from '~/services/lesson.service.server';
import {type TypeUserSession} from '~/types/user-session.type';
import {getUserSession} from '~/utils/session.server';
Expand All @@ -18,11 +17,13 @@ export const loader = async ({request}: LoaderFunctionArgs) => {

const favoritedLessons = await new LessonService().getFavoritedLessonsByUser(userData);

const lessonActivityService = new LessonActivityService();

const favoritedLessonsWithActivity = favoritedLessons.data.map(lesson => ({
...lesson,
activity: lessonActivityService.getLessonActivityForUser(lesson.lessonSlug, userData.id),
activity: {
favorited: true,
saved: lesson.lesson.savedBy[0]?.isSaved ?? false,
completed: lesson.lesson.completedBy[0]?.isCompleted ?? false,
},
}));

return {
Expand Down Expand Up @@ -50,7 +51,7 @@ export default function FavoritedLessons() {

<div className='flex gap-4 my-4 flex-wrap'>
{favoritedLessonsWithActivity.map(lesson => (
<LessonEntityCard key={lesson.id} course={lesson.lesson} to={lesson.link} activity={lesson.activity}/>
<LessonWithoutSuspenseEntityCard key={lesson.id} course={lesson.lesson} to={lesson.link} activity={lesson.activity}/>
))}
</div>
</div>
Expand Down
13 changes: 7 additions & 6 deletions app/routes/profile.saved-lessons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {type LoaderFunctionArgs, useLoaderData, type MetaArgs} from 'react-router';
import {LessonEntityCard} from '~/components/entities-cards';
import {LessonActivityService} from '~/services/lesson-activity.service.server';
import {LessonWithoutSuspenseEntityCard} from '~/components/entities-cards';
import {LessonService} from '~/services/lesson.service.server';
import {type TypeUserSession} from '~/types/user-session.type';
import {getUserSession} from '~/utils/session.server';
Expand All @@ -26,11 +25,13 @@ export const loader = async ({request}: LoaderFunctionArgs) => {

const savedLessons = await new LessonService().getSavedLessonsByUser(userData);

const lessonActivityService = new LessonActivityService();

const savedLessonsWithActivity = savedLessons.data.map(lesson => ({
...lesson,
activity: lessonActivityService.getLessonActivityForUser(lesson.lessonSlug, userData.id),
activity: {
saved: true,
completed: lesson.lesson.completedBy[0]?.isCompleted ?? false,
favorited: lesson.lesson.favoritedBy[0]?.isFavorited ?? false,
},
}));

return {
Expand Down Expand Up @@ -58,7 +59,7 @@ export default function CompletedLessons() {

<div className='flex gap-4 my-4 flex-wrap'>
{savedLessonsWithActivity.map(lesson => (
<LessonEntityCard key={lesson.id} course={lesson.lesson} to={lesson.link} activity={lesson.activity}/>
<LessonWithoutSuspenseEntityCard key={lesson.id} course={lesson.lesson} to={lesson.link} activity={lesson.activity}/>
))}
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions app/services/lesson-activity.service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,3 @@ export class LessonActivityService {
}
}
}

type test = Prisma.LessonToModuleWhereInput;
36 changes: 36 additions & 0 deletions app/services/lesson.service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,18 @@ export class LessonService {
},
},
},
favoritedBy: {
where: {
userId: user.id,
isFavorited: true,
},
},
savedBy: {
where: {
userId: user.id,
isSaved: true,
},
},
},
},
},
Expand Down Expand Up @@ -644,6 +656,18 @@ export class LessonService {
},
},
},
favoritedBy: {
where: {
userId: user.id,
isFavorited: true,
},
},
completedBy: {
where: {
userId: user.id,
isCompleted: true,
},
},
},
},
},
Expand Down Expand Up @@ -710,6 +734,18 @@ export class LessonService {
},
},
},
savedBy: {
where: {
userId: user.id,
isSaved: true,
},
},
completedBy: {
where: {
userId: user.id,
isCompleted: true,
},
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions app/types/lesson.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export type TPrismaPayloadGetCompletedLessons = Array<Prisma.CompletedLessonsGet
};
};
};
favoritedBy: true;
savedBy: true;
};
};
};
Expand Down Expand Up @@ -169,6 +171,8 @@ export type TPrismaPayloadGetSavedLessons = Array<Prisma.SavedLessonsGetPayload<
};
};
};
favoritedBy: true;
completedBy: true;
};
};
};
Expand Down Expand Up @@ -209,6 +213,8 @@ export type TPrismaPayloadGetFavoritedLessons = Array<Prisma.FavoritedLessonsGet
};
};
};
savedBy: true;
completedBy: true;
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"sideEffects": false,
"type": "module",
"engines": {
"node": ">=22.12.0"
"node": ">=22.13.0"
},
"bugs:": "https://github.com/claushaas/yem/issues",
"scripts": {
Expand Down

0 comments on commit 03ca696

Please sign in to comment.