Skip to content

Commit 189401d

Browse files
Merge pull request #123 from SingularityNET-Archive:development
feat: Add useCallback to handleVideoDataUpdate in SummaryMeetingInfo
2 parents 92757b4 + 0450edb commit 189401d

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

components/SummaryMeetingInfo.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react';
1+
import { useState, useEffect, useCallback } from 'react';
22
import styles from '../styles/typea.module.css';
33
import { useMyVariable } from '../context/MyVariableContext';
44
import SelectNames from './SelectNames';
@@ -154,7 +154,7 @@ const SummaryMeetingInfo: React.FC<SummaryMeetingInfoProps> = ({ workgroup, onUp
154154
});
155155
}, [myVariable.summary?.meetingInfo]); // Add myVariable.summary.meetingInfo to the dependency array
156156

157-
const handleVideoDataUpdate = (newVideoData: any) => {
157+
const handleVideoDataUpdate = useCallback((newVideoData: any) => {
158158
setMeetingInfo(prevMeetingInfo => {
159159
if (JSON.stringify(prevMeetingInfo.timestampedVideo) === JSON.stringify(newVideoData)) {
160160
return prevMeetingInfo;
@@ -164,7 +164,7 @@ const SummaryMeetingInfo: React.FC<SummaryMeetingInfoProps> = ({ workgroup, onUp
164164
timestampedVideo: newVideoData,
165165
};
166166
});
167-
};
167+
}, []);
168168

169169
return (
170170
<>

components/SummaryTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const SummaryTemplate = ({ updateMeetings }: SummaryTemplateProps) => {
8989
transcriptLink: "",
9090
mediaLink: "",
9191
workingDocs: [{ title: "", link: "" }],
92-
timestampedVideo: { url: "", intro: "", timestamps: [{ title: "", timestamp: "" }] }
92+
timestampedVideo: { url: "", intro: "", timestamps: "" }
9393
},
9494
agendaItems: [
9595
{

components/TimestampedVideo.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,26 @@ const TimestampedVideo: React.FC<TimestampedVideoProps> = ({ onUpdate, initialDa
1717
timestamps: initialData?.timestamps || '',
1818
});
1919

20+
useEffect(() => {
21+
// Update videoData when initialData changes
22+
setVideoData({
23+
url: initialData?.url || '',
24+
intro: initialData?.intro || '',
25+
timestamps: initialData?.timestamps || '',
26+
});
27+
}, [initialData]);
28+
2029
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
2130
const { name, value } = e.target;
22-
setVideoData({ ...videoData, [name]: value });
31+
setVideoData((prevVideoData: any) => {
32+
const updatedVideoData = { ...prevVideoData, [name]: value };
33+
if (prevVideoData[name] !== value) {
34+
setTimeout(() => onUpdate(updatedVideoData), 0); // Delay the onUpdate call
35+
}
36+
return updatedVideoData;
37+
});
2338
};
2439

25-
useEffect(() => {
26-
onUpdate(videoData); // Call onUpdate with the current state of videoData
27-
}, [videoData, onUpdate]); // Add videoData and onUpdate to the dependency array
28-
2940
return (
3041
<div className={styles.container}>
3142
<div className={styles.field}>

0 commit comments

Comments
 (0)