mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
externalize main RouterLink transition name computation to store
This commit is contained in:
parent
b3e1860b6a
commit
fa63687cd6
3 changed files with 20 additions and 19 deletions
|
@ -86,33 +86,17 @@ export default {
|
||||||
ViewLockOverlay
|
ViewLockOverlay
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
transitionName: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
'connected',
|
'connected',
|
||||||
'yunohost',
|
'yunohost',
|
||||||
'routerKey',
|
'routerKey',
|
||||||
'transitions',
|
'transitions',
|
||||||
|
'transitionName',
|
||||||
'waiting'
|
'waiting'
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
|
||||||
// Set the css class to animate the components transition
|
|
||||||
'$route' (to, from) {
|
|
||||||
if (!this.transitions || from.name === null) return
|
|
||||||
// Use the breadcrumb array length as a direction indicator
|
|
||||||
const toDepth = to.meta.breadcrumb.length
|
|
||||||
const fromDepth = from.meta.breadcrumb.length
|
|
||||||
this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
async logout () {
|
async logout () {
|
||||||
this.$store.dispatch('LOGOUT')
|
this.$store.dispatch('LOGOUT')
|
||||||
|
|
|
@ -30,6 +30,10 @@ const router = new VueRouter({
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
store.dispatch('UPDATE_ROUTER_KEY', { to, from })
|
store.dispatch('UPDATE_ROUTER_KEY', { to, from })
|
||||||
store.dispatch('UPDATE_BREADCRUMB', { to, from })
|
store.dispatch('UPDATE_BREADCRUMB', { to, from })
|
||||||
|
if (store.getters.transitions && from.name !== null) {
|
||||||
|
store.dispatch('UPDATE_TRANSITION_NAME', { to, from })
|
||||||
|
}
|
||||||
|
|
||||||
if (store.getters.error) {
|
if (store.getters.error) {
|
||||||
store.dispatch('DISMISS_ERROR', true)
|
store.dispatch('DISMISS_ERROR', true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@ export default {
|
||||||
historyTimer: null, // null || setTimeout id
|
historyTimer: null, // null || setTimeout id
|
||||||
tempMessages: [], // Array of messages
|
tempMessages: [], // Array of messages
|
||||||
routerKey: undefined, // String if current route has params
|
routerKey: undefined, // String if current route has params
|
||||||
breadcrumb: [] // Array of routes
|
breadcrumb: [], // Array of routes
|
||||||
|
transitionName: null // String of CSS class if transitions are enabled
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
|
@ -97,6 +98,10 @@ export default {
|
||||||
|
|
||||||
'SET_BREADCRUMB' (state, breadcrumb) {
|
'SET_BREADCRUMB' (state, breadcrumb) {
|
||||||
state.breadcrumb = breadcrumb
|
state.breadcrumb = breadcrumb
|
||||||
|
},
|
||||||
|
|
||||||
|
'SET_TRANSITION_NAME' (state, transitionName) {
|
||||||
|
state.transitionName = transitionName
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -333,6 +338,13 @@ export default {
|
||||||
|
|
||||||
// Display a simplified breadcrumb as the document title.
|
// Display a simplified breadcrumb as the document title.
|
||||||
document.title = `${getTitle(breadcrumb)} | ${i18n.t('yunohost_admin')}`
|
document.title = `${getTitle(breadcrumb)} | ${i18n.t('yunohost_admin')}`
|
||||||
|
},
|
||||||
|
|
||||||
|
'UPDATE_TRANSITION_NAME' ({ state, commit }, { to, from }) {
|
||||||
|
// Use the breadcrumb array length as a direction indicator
|
||||||
|
const toDepth = (to.meta.breadcrumb || []).length
|
||||||
|
const fromDepth = (from.meta.breadcrumb || []).length
|
||||||
|
commit('SET_TRANSITION_NAME', toDepth < fromDepth ? 'slide-right' : 'slide-left')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -350,6 +362,7 @@ export default {
|
||||||
return request || state.requests[state.requests.length - 1]
|
return request || state.requests[state.requests.length - 1]
|
||||||
},
|
},
|
||||||
routerKey: state => state.routerKey,
|
routerKey: state => state.routerKey,
|
||||||
breadcrumb: state => state.breadcrumb
|
breadcrumb: state => state.breadcrumb,
|
||||||
|
transitionName: state => state.transitionName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue