added local storage of flow state to fake chat memory for refresh page
This commit is contained in:
parent
37d48faf16
commit
2fb72b1d1e
2 changed files with 16 additions and 1 deletions
|
|
@ -40,6 +40,7 @@ export default function newChatView(): JSX.Element {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const chatOutputResponses: FlowPoolObjectType[] = [];
|
const chatOutputResponses: FlowPoolObjectType[] = [];
|
||||||
outputIds.forEach((outputId) => {
|
outputIds.forEach((outputId) => {
|
||||||
|
console.log("rodou", flowPool[outputId]);
|
||||||
if (outputId.includes("ChatOutput")) {
|
if (outputId.includes("ChatOutput")) {
|
||||||
if (flowPool[outputId] && flowPool[outputId].length > 0) {
|
if (flowPool[outputId] && flowPool[outputId].length > 0) {
|
||||||
chatOutputResponses.push(...flowPool[outputId]);
|
chatOutputResponses.push(...flowPool[outputId]);
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,19 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
set({ flowPool });
|
set({ flowPool });
|
||||||
},
|
},
|
||||||
addDataToFlowPool: (data: any, nodeId: string) => {
|
addDataToFlowPool: (data: any, nodeId: string) => {
|
||||||
|
const currentFlow = useFlowsManagerStore.getState().currentFlow;
|
||||||
let newFlowPool = cloneDeep({ ...get().flowPool });
|
let newFlowPool = cloneDeep({ ...get().flowPool });
|
||||||
if (!newFlowPool[nodeId]) newFlowPool[nodeId] = [data];
|
if (!newFlowPool[nodeId]) newFlowPool[nodeId] = [data];
|
||||||
else {
|
else {
|
||||||
newFlowPool[nodeId].push(data);
|
newFlowPool[nodeId].push(data);
|
||||||
}
|
}
|
||||||
get().setFlowPool(newFlowPool);
|
get().setFlowPool(newFlowPool);
|
||||||
|
if (currentFlow) {
|
||||||
|
window.sessionStorage.setItem(
|
||||||
|
`${currentFlow!.id}`,
|
||||||
|
JSON.stringify(newFlowPool)
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CleanFlowPool: () => {
|
CleanFlowPool: () => {
|
||||||
get().setFlowPool({});
|
get().setFlowPool({});
|
||||||
|
|
@ -59,9 +66,15 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
set({ isPending });
|
set({ isPending });
|
||||||
},
|
},
|
||||||
resetFlow: ({ nodes, edges, viewport }) => {
|
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);
|
let newEdges = cleanEdges(nodes, edges);
|
||||||
const { inputs, outputs } = getInputsAndOutputs(nodes);
|
const { inputs, outputs } = getInputsAndOutputs(nodes);
|
||||||
|
|
||||||
set({
|
set({
|
||||||
nodes,
|
nodes,
|
||||||
edges: newEdges,
|
edges: newEdges,
|
||||||
|
|
@ -69,6 +82,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
inputs,
|
inputs,
|
||||||
outputs,
|
outputs,
|
||||||
hasIO: inputs.length > 0 && outputs.length > 0,
|
hasIO: inputs.length > 0 && outputs.length > 0,
|
||||||
|
flowPool,
|
||||||
});
|
});
|
||||||
get().reactFlowInstance!.setViewport(viewport);
|
get().reactFlowInstance!.setViewport(viewport);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue