Skip to content

Commit

Permalink
fix(ClientDB): drop LocalStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Oct 7, 2022
1 parent c76c5a7 commit 7afd857
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/runtime/composables/client-db.ts
@@ -1,6 +1,6 @@
import type { Storage } from 'unstorage'
// @ts-ignore
import LSDriver from 'unstorage/drivers/localstorage'
import memoryDriver from 'unstorage/drivers/memory'
import { createStorage, prefixStorage } from 'unstorage'
import { useRuntimeConfig, useCookie } from '#app'
import { withBase } from 'ufo'
Expand All @@ -11,7 +11,7 @@ import { createNav } from '../server/navigation'

const withContentBase = url => withBase(url, '/api/' + useRuntimeConfig().public.content.base)

export const contentStorage = prefixStorage(createStorage({ driver: LSDriver() }), '@content')
export const contentStorage = prefixStorage(createStorage({ driver: memoryDriver() }), '@content')

export const getPreview = () => {
return useCookie('previewToken').value
Expand Down
15 changes: 6 additions & 9 deletions src/runtime/preview/preview-plugin.ts
@@ -1,4 +1,5 @@
import { createApp } from 'vue'
import { contentStorage } from '../composables/client-db'
import { defineNuxtPlugin, useRoute, useCookie, refreshNuxtData, useRuntimeConfig } from '#imports'
import { ContentPreviewMode } from '#components'

Expand All @@ -14,12 +15,8 @@ export default defineNuxtPlugin((nuxt) => {
}
})
// Remove previous preview data
Object.keys(window.localStorage)
.forEach((key) => {
if (key.startsWith(`@content:${token}:`)) {
window.localStorage.removeItem(key)
}
})
const keys = await contentStorage.getKeys(`${token}:`)
keys.forEach(key => contentStorage.removeItem(key))

// Fill store with preview content
const items = [
Expand All @@ -29,15 +26,15 @@ export default defineNuxtPlugin((nuxt) => {
]

// Set preview meta
window.localStorage.setItem(
`@content:${token}$`,
await contentStorage.setItem(
`${token}$`,
JSON.stringify({
ignoreBuiltContents: (data.files || []).length !== 0
})
)

for (const item of items) {
window.localStorage.setItem(`@content:${token}:${item.parsed._id}`, JSON.stringify(item.parsed))
await contentStorage.setItem(`${token}:${item.parsed._id}`, JSON.stringify(item.parsed))
}
}

Expand Down

0 comments on commit 7afd857

Please sign in to comment.