Skip to content

Commit

Permalink
Merge branch 'main' of github.com:nimit9/cms-new into feat/bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
nimit9 committed Mar 28, 2024
2 parents d9393ae + 7d8f6b7 commit e49737d
Show file tree
Hide file tree
Showing 21 changed files with 405 additions and 48 deletions.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Bug
about: Create a report to help us improve
title: "bug: "
labels: bug
assignees: ''
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Do something
2. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots or GIFs**
If applicable, add screenshots to help explain your problem.

**Info (please complete the following information):**
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Feature request
about: Suggest an idea for this project
title: 'feature: '
labels: enhancement
assignees: ''
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
9 changes: 9 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### PR Fixes:
- 1
- 2

Resolves #[Issue Number if there]

### Checklist before requesting a review
- [ ] I have performed a self-review of my code
- [ ] I assure there is no similar/duplicate pull request regarding same issue
80 changes: 80 additions & 0 deletions src/actions/refresh-db/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use server';
import db from '@/db';
import { Cache } from '@/db/Cache';
import { getAllCourses } from '@/db/course';
import { authOptions } from '@/lib/auth';
import { checkUserEmailForPurchase } from '@/utiles/appx-check-mail';
import { Course } from '@prisma/client';
import { getServerSession } from 'next-auth';

type RefreshDbFn = (args: { userId: string; email: string }) => Promise<{
error: boolean;
message: string;
}>;

