From 6724b200359caa47cefcacdba9ad5f0ef17b8861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fred=20Lef=C3=A9v=C3=A8re-Laoide?= <90181748+FredLL-Avaiga@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:41:38 +0200 Subject: [PATCH] refresh when the list of messages is emptied (#1651) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolves #1618 Co-authored-by: Fred Lefévère-Laoide --- .../taipy-gui/src/components/Taipy/Chat.tsx | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/taipy-gui/src/components/Taipy/Chat.tsx b/frontend/taipy-gui/src/components/Taipy/Chat.tsx index 139d446ca0..e4ec2dfa48 100644 --- a/frontend/taipy-gui/src/components/Taipy/Chat.tsx +++ b/frontend/taipy-gui/src/components/Taipy/Chat.tsx @@ -35,7 +35,7 @@ import { TaipyActiveProps, disableColor, getSuffixedClassNames } from "./utils"; import { useClassNames, useDispatch, useDynamicProperty, useElementVisible, useModule } from "../../utils/hooks"; import { LoVElt, useLovListMemo } from "./lovUtils"; import { IconAvatar, avatarSx } from "../../utils/icon"; -import { getInitials } from "../../utils"; +import { emptyArray, getInitials } from "../../utils"; import { RowType, TableValueType } from "./tableUtils"; interface ChatProps extends TaipyActiveProps { @@ -290,20 +290,24 @@ const Chat = (props: ChatProps) => { useEffect(() => { if (!refresh && props.messages && page.current.key && props.messages[page.current.key] !== undefined) { const newValue = props.messages[page.current.key]; - const nr = newValue.data as RowType[]; - if (Array.isArray(nr) && nr.length > newValue.start && nr[newValue.start]) { - setRows((old) => { - old.length && nr.length > old.length && setShowMessage(true); - if (nr.length < old.length) { - return nr.concat(old.slice(nr.length)) - } - if (old.length > newValue.start) { - return old.slice(0, newValue.start).concat(nr.slice(newValue.start)); - } - return nr; - }); - const cols = Object.keys(nr[newValue.start]); - setColumns(cols.length > 2 ? cols : cols.length == 2 ? [...cols, ""] : ["", ...cols, "", ""]); + if (newValue.rowcount == 0) { + setRows(emptyArray) + } else { + const nr = newValue.data as RowType[]; + if (Array.isArray(nr) && nr.length > newValue.start && nr[newValue.start]) { + setRows((old) => { + old.length && nr.length > old.length && setShowMessage(true); + if (nr.length < old.length) { + return nr.concat(old.slice(nr.length)) + } + if (old.length > newValue.start) { + return old.slice(0, newValue.start).concat(nr.slice(newValue.start)); + } + return nr; + }); + const cols = Object.keys(nr[newValue.start]); + setColumns(cols.length > 2 ? cols : cols.length == 2 ? [...cols, ""] : ["", ...cols, "", ""]); + } } page.current.key = getChatKey(0, pageSize); }