Skip to content

Commit 09bd76e

Browse files
committed
Clear selected apps and selected functions
1 parent de86965 commit 09bd76e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

frontend/src/lib/store/agent.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ export const useAgentStore = create<AgentState>()(
175175
},
176176
initializeFromProject: (project: Project) => {
177177
if (project?.agents && project.agents.length > 0) {
178-
// After the selected agent's loaded from session storage,
179-
// we need to check if the selected agent is still in the project.
180-
// If not, we need to set the default agent to the first agent in the project.
181178
const currentSelectedAgent = get().selectedAgent;
182179
let selectedAgent = currentSelectedAgent;
183180

@@ -195,6 +192,13 @@ export const useAgentStore = create<AgentState>()(
195192
project.agents.find((agent) => agent.id === selectedAgent)
196193
?.allowed_apps || [],
197194
currentProjectId: project.id,
195+
// Clear these when switching projects
196+
apps: [],
197+
appFunctions: [],
198+
linkedAccounts: [],
199+
selectedApps: [],
200+
selectedFunctions: [],
201+
selectedLinkedAccountOwnerId: "",
198202
}));
199203
}
200204
},
@@ -229,11 +233,17 @@ export const useAgentStore = create<AgentState>()(
229233
}),
230234
onRehydrateStorage: () => (state) => {
231235
// Clear state if project ID doesn't match
232-
if (state && state.currentProjectId !== state.currentProjectId) {
236+
if (
237+
state &&
238+
state.currentProjectId !== window.location.pathname.split("/")[2]
239+
) {
233240
state.selectedApps = [];
234241
state.selectedFunctions = [];
235242
state.selectedLinkedAccountOwnerId = "";
236243
state.selectedAgent = "";
244+
state.apps = [];
245+
state.appFunctions = [];
246+
state.linkedAccounts = [];
237247
}
238248
},
239249
},

0 commit comments

Comments
 (0)