-
Notifications
You must be signed in to change notification settings - Fork 1.1k
new: add video duration to cards #902
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughAdds moment-based duration formatting and renders a duration badge in CapCard when cap.metadata?.duration exists. Change is internal to CapCard; no public component signatures or VideoThumbnail props were modified. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CapCard
User->>CapCard: Render cap card
CapCard->>CapCard: parse & format duration (moment) if metadata.duration
CapCard-->>User: Render duration badge (when present)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx (1)
454-467: Add optionalvideoMetadataprop to VideoThumbnail and rename usageThe
VideoThumbnailPropsinterface currently only definesuserId,videoId, andalt. Since you’re passingcap.metadata, you need to:
- Declare a new optional prop in
VideoThumbnailProps:import { VideoMetadata } from "…"; // wherever VideoMetadata lives interface VideoThumbnailProps { userId: string; videoId: string; alt: string; videoMetadata?: VideoMetadata; // new, optional }- Destructure and safely handle it in the component:
export const VideoThumbnail: React.FC<VideoThumbnailProps> = memo( ({ userId, videoId, alt, videoMetadata }) => { // e.g. const { resolution, bandwidth } = videoMetadata ?? {}; // … } );- Rename the prop in
CapCard.tsxfor consistency:<VideoThumbnail- videoMetaData={cap.metadata}
- videoMetadata={cap.metadata}
imageClass={…}
userId={cap.ownerId}
videoId={cap.id}
alt={${cap.name} Thumbnail}
/>Locations to update: - **apps/web/components/VideoThumbnail.tsx** – Add import of `VideoMetadata` – Extend `VideoThumbnailProps` with `videoMetadata?: VideoMetadata` – Update component signature and internal handling - **apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx** – Change `videoMetaData` → `videoMetadata` </blockquote></details> </blockquote></details> <details> <summary>🧹 Nitpick comments (2)</summary><blockquote> <details> <summary>apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx (2)</summary><blockquote> `108-124`: **Replace Moment-based formatter; fix pluralization and multi-hour handling** Current logic returns "1 hr" for any duration ≥ 1 hour, and produces "1 mins" for 1 minute. It also depends on Moment unnecessarily. A small math-based formatter is clearer, correct, and cheaper for the bundle. ```diff - const formatDuration = (duration: number | undefined) => { - if (!duration) return "0 secs"; - - const momentDuration = moment.duration(duration, "milliseconds"); - const totalMinutes = Math.floor(momentDuration.asMinutes()); - const totalHours = Math.floor(momentDuration.asHours()); - const seconds = momentDuration.seconds(); - - if (totalHours > 0) { - return "1 hr"; - } else if (totalMinutes > 0) { - return `${totalMinutes} mins`; - } else { - return `${seconds} secs`; - } - }; + const formatDuration = (durationMs?: number) => { + const totalSeconds = Math.max(0, Math.floor((durationMs ?? 0) / 1000)); + const hours = Math.floor(totalSeconds / 3600); + if (hours > 0) { + return `${hours} ${hours === 1 ? "hr" : "hrs"}`; + } + const minutes = Math.floor((totalSeconds % 3600) / 60); + if (minutes > 0) { + return `${minutes} ${minutes === 1 ? "min" : "mins"}`; + } + const seconds = totalSeconds % 60; + return `${seconds} ${seconds === 1 ? "sec" : "secs"}`; + };If you prefer the original product requirement of “1 hr” for all multi-hour videos, keep the hours branch but fix pluralization elsewhere.
410-414: Show 0s durations, fix invalid Tailwind class; consider more robust positioning
- The current guard hides 0-length videos; use a type check so 0 shows as “0 secs”.
- Tailwind doesn’t provide
leading-0; useleading-none.- Positioning via
top-[112px]is brittle across card sizes. Consider anchoring to the thumbnail container’s bottom-left instead.-{cap.metadata?.duration && ( - <p className="text-white leading-0 px-2 py-px rounded-full backdrop-blur-sm absolute z-10 left-3 top-[112px] bg-black/50 text-[10px]"> - {formatDuration(cap.metadata.duration as number)} - </p> -)} +{typeof cap.metadata?.duration === "number" && ( + <p className="text-white leading-none px-2 py-px rounded-full backdrop-blur-sm absolute z-10 left-3 top-[112px] bg-black/50 text-[10px]"> + {formatDuration(cap.metadata.duration)} + </p> +)}To robustly position over the thumbnail, move the badge inside the Link and make the Link a positioning context:
<Link className={clsx("block group relative", anyCapSelected && "cursor-pointer pointer-events-none")} ...> <VideoThumbnail ... /> {typeof cap.metadata?.duration === "number" && ( <p className="text-white leading-none px-2 py-px rounded-full backdrop-blur-sm absolute z-10 left-2 bottom-2 bg-black/50 text-[10px]"> {formatDuration(cap.metadata.duration)} </p> )} </Link>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
- GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
- GitHub Check: Analyze (rust)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx (1)
22-22: Multiple Moment.js imports detected—plan a full removalMoment.js is still imported in several components and declared in your bundle’s dependencies:
• apps/web/app/s/[videoId]/_components/ShareHeader.tsx
• apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardContent.tsx
• apps/web/app/(org)/dashboard/spaces/[spaceId]/components/VideoCard.tsx
• apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
• apps/web/app/(org)/dashboard/_components/Notifications/NotificationItem.tsxAnd in apps/web/package.json:
"moment": "^2.30.1"To safely remove Moment.js and avoid runtime errors:
- Replace each
momentusage with your lightweight formatter (e.g., a small date‐math utility ordate-fns).- Remove all
import moment from "moment";lines across the codebase.- Verify no remaining imports with:
rg -nP "import\s+moment\s+from\s+['\"]moment['\"]"- Drop
"moment"from package.json once all references are gone.Please review and confirm that all usages are migrated before removing the dependency.
This PR: You will be able to see video duration on newly uploaded videos since we added this as metadata.
Summary by CodeRabbit