-
Notifications
You must be signed in to change notification settings - Fork 186
[Feat] all pro sessions at one place #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
huamanraj
wants to merge
19
commits into
apsinghdev:main
Choose a base branch
from
huamanraj:feat/pro-sessions-hub
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2be3239
feat: posthog event tracting for analytics
huamanraj 58cd726
fix: sanitizing the callback URL
huamanraj 956a8b1
chore: add analytics for signin
apsinghdev 4c12ccc
chore: update the msg
apsinghdev 428193a
perf: optimize Hero animations following best practices
ketankauntia 4a9f2ad
feat: added gsoc orgs + tested it
ketankauntia 08b471c
chore: fixes + capitalization consistency of words
ketankauntia ebb397c
chore: add newsletter 2
apsinghdev f0d0391
chore: delete the inc file
apsinghdev b502122
chore: delete useless file
apsinghdev 35bce3f
Merge branch 'apsinghdev:main' into main
huamanraj 88b5a1b
feat: Pro Sessions page
huamanraj b827703
fix: made divs keyboard accessible
huamanraj e5c4ab8
fix: ts errors
huamanraj 9bcbfed
Merge branch 'apsinghdev:main' into feat/pro-sessions-hub
huamanraj b40243e
migrated pro session to db from frotend
huamanraj 57b1f2f
type error fix
huamanraj 27a00ab
refactor: restructure session components and optimize data fetching
huamanraj 98dd02e
enhance error handling in getSessions
huamanraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { router, protectedProcedure } from "../trpc.js"; | ||
| import { sessionService } from "../services/session.service.js"; | ||
|
|
||
| export const sessionsRouter = router({ | ||
| // get all sessions for authenticated paid users | ||
| getAll: protectedProcedure.query(async ({ ctx }) => { | ||
| const userId = ctx.user.id; | ||
| return await sessionService.getSessions(ctx.db.prisma, userId); | ||
| }), | ||
| }); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import type { Prisma, PrismaClient } from "@prisma/client"; | ||
| import type { ExtendedPrismaClient } from "../prisma.js"; | ||
| import { SUBSCRIPTION_STATUS } from "../constants/subscription.js"; | ||
|
|
||
| export type SessionWithTopics = Prisma.WeeklySessionGetPayload<{ | ||
| select: { | ||
| id: true; | ||
| title: true; | ||
| description: true; | ||
| youtubeUrl: true; | ||
| sessionDate: true; | ||
| topics: { | ||
| select: { | ||
| id: true; | ||
| timestamp: true; | ||
| topic: true; | ||
| order: true; | ||
| }; | ||
| }; | ||
| }; | ||
| }>; | ||
|
|
||
| export const sessionService = { | ||
| /** | ||
| * Get all sessions for authenticated paid users | ||
| * Sessions are ordered by sessionDate descending (newest first) | ||
| */ | ||
| async getSessions( | ||
| prisma: ExtendedPrismaClient | PrismaClient, | ||
| userId: string | ||
| ): Promise<SessionWithTopics[]> { | ||
| try { | ||
| // verify user has active subscription | ||
| const subscription = await prisma.subscription.findFirst({ | ||
| where: { | ||
| userId, | ||
| status: SUBSCRIPTION_STATUS.ACTIVE, | ||
| endDate: { | ||
| gte: new Date(), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| if (!subscription) { | ||
| throw new Error("Active subscription required to access sessions"); | ||
| } | ||
| } catch (error) { | ||
| // log error with context before rethrowing | ||
| // rethrowing ensures automatic transaction rollback if this is part of a transaction | ||
| const timestamp = new Date().toISOString(); | ||
| const functionName = "getSessions"; | ||
|
|
||
| console.error( | ||
| `[${timestamp}] Error in sessionService.${functionName} - userId: ${userId}, endpoint: ${functionName}`, | ||
| error | ||
| ); | ||
|
|
||
| // rethrow to ensure transaction rollback (if in transaction) and proper error propagation | ||
| throw error; | ||
| } | ||
|
|
||
| // fetch only fields needed by the web ui; keep topics ordered | ||
| const sessions = await prisma.weeklySession.findMany({ | ||
| select: { | ||
| id: true, | ||
| title: true, | ||
| description: true, | ||
| youtubeUrl: true, | ||
| sessionDate: true, | ||
| topics: { | ||
| select: { | ||
| id: true, | ||
| timestamp: true, | ||
| topic: true, | ||
| order: true, | ||
| }, | ||
| orderBy: { | ||
| order: "asc", | ||
| }, | ||
| }, | ||
| }, | ||
| orderBy: { | ||
| sessionDate: "desc", | ||
| }, | ||
| }); | ||
|
|
||
| return sessions; | ||
| }, | ||
| }; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
apps/web/src/app/(main)/dashboard/pro/sessions/_components/SessionCard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| "use client"; | ||
|
|
||
| import { Play } from "lucide-react"; | ||
|
|
||
| import type { WeeklySession } from "./session-types"; | ||
|
|
||
| type SessionCardProps = { | ||
| session: WeeklySession; | ||
| onPlayAction: (session: WeeklySession) => void; | ||
| }; | ||
|
|
||
| export function SessionCard({ | ||
| session, | ||
| onPlayAction, | ||
| }: SessionCardProps): JSX.Element | null { | ||
| return ( | ||
| <div className="bg-dash-surface border border-dash-border rounded-xl p-5"> | ||
| <div className="flex items-start justify-between gap-4"> | ||
| <div className="min-w-0"> | ||
| <h3 className="text-text-primary font-semibold text-lg truncate"> | ||
| {session.title} | ||
| </h3> | ||
| {session.description ? ( | ||
| <p className="text-text-secondary text-sm mt-1 line-clamp-2"> | ||
| {session.description} | ||
| </p> | ||
| ) : null} | ||
| </div> | ||
|
|
||
| <button | ||
| type="button" | ||
| aria-label={`Play session: ${session.title}`} | ||
| className="shrink-0 inline-flex items-center justify-center w-10 h-10 rounded-full bg-brand-purple/10 hover:bg-brand-purple transition-all duration-200 focus-visible:ring-2 focus-visible:ring-brand-purple/50 focus-visible:outline-none" | ||
| onClick={() => onPlayAction(session)} | ||
| > | ||
| <Play className="w-4 h-4 text-brand-purple-light hover:text-text-primary" /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
|
|
142 changes: 142 additions & 0 deletions
142
apps/web/src/app/(main)/dashboard/pro/sessions/_components/SessionVideoDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useMemo, useRef } from "react"; | ||
|
|
||
| import { CheckCircle2, X } from "lucide-react"; | ||
|
|
||
| import { getYoutubeEmbedUrl } from "./youtube"; | ||
| import type { WeeklySession } from "./session-types"; | ||
|
|
||
| type SessionVideoDialogProps = { | ||
| isOpen: boolean; | ||
| session: WeeklySession | null; | ||
| onCloseAction: () => void; | ||
| }; | ||
|
|
||
| export function SessionVideoDialog({ | ||
| isOpen, | ||
| session, | ||
| onCloseAction, | ||
| }: SessionVideoDialogProps): JSX.Element | null { | ||
| const closeButtonRef = useRef<HTMLButtonElement | null>(null); | ||
|
|
||
| const embedUrl = useMemo(() => { | ||
| if (!session?.youtubeUrl) return null; | ||
| return getYoutubeEmbedUrl(session.youtubeUrl); | ||
| }, [session?.youtubeUrl]); | ||
|
|
||
| useEffect(() => { | ||
| if (!isOpen) return; | ||
|
|
||
| const previousOverflow = document.body.style.overflow; | ||
| document.body.style.overflow = "hidden"; | ||
| closeButtonRef.current?.focus(); | ||
|
|
||
| return () => { | ||
| document.body.style.overflow = previousOverflow; | ||
| }; | ||
| }, [isOpen]); | ||
|
|
||
| if (!isOpen || !session) return null; | ||
|
|
||
| return ( | ||
| <div | ||
| className="fixed inset-0 z-50" | ||
| role="dialog" | ||
| aria-modal="true" | ||
| aria-label={`Session video: ${session.title}`} | ||
| onKeyDown={(e) => { | ||
| if (e.key === "Escape") onCloseAction(); | ||
| }} | ||
| > | ||
| <button | ||
| type="button" | ||
| aria-label="Close session video" | ||
| className="absolute inset-0 bg-black/60" | ||
| onClick={onCloseAction} | ||
| /> | ||
|
|
||
| <div className="relative h-full w-full p-4 sm:p-6 flex items-center justify-center"> | ||
| <div className="relative w-full max-w-5xl bg-dash-surface border border-dash-border rounded-2xl shadow-xl overflow-hidden"> | ||
| <div className="flex items-center justify-between gap-3 px-4 sm:px-5 py-3 border-b border-dash-border"> | ||
| <div className="min-w-0"> | ||
| <p className="text-text-primary font-semibold truncate"> | ||
| {session.title} | ||
| </p> | ||
| {session.description ? ( | ||
| <p className="text-text-muted text-sm truncate"> | ||
| {session.description} | ||
| </p> | ||
| ) : null} | ||
| </div> | ||
|
|
||
| <button | ||
| ref={closeButtonRef} | ||
| type="button" | ||
| className="shrink-0 inline-flex items-center justify-center h-9 w-9 rounded-lg bg-dash-raised hover:bg-dash-hover transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-brand-purple/50 focus-visible:outline-none" | ||
| onClick={onCloseAction} | ||
| > | ||
| <X className="h-4 w-4 text-text-secondary" /> | ||
| </button> | ||
| </div> | ||
|
|
||
| <div className="grid grid-cols-1 md:grid-cols-5"> | ||
| <div className="md:col-span-3 p-4 sm:p-5"> | ||
| <div className="w-full aspect-video rounded-xl overflow-hidden border border-dash-border bg-dash-base"> | ||
| {embedUrl ? ( | ||
| <iframe | ||
| key={embedUrl} | ||
| src={embedUrl} | ||
| title={session.title} | ||
| className="h-full w-full" | ||
| allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" | ||
| referrerPolicy="strict-origin-when-cross-origin" | ||
| allowFullScreen | ||
| /> | ||
| ) : ( | ||
| <div className="h-full w-full flex items-center justify-center p-6"> | ||
| <p className="text-text-secondary text-sm text-center"> | ||
| This session video link is invalid. | ||
| </p> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="md:col-span-2 border-t md:border-t-0 md:border-l border-dash-border"> | ||
| <div className="p-4 sm:p-5"> | ||
| <p className="text-text-muted text-xs uppercase tracking-wider font-medium"> | ||
| Topics covered | ||
| </p> | ||
|
|
||
| {session.topics?.length ? ( | ||
| <ul className="mt-3 space-y-2 max-h-[40vh] md:max-h-[60vh] overflow-auto pr-1"> | ||
| {session.topics.map((topic) => ( | ||
| <li | ||
| key={topic.id} | ||
| className="flex items-start gap-2.5 text-text-secondary text-sm" | ||
| > | ||
| <CheckCircle2 className="w-4 h-4 text-brand-purple/70 mt-0.5 flex-shrink-0" /> | ||
| <div className="min-w-0"> | ||
| <p className="text-text-secondary break-words"> | ||
| {topic.topic} | ||
| </p> | ||
| </div> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| ) : ( | ||
| <p className="mt-3 text-text-secondary text-sm"> | ||
| No topics listed for this session yet. | ||
| </p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.