Skip to content

Commit

Permalink
feat(#150): add recent documents store
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Aug 23, 2021
1 parent 68e26c2 commit d82c0ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/middleware/recent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function ({ store, route }) {
store.commit('addRecent', route)
}
4 changes: 4 additions & 0 deletions docs/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export default {
build: {},

telemetry: true,

router: {
middleware: 'recent',
}
}
16 changes: 16 additions & 0 deletions docs/store/mutations.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
11 changes: 9 additions & 2 deletions docs/store/state.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -16,5 +20,8 @@ export default () => ({
'schema',
'site',
'views'
]
],

// Recently opened documents.
recent: [],
})

0 comments on commit d82c0ac

Please sign in to comment.