Skip to content

Commit

Permalink
feat(assets): options storage (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
arashsheyda committed Aug 9, 2023
1 parent 8d34de1 commit 75512f8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/devtools-kit/src/_types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,7 @@ export interface NuxtDevToolsOptions {
view: 'tree' | 'list'
inputDefaults: Record<string, ServerRouteInput[]>
}
assets: {
view: 'grid' | 'list'
}
}
19 changes: 14 additions & 5 deletions packages/devtools/client/composables/storage-options.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { toRefs, watchDebounced } from '@vueuse/core'

// Assets
const assetsOptions = ref(await rpc.getOptions('assets'))
const assets = toRefs(assetsOptions)

watchDebounced(assetsOptions, async (options) => {
rpc.updateOptions('assets', options)
}, { deep: true, flush: 'post', debounce: 500, maxWait: 1000 })

// Server Routes
const serverRouteOptions = ref(await rpc.getOptions('serverRoutes'))
const serverRoutes = toRefs(serverRouteOptions)

watchDebounced(serverRouteOptions, async (options) => {
rpc.updateOptions('serverRoutes', options)
}, { deep: true, flush: 'post', debounce: 500, maxWait: 1000 })

// Options List
const list = {
serverRoutes,
assets,
}

export function useDevToolsOptions<T extends keyof typeof list>(tab: T) {
return list[tab]
}

// Server Routes
watchDebounced(serverRouteOptions, async (options) => {
rpc.updateOptions('serverRoutes', options)
}, { deep: true, flush: 'post', debounce: 500, maxWait: 1000 })
2 changes: 1 addition & 1 deletion packages/devtools/client/pages/modules/assets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const byTree = computed(() => {
const selected = ref<AssetInfo>()
const view = ref<'list' | 'grid'>('grid')
const { view } = useDevToolsOptions('assets')
function toggleView() {
view.value = view.value === 'list' ? 'grid' : 'list'
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ export const defaultTabOptions: NuxtDevToolsOptions = {
headers: [],
},
},
assets: {
view: 'grid',
},
}

0 comments on commit 75512f8

Please sign in to comment.