Initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import type { CommentWithReplies } from "@/types";
|
||||
|
||||
export function useFrameComments(comments: CommentWithReplies[], frameNumber: number) {
|
||||
const frameComments = useMemo(
|
||||
() => comments.filter((c) => c.frameNumber === frameNumber),
|
||||
[comments, frameNumber]
|
||||
);
|
||||
|
||||
const nearbyComments = useMemo(
|
||||
() => comments.filter((c) => Math.abs(c.frameNumber - frameNumber) <= 3 && c.frameNumber !== frameNumber),
|
||||
[comments, frameNumber]
|
||||
);
|
||||
|
||||
const unresolvedCount = useMemo(
|
||||
() => comments.filter((c) => !c.isResolved).length,
|
||||
[comments]
|
||||
);
|
||||
|
||||
const commentsByFrame = useMemo(() => {
|
||||
const map = new Map<number, CommentWithReplies[]>();
|
||||
comments.forEach((c) => {
|
||||
const existing = map.get(c.frameNumber) ?? [];
|
||||
map.set(c.frameNumber, [...existing, c]);
|
||||
});
|
||||
return map;
|
||||
}, [comments]);
|
||||
|
||||
const hasCommentAtFrame = (frame: number) => commentsByFrame.has(frame);
|
||||
|
||||
const getCommentsAtFrame = (frame: number) =>
|
||||
commentsByFrame.get(frame) ?? [];
|
||||
|
||||
return {
|
||||
frameComments,
|
||||
nearbyComments,
|
||||
unresolvedCount,
|
||||
commentsByFrame,
|
||||
hasCommentAtFrame,
|
||||
getCommentsAtFrame,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user