From 1fdeafa7e9a1b7eadd9a33a1cf40a11f476549e2 Mon Sep 17 00:00:00 2001 From: Embbnux Ji Date: Mon, 6 Jan 2025 14:43:51 +0800 Subject: [PATCH] fix: smart note re-render (#957) --- src/components/SideDrawerView/index.tsx | 12 +++++++++++- src/modules/SmartNotes/index.ts | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/SideDrawerView/index.tsx b/src/components/SideDrawerView/index.tsx index ff2ad66d..d0a2b550 100644 --- a/src/components/SideDrawerView/index.tsx +++ b/src/components/SideDrawerView/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { RcDrawer, styled } from '@ringcentral/juno'; import { SmartNoteApp } from './SmartNoteApp'; @@ -21,7 +21,17 @@ export function SideDrawerView({ onSmartNoteSave, }) { const [session, setSession] = useState(null); + const sessionRef = useRef(session); useEffect(() => { + if ( + sessionRef.current && + smartNoteSession && + sessionRef.current.id === smartNoteSession.id + ) { + // avoid re-render when session is the same + return; + } + sessionRef.current = smartNoteSession; setSession(null); const timeout = setTimeout(() => { setSession(smartNoteSession); diff --git a/src/modules/SmartNotes/index.ts b/src/modules/SmartNotes/index.ts index 7130847a..6e76e2b8 100644 --- a/src/modules/SmartNotes/index.ts +++ b/src/modules/SmartNotes/index.ts @@ -280,6 +280,14 @@ export class SmartNotes extends RcModuleV2 { if (!smartNoteClient) { return; } + if ( + this.session && + this.session.id === session.id && + this.session.status === 'Disconnected' + ) { + // avoid duplicated call + return; + } if (smartNoteClient.transcriptions.length > 1) { this.addRecentNotedCall(session.id); }