mirror of
https://github.com/KevinMidboe/seasoned.git
synced 2026-03-10 19:39:10 +00:00
New store module for setting the document title. Each route changes the document title to its name
This commit is contained in:
37
src/modules/documentTitle.js
Normal file
37
src/modules/documentTitle.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const capitalize = (string) => {
|
||||
return string.includes(' ') ?
|
||||
string.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).replace('_', ' ')).join(' ')
|
||||
: string.charAt(0).toUpperCase() + string.slice(1)
|
||||
}
|
||||
|
||||
const setDocumentTitle = (state) => {
|
||||
document.title = `${state.emoji} ${state.titlePrefix} | ${capitalize(state.title)}`
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
emoji: '🍕',
|
||||
titlePrefix: 'request',
|
||||
title: undefined
|
||||
},
|
||||
getters: {},
|
||||
mutations: {
|
||||
SET_EMOJI: (state, emoji) => {
|
||||
state.emoji = emoji
|
||||
setDocumentTitle(state)
|
||||
},
|
||||
SET_TITLE: (state, title) => {
|
||||
state.title = title
|
||||
setDocumentTitle(state)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
updateEmoji({ commit }, emoji) {
|
||||
commit('SET_EMOJI', emoji)
|
||||
},
|
||||
updateTitle({ commit }, title) {
|
||||
commit('SET_TITLE', title)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user