Skip to content

Commit

Permalink
feat(useRoadizPreview()): use init function
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelodelain committed Mar 14, 2024
1 parent ff02433 commit 0cfbb18
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions composables/use-roadiz-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ interface UsePreviewState {
interface UsePreviewOptions extends UsePreviewState {}

export function useRoadizPreview(options?: UsePreviewOptions) {
const state = useState<UsePreviewState>('preview', () => ({
isActive: false,
token: undefined as string | undefined,
}))
const state = useState<UsePreviewState>('preview', () => {
const route = useRoute()
const token = typeof route.query?.token === 'string' ? route.query.token : undefined
const isActive = !!token && route.query?._preview === '1'

return { token, isActive }
})

const isActive = computed({
get() {
Expand Down

0 comments on commit 0cfbb18

Please sign in to comment.