export async function actionGlobalPasteState(pinia: Pinia) {
if (checkClipboardAccess()) return
try {
- Object.assign(
- pinia.state.value,
- JSON.parse(await navigator.clipboard.readText())
- )
+ loadStoresState(pinia, JSON.parse(await navigator.clipboard.readText()))
toastMessage('Global state pasted from clipboard.')
} catch (error) {
if (checkNotFocusedError(error)) return
const result = await open()
if (!result) return
const { text, file } = result
- Object.assign(pinia.state.value, JSON.parse(text))
+ loadStoresState(pinia, JSON.parse(text))
toastMessage(`Global state imported from "${file.name}".`)
} catch (error) {
toastMessage(
console.error(error)
}
}
+
+function loadStoresState(pinia: Pinia, state: Record<string, unknown>) {
+ for (const key in state) {
+ const storeState = pinia.state.value[key]
+ if (storeState) {
+ Object.assign(storeState, state[key])
+ }
+ }
+}