/* * @copyright Copyright (c) 2020 Jonas Heinrich <onny@project-insanity.org> * * @author Jonas Heinrich <onny@project-insanity.org> * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import Vue from 'vue' import Router from 'vue-router' import { generateUrl } from '@nextcloud/router' import axios from '@nextcloud/axios' import Main from './components/Main' import Show from './views/Show' import Episode from './views/Episode' import store from './store.js' Vue.use(Router) const requesttoken = axios.defaults.headers.requesttoken const router = new Router({ base: generateUrl('/apps/podcast/'), linkActiveClass: 'active', routes: [ { path: '/listening', component: Main, name: 'LISTENING', }, { path: '/library', component: Main, name: 'LIBRARY', }, { path: '/browse', component: Main, name: 'BROWSE', }, { path: '/search/:query', component: Main, name: 'SEARCH', props: {}, }, { path: '/show/:id', component: Show, name: 'SHOW', props: {}, }, { path: '/show/:id/:episodeId', component: Episode, name: 'EPISODE', props: {}, }, ], }) router.beforeEach((to, from, next) => { if (to.name) { store.dispatch('setMenuState', to.name) next() } else { axios.defaults.headers.requesttoken = requesttoken axios .get(generateUrl('/apps/podcast/settings/menuState')) .then(async response => { const { data: { menuState: value }, } = response next({ name: value }) }) } }) export default router