Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix update folder items
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Aug 1, 2023
1 parent 8fcb431 commit 9dafd9e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
25 changes: 23 additions & 2 deletions .ui-dev/src/components/Chatbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ const Chatbar: React.FC<IChatbarProps> = ({
const list = [...items];

if (currentFolder) {
currentFolder.conversations.push(newConversation);
[...list].forEach((item, itemIndex) => {
if ('conversations' in item && item.id === currentFolder.id) {
list[itemIndex] = {
...item,

conversations: [...currentFolder.conversations, newConversation]
};
}
});
} else {
list.push(newConversation);
}
Expand Down Expand Up @@ -157,11 +165,24 @@ const Chatbar: React.FC<IChatbarProps> = ({
}, [handleItemsUpdate, items, onConversationDelete]);

const handleUpdateConversation = useCallback((newData: IChatConversation) => {
const folder = folders.find((f) => {
let folder = folders.find((f) => {
return f.id === newData.folderId;
});

const newList = [...items];
if (folder) {
folder = {
...folder,

conversations: [...folder.conversations]
};

[...newList].forEach((item, itemIndex) => {
if ('conversations' in item && item.id === folder!.id) {
newList[itemIndex] = folder!;
}
});
}

const list = folder ? folder.conversations : newList;
[...list].forEach((item, itemIndex) => {
Expand Down
25 changes: 23 additions & 2 deletions .ui-dev/src/components/Promptbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,15 @@ const Promptbar: React.FC<IPromptbarProps> = ({
const list = [...items];

if (currentFolder) {
currentFolder.prompts.push(newPrompt);
[...list].forEach((item, itemIndex) => {
if ('prompts' in item && item.id === currentFolder.id) {
list[itemIndex] = {
...item,

prompts: [...currentFolder.prompts, newPrompt]
};
}
});
} else {
list.push(newPrompt);
}
Expand All @@ -108,11 +116,24 @@ const Promptbar: React.FC<IPromptbarProps> = ({
}, []);

const handleUpdatePrompt = useCallback((newData: IChatPrompt) => {
const folder = folders.find((f) => {
let folder = folders.find((f) => {
return f.id === newData.folderId;
});

const newList = [...items];
if (folder) {
folder = {
...folder,

prompts: [...folder.prompts]
};

[...newList].forEach((item, itemIndex) => {
if ('prompts' in item && item.id === folder!.id) {
newList[itemIndex] = folder!;
}
});
}

const list = folder ? folder.prompts : newList;
[...list].forEach((item, itemIndex) => {
Expand Down

0 comments on commit 9dafd9e

Please sign in to comment.