Skip to content

Commit

Permalink
fix: update navigation on file update/remove (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored May 20, 2021
1 parent 4f6b069 commit a1c9416
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/core/runtime/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ export const useDocusNavigation = ({ $nuxt, context, state, api }: DocusAddonCon
if (!state.navigation) state.navigation = {}

// compute `currentNav` on every route change
const fetchCounter = ref(0)
const path = ref(route.path)
const currentNav = computed(() =>
get({
const currentNav = computed(() => {
// eslint-disable-next-line no-unused-expressions
fetchCounter.value
return get({
locale: app.i18n.locale,
from: path.value
})
)
})
app.router.beforeEach((to: any, __: any, next: any) => {
path.value = to.path
next()
Expand All @@ -26,6 +29,7 @@ export const useDocusNavigation = ({ $nuxt, context, state, api }: DocusAddonCon
const fetchNavigation = async () => {
const { body } = await api.data('/docus/navigation/' + locale)
state.navigation[locale] = body
fetchCounter.value += 1
}

function get({ depth, locale, from }: { depth?: number; locale?: string; from?: string }) {
Expand Down Expand Up @@ -113,6 +117,12 @@ export const useDocusNavigation = ({ $nuxt, context, state, api }: DocusAddonCon
return withTrailingSlash(path) === withTrailingSlash(context.$contentLocalePath(to))
}

window.onNuxtReady($nuxt => {
$nuxt.$on('content:update', () => {
fetchNavigation()
})
})

return {
getPageTemplate,
fetchNavigation,
Expand Down
6 changes: 4 additions & 2 deletions src/core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ export const docusDriver = defineDriver((options: DriverOptions) => {
const content = await fs.getItem(key)

await parseAndIndex(key, content)

callHook('docus:storage:updated', { event, key })
}
if (event === 'remove') {
await items.removeWhere(doc => doc.key === key)
}
callHook('docus:storage:updated', { event, key })
callback(event, key)
})
}
Expand Down

1 comment on commit a1c9416

@vercel
Copy link

@vercel vercel bot commented on a1c9416 May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.