From 9b44534f5c3b4bff560860cf3d0f9c44de876ae3 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 26 Dec 2023 01:31:34 +0100 Subject: [PATCH] refactor: persist store to localstorage (#70) Add pinia plugin to persist store to localStorage --- package.json | 1 + src/main.js | 3 +++ src/store.js | 4 ++++ yarn.lock | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/package.json b/package.json index 46494d465ed..672da40d65f 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "html5-qrcode": "^2.3.8", "leaflet": "^1.9.4", "pinia": "^2.1.7", + "pinia-plugin-persistedstate": "^3.2.1", "universal-cookie": "^6.1.1", "vue": "^3.3.9", "vue-router": "^4.2.5", diff --git a/src/main.js b/src/main.js index 1c0ea131380..05ff9eaf393 100644 --- a/src/main.js +++ b/src/main.js @@ -1,12 +1,15 @@ import { createApp } from 'vue' import { createPinia } from 'pinia' +import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' import './assets/main.css' import App from './App.vue' import router from './router.js' import { vuetify } from './plugins/vuetify.js' const app = createApp(App) + const pinia = createPinia() +pinia.use(piniaPluginPersistedstate) app.use(pinia) app.use(router) diff --git a/src/store.js b/src/store.js index 9657616a280..ab8948fd70d 100644 --- a/src/store.js +++ b/src/store.js @@ -17,5 +17,9 @@ export const useAppStore = defineStore('app', { this.user.username = null this.user.token = null } + }, + // pinia-plugin-persistedstate + persist: { + storage: localStorage } }) diff --git a/yarn.lock b/yarn.lock index f08b0c648a0..35a735c7550 100644 --- a/yarn.lock +++ b/yarn.lock @@ -551,6 +551,11 @@ picocolors@^1.0.0: resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== +pinia-plugin-persistedstate@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/pinia-plugin-persistedstate/-/pinia-plugin-persistedstate-3.2.1.tgz#66780602aecd6c7b152dd7e3ddc249a1f7a13fe5" + integrity sha512-MK++8LRUsGF7r45PjBFES82ISnPzyO6IZx3CH5vyPseFLZCk1g2kgx6l/nW8pEBKxxd4do0P6bJw+mUSZIEZUQ== + pinia@^2.1.7: version "2.1.7" resolved "https://registry.yarnpkg.com/pinia/-/pinia-2.1.7.tgz#4cf5420d9324ca00b7b4984d3fbf693222115bbc"