Skip to content
Snippets Groups Projects
router.js 2.44 KiB
Newer Older
onny's avatar
onny committed
/*
 * @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 Browse from './views/Browse'
import BrowseAll from './views/BrowseAll'
import NotImplemented from './views/NotImplemented'
onny's avatar
onny committed
import store from './store.js'

import BrowseEmpty from './views/placeholder/Browse'

onny's avatar
onny committed
Vue.use(Router)
const requesttoken = axios.defaults.headers.requesttoken

const router = new Router({
onny's avatar
onny committed
	base: generateUrl('/apps/podcast/'),
onny's avatar
onny committed
	linkActiveClass: 'active',
	routes: [
		{
onny's avatar
onny committed
			path: '/listening',
onny's avatar
onny committed
			name: 'LISTENING',
onny's avatar
onny committed
		},
		{
onny's avatar
onny committed
			path: '/library',
			component: NotImplemented,
onny's avatar
onny committed
			name: 'LIBRARY',
onny's avatar
onny committed
		},
		{
onny's avatar
onny committed
			path: '/browse',
			component: Browse,
onny's avatar
onny committed
			name: 'BROWSE',
onny's avatar
onny committed
		},
		{
			path: '/browse/hot',
			component: BrowseAll,
			name: 'BROWSE',
		},
onny's avatar
onny committed
		{
			component: Show,
			name: 'SHOW',
			props: {},
		},
		{
			path: '/browse/show/:id/:episodeId',
			component: Episode,
			name: 'EPISODE',
onny's avatar
onny committed
			props: {},
		},
		{
			path: '/search/:query',
			component: Main,
			name: 'SEARCH',
			props: {},
		},
onny's avatar
onny committed
	],
})

router.beforeEach((to, from, next) => {

	if (to.name) {
		store.dispatch('setMenuState', to.name)
		next()
	} else {
		axios.defaults.headers.requesttoken = requesttoken
		axios
onny's avatar
onny committed
			.get(generateUrl('/apps/podcast/settings/menuState'))
onny's avatar
onny committed
			.then(async response => {
				const {
					data: { menuState: value },
				} = response
				next({ name: value })
			})
	}

})

export default router