diff --git a/packages/flowtest-electron/src/app/watcher.js b/packages/flowtest-electron/src/app/watcher.js index 6730aea..754d75a 100644 --- a/packages/flowtest-electron/src/app/watcher.js +++ b/packages/flowtest-electron/src/app/watcher.js @@ -92,9 +92,12 @@ class Watcher { change(mainWindow, pathname, collectionId, watchPath) { console.log(`[Watcher] file ${pathname} changed`); if (this.isFlowTestFile(pathname)) { + const content = readFile(pathname); + const flowData = serialize(JSON.parse(content)); const file = { name: path.basename(pathname), - pathname: pathname, + pathname, + flowData, }; mainWindow.webContents.send('main:update-flowtest', file, collectionId); } else if (this.isEnvFile(pathname, watchPath)) { diff --git a/src/stores/CollectionStore.js b/src/stores/CollectionStore.js index 304ef5b..db1aed9 100644 --- a/src/stores/CollectionStore.js +++ b/src/stores/CollectionStore.js @@ -117,8 +117,8 @@ const useCollectionStore = create((set, get) => ({ // check if there are any open tabs, if yes mark them saved const tab = useTabStore.getState().tabs.find((t) => t.id === existingEnv.id); - if (tab && tab.variablesDraft) { - tab.variables = cloneDeep(tab.variablesDraft); + if (tab) { + tab.variables = cloneDeep(file.variables); tab.variablesDraft = null; } } else { @@ -286,9 +286,9 @@ const useCollectionStore = create((set, get) => ({ // console.log(`Collection updated: ${JSON.stringify(collection)}`); // check if there are any open tabs, if yes mark them saved - const tab = useTabStore.getState().tabs.find((t) => t.id === item.id); - if (tab && tab.flowDataDraft) { - useTabStore.getState().saveFlowTestTab(tab); + const existingTab = useTabStore.getState().tabs.find((t) => t.id === item.id); + if (existingTab) { + useTabStore.getState().saveFlowTestTab(existingTab, cloneDeep(file.flowData)); } } } diff --git a/src/stores/TabStore.js b/src/stores/TabStore.js index ba68b0b..243c98d 100644 --- a/src/stores/TabStore.js +++ b/src/stores/TabStore.js @@ -33,7 +33,7 @@ export const useTabStore = create((set, get) => ({ set((state) => ({ tabs: [...state.tabs, newTab] })); set(() => ({ focusTabId: newTab.id })); }, - saveFlowTestTab: (tab) => { + saveFlowTestTab: (tab, updatedFlowData) => { set( produce((state) => { const existingTab = state.tabs.find( @@ -45,7 +45,7 @@ export const useTabStore = create((set, get) => ({ tab.type === OBJ_TYPES.flowtest, ); if (existingTab) { - existingTab.flowData = cloneDeep(existingTab.flowDataDraft); + existingTab.flowData = updatedFlowData; existingTab.flowDataDraft = null; } }),