Skip to content

Commit

Permalink
refresh when the list of messages is emptied (#1651)
Browse files Browse the repository at this point in the history
resolves #1618

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Aug 8, 2024
1 parent 2555495 commit 6724b20
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions frontend/taipy-gui/src/components/Taipy/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6724b20

Please sign in to comment.