export const refreshDb: RefreshDbFn = async () => {
const session = await getServerSession(authOptions);
const email = session?.user.email || '';
const userId = session?.user.id;

if (!email) {
return {
error: true,
message: 'You are not logged in',
};
}

// Only allow user to refetch every minute
if (Cache.getInstance().get('rate-limit', [email])) {
return {
error: true,
message: 'Wait sometime before refetching',
};
}

const allCourses = (await getAllCourses()) as Course[];

// Check which course the user has purchased
const userCourses = await db.userPurchases.findMany({
where: {
userId,
},
});

const coursesWithoutUser = allCourses.filter((course) => {
return !userCourses.some((userCourse) => userCourse.courseId === course.id);
});

const responses: Course[] = [];

const promises = coursesWithoutUser
.filter((x) => !x.openToEveryone)
.map(async (course) => {
const courseId = course.appxCourseId.toString();
const data = await checkUserEmailForPurchase(email, courseId);

if (data.data === '1') {
responses.push(course);
}
});

await Promise.all(promises);

responses.forEach(async (res) => {
try {
await db.userPurchases.create({
data: {
userId,
courseId: res.id,
},
});
} catch {
return { error: true, message: 'Unable to insert courses' };
}
});

Cache.getInstance().evict('courses', [email]);
Cache.getInstance().set('rate-limit', [email], true, 60);

return { error: false, message: 'Refetched Courses' };
};
15 changes: 14 additions & 1 deletion src/app/courses/[...courseId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ import db from '@/db';
import { rateLimit } from '@/lib/utils';
import BookmarkView from '@/components/bookmark/BookmarkView';

interface PurchaseType {
id: number;
title: string;
imageUrl: string;
description: string;
appxCourseId: number;
openToEveryone: boolean;
slug: string;
discordRoleId: string;
totalVideos?: number;
totalVideosWatched: number;
}

const getBookmarkData = async (
courseId: string,
): Promise<TBookmarkWithContent[] | { error: string }> => {
Expand Down Expand Up @@ -47,7 +60,7 @@ const checkAccess = async (courseId: string) => {
return false;
}
const purchases = await getPurchases(session.user.email);
if (purchases.map((p: any) => p.id).includes(Number(courseId))) {
if (purchases.map((p: PurchaseType) => p.id).includes(Number(courseId))) {
return true;
}
return false;
Expand Down
21 changes: 21 additions & 0 deletions src/app/pdf/[contentId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NotionAPI } from 'notion-client';
import db from '@/db';
const notion = new NotionAPI();
import PrintNotes from '@/components/print/PrintNotes';

export default async function PrintNotion({
params: { contentId },
}: {
params: { contentId: string };
}) {
const notionMetadata = await db.notionMetadata.findFirst({
where: {
contentId: parseInt(contentId, 10),
},
});

if (notionMetadata?.notionId) {
const recordMap = await notion.getPage(notionMetadata?.notionId);
return <PrintNotes recordMap={recordMap} />;
}
}
4 changes: 2 additions & 2 deletions src/components/Appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Appbar = () => {

return (
<>
<nav className="fixed z-50 top-0 px-4 w-full h-16 border-b shadow-sm bg-background/80 backdrop-blur-md flex items-center gap-2">
<nav className="fixed z-50 top-0 px-4 w-full h-16 border-b shadow-sm bg-background/80 backdrop-blur-md flex items-center gap-2 print:hidden">
{currentPath.includes('courses') && (
<ToggleButton
onClick={() => {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const Appbar = () => {
)}
</div>
</nav>
<div className="h-16 w-full" />
<div className="h-16 w-full print:hidden" />
</>
);
};
40 changes: 22 additions & 18 deletions src/components/Courses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@
import { Course } from '@prisma/client';
import { CourseCard } from './CourseCard';
import { useRouter } from 'next/navigation';
import { RefreshDb } from './RefreshDb';

export const Courses = ({ courses }: { courses: Course[] }) => {
const router = useRouter();
return (
<div className="max-w-screen-xl w-full mx-auto py-6 px-6 cursor-pointer grid grid-cols-1 gap-5 md:grid-cols-3">
{courses?.map((course) => (
<CourseCard
key={course.id}
course={course}
onClick={() => {
if (
course.title.includes('Machine Learning') ||
course.title.includes('Harnoor')
) {
router.push('https://harkirat.classx.co.in/');
} else {
router.push(`/courses/${course.id}`);
}
}}
/>
))}
</div>
<section className="flex flex-col items-center w-full">
<div className="max-w-screen-xl w-full mx-auto py-6 px-6 cursor-pointer grid grid-cols-1 gap-5 md:grid-cols-3">
{courses?.map((course) => (
<CourseCard
key={course.id}
course={course}
onClick={() => {
if (
course.title.includes('Machine Learning') ||
course.title.includes('Harnoor')
) {
router.push('https://harkirat.classx.co.in/');
} else {
router.push(`/courses/${course.id}`);
}
}}
/>
))}
</div>
<RefreshDb />
</section>
);
};
20 changes: 19 additions & 1 deletion src/components/NotionRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import 'prismjs/themes/prism-tomorrow.css';
// used for rendering equations (optional)
import 'katex/dist/katex.min.css';
import { Loader } from './Loader';
import Link from 'next/link';
import { Button } from './ui/button';
import { DownloadIcon } from 'lucide-react';

// Week-4-1-647987d9b1894c54ba5c822978377910
export const NotionRenderer = ({ id }: { id: string }) => {
Expand All @@ -37,7 +40,22 @@ export const NotionRenderer = ({ id }: { id: string }) => {
}

return (
<div>
<div className="relative">
<Link
href={`/pdf/${id}`}
target="_blank"
className="absolute right-4 top-4 z-20"
>
<Button
variant="outline"
className="bg-white text-black dark:bg-[#020917] dark:text-white"
>
Download
<div className="pl-2">
<DownloadIcon />
</div>
</Button>
</Link>
<div style={{}}>
<NotionRendererLib
recordMap={data}
Expand Down
31 changes: 31 additions & 0 deletions src/components/RefreshDb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';
import { refreshDb } from '@/actions/refresh-db';
import { Button } from './ui/button';
import { toast } from 'sonner';
import { useSession } from 'next-auth/react';

export function RefreshDb() {
const session = useSession();
console.log(session);

const handleClick = async () => {
// @ts-ignore
const res = await refreshDb({ userId: session.data.user.id });
if (res.error) {
toast.error(res.message);
} else {
toast.info(res.message);
}
};

if (session.status === 'loading') return <>Loading...</>;

return (
<div className="flex flex-col gap-2">
<h1>Don't see all your courses?</h1>
<Button className="dark:text-white" onClick={handleClick}>
Refresh Database
</Button>
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/ThemeToggler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function ThemeToggler() {
const { setTheme } = useTheme();

return (
<DropdownMenu>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="iconSM">
<SunDimIcon className="h-[1rem] w-[1rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
Expand Down
34 changes: 33 additions & 1 deletion src/components/VideoPlayer2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,43 @@ export const VideoPlayer: FunctionComponent<VideoPlayerProps> = ({
player.currentTime(player.currentTime() - 5);
event.stopPropagation();
break;
case 'KeyF': // F key for fullscree
case 'KeyF': // F key for fullscreen
if (player.isFullscreen_) document.exitFullscreen();
else player.requestFullscreen();
event.stopPropagation();
break;
case 'KeyR': // 'R' key to restart playback from the beginning
player.currentTime(0);
event.stopPropagation();
break;
case 'KeyM': // 'M' key to toggle mute/unmute
if (player.volume() === 0) {
player.volume(1);
} else {
player.volume(0);
}
event.stopPropagation();
break;
case 'KeyK': // 'K' key for play/pause toggle
if (player.paused()) {
player.play();
} else {
player.pause();
}
event.stopPropagation();
break;
case 'KeyJ': // 'J' key for seeking backward 10 seconds multiplied by the playback rate
player.currentTime(
player.currentTime() - 10 * player.playbackRate(),
);
event.stopPropagation();
break;
case 'KeyL': // 'L' key for seeking forward 10 seconds multiplied by the playback rate
player.currentTime(
player.currentTime() + 10 * player.playbackRate(),
);
event.stopPropagation();
break;
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/comment/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const Comments = async ({
parentId={data?.parentComment?.id}
/>
<div className="mb-5 flex mt-5">
<DropdownMenu key="1">
<DropdownMenu key="1" modal={false}>
<DropdownMenuTrigger asChild>
<Button
className="w-[200px] justify-between text-left font-normal"
Expand Down Expand Up @@ -169,7 +169,7 @@ const Comments = async ({
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
<DropdownMenu>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button
className="w-[200px] justify-between text-left font-normal"
Expand Down
Loading

0 comments on commit e49737d

Please sign in to comment.