Initial Collection State System implementation
Co-authored-by: Liyas Thomas <hi@liyasthomas.com>
This commit is contained in:
@@ -8,6 +8,12 @@ import {
|
||||
setRESTHistoryEntries,
|
||||
setGraphqlHistoryEntries,
|
||||
} from "./history"
|
||||
import {
|
||||
restCollectionStore,
|
||||
graphqlCollectionStore,
|
||||
setGraphqlCollections,
|
||||
setRESTCollections,
|
||||
} from "./collections"
|
||||
|
||||
function checkAndMigrateOldSettings() {
|
||||
const vuexData = JSON.parse(window.localStorage.getItem("vuex") || "{}")
|
||||
@@ -22,6 +28,22 @@ function checkAndMigrateOldSettings() {
|
||||
delete vuexData.postwoman.settings
|
||||
window.localStorage.setItem("vuex", JSON.stringify(vuexData))
|
||||
}
|
||||
|
||||
if (vuexData.postwoman && vuexData.postwoman.collections) {
|
||||
const restColls = vuexData.postwoman.collections
|
||||
window.localStorage.setItem("collections", JSON.stringify(restColls))
|
||||
|
||||
delete vuexData.postwoman.collections
|
||||
window.localStorage.setItem("vuex", JSON.stringify(vuexData))
|
||||
}
|
||||
|
||||
if (vuexData.postwoman && vuexData.postwoman.collectionsGraphql) {
|
||||
const gqlColls = vuexData.postwoman.collectionsGraphql
|
||||
window.localStorage.setItem("collectionsGraphql", JSON.stringify(gqlColls))
|
||||
|
||||
delete vuexData.postwoman.collectionsGraphql
|
||||
window.localStorage.setItem("vuex", JSON.stringify(vuexData))
|
||||
}
|
||||
}
|
||||
|
||||
function setupSettingsPersistence() {
|
||||
@@ -59,9 +81,31 @@ function setupHistoryPersistence() {
|
||||
})
|
||||
}
|
||||
|
||||
function setupCollectionsPersistence() {
|
||||
const restCollectionData = JSON.parse(
|
||||
window.localStorage.getItem("collections") || "[]"
|
||||
)
|
||||
|
||||
const graphqlCollectionData = JSON.parse(
|
||||
window.localStorage.getItem("collectionsGraphql") || "[]"
|
||||
)
|
||||
|
||||
setRESTCollections(restCollectionData)
|
||||
setGraphqlCollections(graphqlCollectionData)
|
||||
|
||||
restCollectionStore.subject$.subscribe(({ state }) => {
|
||||
window.localStorage.setItem("collections", JSON.stringify(state))
|
||||
})
|
||||
|
||||
graphqlCollectionStore.subject$.subscribe(({ state }) => {
|
||||
window.localStorage.setItem("collectionsGraphql", JSON.stringify(state))
|
||||
})
|
||||
}
|
||||
|
||||
export function setupLocalPersistence() {
|
||||
checkAndMigrateOldSettings()
|
||||
|
||||
setupSettingsPersistence()
|
||||
setupHistoryPersistence()
|
||||
setupCollectionsPersistence()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user