added local storage of flow state to fake chat memory for refresh page

This commit is contained in:
anovazzi1 2024-01-29 14:46:38 -03:00
commit 2fb72b1d1e
2 changed files with 16 additions and 1 deletions

View file

@ -40,6 +40,7 @@ export default function newChatView(): JSX.Element {
useEffect(() => {
const chatOutputResponses: FlowPoolObjectType[] = [];
outputIds.forEach((outputId) => {
console.log("rodou", flowPool[outputId]);
if (outputId.includes("ChatOutput")) {
if (flowPool[outputId] && flowPool[outputId].length > 0) {
chatOutputResponses.push(...flowPool[outputId]);

View file

@ -45,12 +45,19 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
set({ flowPool });
},
addDataToFlowPool: (data: any, nodeId: string) => {
const currentFlow = useFlowsManagerStore.getState().currentFlow;
let newFlowPool = cloneDeep({ ...get().flowPool });
if (!newFlowPool[nodeId]) newFlowPool[nodeId] = [data];
else {
newFlowPool[nodeId].push(data);
}
get().setFlowPool(newFlowPool);
if (currentFlow) {
window.sessionStorage.setItem(
`${currentFlow!.id}`,
JSON.stringify(newFlowPool)
);
}
},
CleanFlowPool: () => {
get().setFlowPool({});
@ -59,9 +66,15 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
set({ isPending });
},
resetFlow: ({ nodes, edges, viewport }) => {
const currentFlow = useFlowsManagerStore.getState().currentFlow;
let flowPool = {};
if (currentFlow) {
flowPool = JSON.parse(
window.sessionStorage.getItem(`${currentFlow!.id}`) ?? "{}"
);
}
let newEdges = cleanEdges(nodes, edges);
const { inputs, outputs } = getInputsAndOutputs(nodes);
set({
nodes,
edges: newEdges,
@ -69,6 +82,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
inputs,
outputs,
hasIO: inputs.length > 0 && outputs.length > 0,
flowPool,
});
get().reactFlowInstance!.setViewport(viewport);
},