From d82c0ac3849bb00bbb946c21ab9a65537ec71a82 Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Mon, 23 Aug 2021 23:33:00 +0000 Subject: [PATCH] feat(#150): add recent documents store --- docs/middleware/recent.js | 3 +++ docs/nuxt.config.js | 4 ++++ docs/store/mutations.js | 16 ++++++++++++++++ docs/store/state.js | 11 +++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 docs/middleware/recent.js create mode 100644 docs/store/mutations.js diff --git a/docs/middleware/recent.js b/docs/middleware/recent.js new file mode 100644 index 000000000..a27d97067 --- /dev/null +++ b/docs/middleware/recent.js @@ -0,0 +1,3 @@ +export default function ({ store, route }) { + store.commit('addRecent', route) +} diff --git a/docs/nuxt.config.js b/docs/nuxt.config.js index d2e223096..99adabf38 100644 --- a/docs/nuxt.config.js +++ b/docs/nuxt.config.js @@ -46,4 +46,8 @@ export default { build: {}, telemetry: true, + + router: { + middleware: 'recent', + } } diff --git a/docs/store/mutations.js b/docs/store/mutations.js new file mode 100644 index 000000000..9d03397e0 --- /dev/null +++ b/docs/store/mutations.js @@ -0,0 +1,16 @@ +export default { + // TODO: add ability to pin items + // TODO: add support for page titles + addRecent(state, route) { + // Filter out current route. + const recent = [...state.recent].filter((o) => o.to !== route.path) + + // Add item. + recent.unshift({ + to: route.path + }) + + // Return only the last 5 items. + state.recent = recent.filter((o, index) => index < 5) + } +} diff --git a/docs/store/state.js b/docs/store/state.js index f396f678f..7ae64ff03 100644 --- a/docs/store/state.js +++ b/docs/store/state.js @@ -1,11 +1,15 @@ export default () => ({ + // Main menu items. menu: [{ title: 'Home', path: '/', }, { - title: 'API', + title: 'API documentation', path: '/api', }], + + // Module list. + // TODO: get this data programatically. modules: [ 'druxt', 'breadcrumb', @@ -16,5 +20,8 @@ export default () => ({ 'schema', 'site', 'views' - ] + ], + + // Recently opened documents. + recent: [], })