-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (admin-ui) re-implement admin ui plugin
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Context, Plugin } from '@nuxt/types' | ||
import { createCookies } from '@vueuse/integrations' | ||
import defu from 'defu' | ||
import Vue from 'vue' | ||
import { reactive, watch } from 'vue-demi' | ||
import { DocusRuntimeInstance } from '../../index.d' | ||
import DocusUI from './DocusUI.vue' | ||
|
||
const COOKIE_NAME = 'docus.ui' | ||
|
||
export default <Plugin>async function ({ ssrContext, $docus }: Context & { $docus: DocusRuntimeInstance }) { | ||
const useUniversalCookies = createCookies(ssrContext?.req) | ||
const cookies = useUniversalCookies() | ||
const ui = cookies.get(COOKIE_NAME) || {} | ||
|
||
// UI data (universal storage) | ||
$docus.ui = reactive( | ||
defu(ui, { | ||
slots: false, | ||
draft: false | ||
}) | ||
) | ||
|
||
if (process.client) { | ||
// Watch drafts, refresh data once updated | ||
watch($docus.ui, () => cookies.set(COOKIE_NAME, $docus.ui)) | ||
|
||
// Watch draft and fetch nav | ||
watch( | ||
() => $docus.ui.draft, | ||
() => $docus?.fetchNavigation?.() | ||
) | ||
|
||
// Mount DocusUI widget on client-side | ||
const el = document.createElement('div') | ||
|
||
document.body.appendChild(el) | ||
|
||
const instanceData: any = { | ||
...DocusUI, | ||
$docus | ||
} | ||
|
||
new Vue(instanceData).$mount(el) | ||
} | ||
|
||
// Re-fetch categories | ||
if (process.server) await $docus?.fetchNavigation?.() | ||
} |
674418f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: