import React, { useContext, useState, useEffect } from "react"; import { IVod } from "@/app/lib/vods"; import { ITimestamp, deleteTimestamp } from "@/app/lib/timestamps"; import { formatTimestamp, formatUrlTimestamp, } from "@/app/lib/dates"; import Link from 'next/link'; import { faClock, faLink, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { isWithinInterval, subHours, Interval } from 'date-fns'; import { useRouter } from 'next/navigation'; export interface ITimestampsProps { vod: IVod; timestamps: ITimestamp[]; setTimestamps: Function; } function isCreatedByMeRecently(authData: any, ts: ITimestamp) { if (!authData?.user) return false; if (authData.user.id !== ts.creator_id) return false; const last24H: Interval = { start: subHours(new Date(), 24), end: new Date() }; return isWithinInterval(new Date(ts.created_at), last24H); } export function TimestampsList({ vod, timestamps, setTimestamps }: ITimestampsProps): React.JSX.Element { // const throttledTimestampFetch = throttle(getRawTimestampsForVod); const hasTimestamps = timestamps.length > 0; return (
{hasTimestamps && ( timestamps.map((ts: ITimestamp) => (

{JSON.stringify(ts, null, 2)}


{formatTimestamp(ts.time)} {' '} {/* {ts.tag.name} */} {isCreatedByMeRecently({}, ts) && ( )}

)) )} {!hasTimestamps &&

This VOD has no timestamps

}
); }