diff --git a/web/README.md b/web/README.md index 610db26..6e18821 100644 --- a/web/README.md +++ b/web/README.md @@ -1,42 +1,2 @@ -# - -This template should help get you started developing with Vue 3 in Vite. - -## Recommended IDE Setup - -[VS Code](https://code.visualstudio.com/) + [Vue (Official)](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur). - -## Recommended Browser Setup - -- Chromium-based browsers (Chrome, Edge, Brave, etc.): - - [Vue.js devtools](https://chromewebstore.google.com/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd) - - [Turn on Custom Object Formatter in Chrome DevTools](http://bit.ly/object-formatters) -- Firefox: - - [Vue.js devtools](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/) - - [Turn on Custom Object Formatter in Firefox DevTools](https://fxdx.dev/firefox-devtools-custom-object-formatters/) - -## Type Support for `.vue` Imports in TS - -TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types. - -## Customize configuration - -See [Vite Configuration Reference](https://vite.dev/config/). - -## Project Setup - -```sh -npm install -``` - -### Compile and Hot-Reload for Development - -```sh -npm run dev -``` - -### Type-Check, Compile and Minify for Production - -```sh -npm run build -``` +# MusicPlayer Webapp +More notes to come diff --git a/web/src/router/index.ts b/web/src/router/index.ts index 85ca752..956d739 100644 --- a/web/src/router/index.ts +++ b/web/src/router/index.ts @@ -1,10 +1,64 @@ +import { + useAuthStore +} from '@/stores/authstore'; import { createRouter, createWebHistory } from 'vue-router'; const router = createRouter( { 'history': createWebHistory( import.meta.env.BASE_URL ), - 'routes': [] + 'routes': [ + { + 'path': '/', + 'name': 'home', + 'component': () => import( '@/views/StartPage.vue' ), + 'meta': { + 'title': 'Home', + 'auth': false + } + }, + { + 'path': '/app', + 'name': 'app', + 'component': () => import( '@/views/AppView.vue' ), + 'meta': { + 'title': 'Player', + 'auth': true + } + }, + { + 'path': '/:pathMatch(.*)*', + 'name': 'NotFound', + 'component': () => import( '@/views/404View.vue' ), + 'meta': { + 'title': '404 :: Page not found', + 'transition': 'scale' + } + } + ] +} ); + +router.beforeEach( ( to, from ) => { + const store = useAuthStore(); + + if ( to.meta.authRequired && !store.isAuth ) { + return { + 'name': 'login' + }; + } else if ( ( to.name === 'login' && store.isAuth ) || ( to.name === 'signup' && store.isAuth ) ) { + return { + 'name': 'app-home' + }; + } +} ); + +router.afterEach( to => { + window.scrollTo( { + 'top': 0, + 'behavior': 'smooth' + } ); + document.title = to.meta.title ? to.meta.title + ' - MusicPlayer' : 'MusicPlayer'; + // NProgress.done(); } ); export default router; diff --git a/web/src/stores/authstore.ts b/web/src/stores/authstore.ts new file mode 100644 index 0000000..14c8803 --- /dev/null +++ b/web/src/stores/authstore.ts @@ -0,0 +1,14 @@ +import { + defineStore +} from 'pinia'; +import { + ref +} from 'vue'; + +export const useAuthStore = defineStore( 'authstore', () => { + const isAuth = ref( false ); + + return { + isAuth + }; +} ); diff --git a/web/src/stores/counter.ts b/web/src/stores/counter.ts deleted file mode 100644 index b6757ba..0000000 --- a/web/src/stores/counter.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ref, computed } from 'vue' -import { defineStore } from 'pinia' - -export const useCounterStore = defineStore('counter', () => { - const count = ref(0) - const doubleCount = computed(() => count.value * 2) - function increment() { - count.value++ - } - - return { count, doubleCount, increment } -}) diff --git a/web/src/views/404View.vue b/web/src/views/404View.vue index 8baf6a6..9dbaddd 100644 --- a/web/src/views/404View.vue +++ b/web/src/views/404View.vue @@ -1,7 +1,10 @@ @@ -10,15 +13,11 @@ diff --git a/web/src/views/AppView.vue b/web/src/views/AppView.vue index e69de29..79800fe 100644 --- a/web/src/views/AppView.vue +++ b/web/src/views/AppView.vue @@ -0,0 +1,5 @@ + diff --git a/web/src/views/StartPage.vue b/web/src/views/StartPage.vue index e69de29..c0c287c 100644 --- a/web/src/views/StartPage.vue +++ b/web/src/views/StartPage.vue @@ -0,0 +1,5 @@ +