MCPcopy Create free account
hub / github.com/code100x/cms / TimeCodeComment

Function TimeCodeComment

src/components/comment/TimeCodeComment.tsx:13–107  ·  view source on GitHub ↗
({
  comment,
  possiblePath,
  searchParams,
  contentId,
})

Source from the content-addressed store, hash-verified

11};
12
13const TimeCodeComment: React.FC<TimeCodeCommentProps> = ({
14 comment,
15 possiblePath,
16 searchParams,
17 contentId,
18}) => {
19 const timeCodeRegex = /(?:(\d{1,2}):)?(\d{1,2}):(\d{1,2})/g;
20 const urlRegex = /((https)?:\/\/[^\s]+)/g;
21
22 const convertToSeconds = (timeCode: string): number => {
23 const parts = timeCode.split(':').reverse().map(Number);
24 return (parts || []).reduce(
25 (acc, part, index) => acc + part * Math.pow(60, index),
26 0,
27 );
28 };
29
30 const processLine = (line: string) => {
31 const elements = [];
32 let lastIndex = 0;
33 let match;
34
35 while ((match = timeCodeRegex.exec(line)) !== null) {
36 if (match.index > lastIndex) {
37 elements.push(
38 <span key={`text-${lastIndex}`}>
39 {line.substring(lastIndex, match.index)}
40 </span>,
41 );
42 }
43
44 const timeInSeconds = convertToSeconds(match[0]);
45 elements.push(
46 <Link
47 key={`timecode-${match.index}`}
48 className="text-blue-500 hover:underline"
49 href={getUpdatedUrl(
50 `/courses/${contentId}/${possiblePath}`,
51 searchParams,
52 {
53 timestamp: timeInSeconds,
54 },
55 )}
56 >
57 {match[0]}
58 </Link>,
59 );
60
61 lastIndex = match.index + match[0].length;
62 }
63
64 while ((match = urlRegex.exec(line)) !== null) {
65 if (match.index > lastIndex) {
66 elements.push(
67 <span key={`text-${lastIndex}`}>
68 {line.substring(lastIndex, match.index)}
69 </span>,
70 );

Callers

nothing calls this directly

Calls 1

processLineFunction · 0.85

Tested by

no test coverage detected