Skip to content

Commit 4e11eab

Browse files
authored
new: add video duration to cards (#902)
* add video duration * cleanup
1 parent 26eba96 commit 4e11eab

File tree

1 file changed

+23
-0
lines changed
  • apps/web/app/(org)/dashboard/caps/components/CapCard

1 file changed

+23
-0
lines changed

apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2020
import { useMutation } from "@tanstack/react-query";
2121
import clsx from "clsx";
22+
import moment from "moment";
2223
import Link from "next/link";
2324
import { useRouter } from "next/navigation";
2425
import { type PropsWithChildren, useState } from "react";
@@ -104,6 +105,23 @@ export const CapCard = ({
104105

105106
const router = useRouter();
106107

108+
const formatDuration = (duration: string) => {
109+
if (!duration) return "0 secs";
110+
111+
const momentDuration = moment.duration(duration, "milliseconds");
112+
const totalMinutes = Math.floor(momentDuration.asMinutes());
113+
const totalHours = Math.floor(momentDuration.asHours());
114+
const seconds = momentDuration.seconds();
115+
116+
if (totalHours > 0) {
117+
return "1 hr";
118+
} else if (totalMinutes > 0) {
119+
return `${totalMinutes} mins`;
120+
} else {
121+
return `${seconds} secs`;
122+
}
123+
};
124+
107125
const downloadMutation = useMutation({
108126
mutationFn: async () => {
109127
const response = await downloadVideo(cap.id);
@@ -389,6 +407,11 @@ export const CapCard = ({
389407
/>
390408
</div>
391409
)}
410+
{cap.metadata?.duration && (
411+
<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]">
412+
{formatDuration(cap.metadata.duration as string)}
413+
</p>
414+
)}
392415
{!sharedCapCard && onSelectToggle && (
393416
<div
394417
className={clsx(

0 commit comments

Comments
 (0)