Skip to content

Commit 01b0ac2

Browse files
authored
Merge pull request #6811 from FlowFuse/6803-pinia-task-1-infrastructure
[6803] Pinia Task 0 - Infrastructure
2 parents 28b9c33 + 9231c6c commit 01b0ac2

6 files changed

Lines changed: 535 additions & 214 deletions

File tree

frontend/src/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { LottieAnimation } from 'lottie-web-vue'
22

33
import { AxiosError } from 'axios'
4+
import { createPinia } from 'pinia'
5+
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
46
import { createApp } from 'vue'
57

68
import './ui-components/index.scss'
@@ -19,15 +21,21 @@ import Alerts from './services/alerts.js'
1921
import { setupSentry } from './services/error-tracking.js'
2022
import { getServiceFactory } from './services/service.factory.js'
2123
import store from './store/index.js'
24+
import { skipResetPlugin } from './stores/plugins/skip-reset.plugin.js'
2225

2326
import './index.css'
2427

2528
import ForgeUIComponents from './ui-components/index.js'
2629

2730
store.commit('initializeStore')
2831

32+
const pinia = createPinia()
33+
pinia.use(piniaPluginPersistedstate)
34+
pinia.use(skipResetPlugin)
35+
2936
const app = createApp(App)
3037
.use(ForgeUIComponents)
38+
.use(pinia)
3139
.use(store)
3240
.use(router)
3341
.use(VueShepherdPlugin)

frontend/src/store/modules/account/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getActivePinia } from 'pinia'
12
import { nextTick } from 'vue'
23

34
import flowBlueprintsApi from '../../../api/flowBlueprints.js'
@@ -504,7 +505,26 @@ const actions = {
504505
},
505506
async logout ({ rootState, dispatch, commit }) {
506507
return userApi.logout()
507-
.then(() => dispatch('$resetState', null, { root: true }))
508+
.then(() => {
509+
// Reset Vuex state (existing behaviour)
510+
dispatch('$resetState', null, { root: true })
511+
512+
// Reset migrated Pinia stores — uncomment each line as its store is migrated
513+
const pinia = getActivePinia()
514+
if (pinia) {
515+
// Task 1: useUxDialogStore().$reset()
516+
// Task 2: useUxToursStore().$reset()
517+
// Task 3: useUxNavigationStore().$reset()
518+
// Task 4: useUxDrawersStore().$reset()
519+
// Task 5: useContextStore().$reset()
520+
// Task 6: useProductTablesStore().$reset()
521+
// Task 7: useProductBrokersStore().$reset()
522+
// Task 8: useProductAssistantStore().$reset()
523+
// Task 9: useProductExpertFfAgentStore().$reset()
524+
// Task 10: useProductExpertOperatorAgentStore().$reset()
525+
// Task 11: useProductExpertStore().$reset()
526+
}
527+
})
508528
.catch(_ => {})
509529
.finally(() => {
510530
if (window._hsq) {

frontend/src/stores/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Barrel export — add store exports here as each task is merged
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function skipResetPlugin ({ store, options }) {
2+
const skipKeys = options.skipReset || []
3+
const originalReset = store.$reset?.bind(store)
4+
5+
store.$reset = () => {
6+
const preserved = {}
7+
skipKeys.forEach(key => { preserved[key] = store[key] })
8+
if (typeof originalReset === 'function') originalReset()
9+
store.$patch(preserved)
10+
}
11+
}

0 commit comments

Comments
 (0)