From 855b5b2efe82e414f8d278b5dff2716e610baf8e Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Sat, 16 Jan 2021 13:12:44 +0100 Subject: [PATCH] put player into seperate store module --- CHANGELOG.md | 2 + src/components/Main.vue | 483 ---------------------------------------- src/router.js | 2 +- src/store/favorites.js | 21 ++ src/store/main.js | 49 ++++ src/store/player.js | 87 ++++++++ 6 files changed, 160 insertions(+), 484 deletions(-) delete mode 100644 src/components/Main.vue create mode 100644 src/store/favorites.js create mode 100644 src/store/main.js create mode 100644 src/store/player.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 29529bd..3f58739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ [235](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/235) @onny - Update license year to 2021 [234](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/234) @onny +- Move menuState and volumeState into localStorage + [236](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/236) @onny ## 1.0.1 - 2020-12 ### Added diff --git a/src/components/Main.vue b/src/components/Main.vue deleted file mode 100644 index dd12eab..0000000 --- a/src/components/Main.vue +++ /dev/null @@ -1,483 +0,0 @@ - - - - - - - diff --git a/src/router.js b/src/router.js index bec9c04..63c5922 100644 --- a/src/router.js +++ b/src/router.js @@ -24,7 +24,7 @@ import Vue from 'vue' import Router from 'vue-router' import { generateUrl } from '@nextcloud/router' -import Main from './components/Main' +import Main from './views/Main' import store from './store/main.js' Vue.use(Router) diff --git a/src/store/favorites.js b/src/store/favorites.js new file mode 100644 index 0000000..989f125 --- /dev/null +++ b/src/store/favorites.js @@ -0,0 +1,21 @@ +/* + * @copyright Copyright (c) 2021 Jonas Heinrich + * + * @author Jonas Heinrich + * + * @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 . + * + */ diff --git a/src/store/main.js b/src/store/main.js new file mode 100644 index 0000000..3c6bd29 --- /dev/null +++ b/src/store/main.js @@ -0,0 +1,49 @@ +/* + * @copyright Copyright (c) 2021 Jonas Heinrich + * + * @author Jonas Heinrich + * + * @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 . + * + */ + +import Vue from 'vue' +import Vuex from 'vuex' +import player from './player' +import favorites from './favorites' + +Vue.use(Vuex) + +export default new Vuex.Store({ + modules: { + player, + favorites, + }, + state: { + menu: localStorage.getItem('radio.menu') || 'top', + }, + mutations: { + setMenuState(state, menuState) { + localStorage.setItem('radio.menu', menuState) + state.menu = menuState + }, + }, + actions: { + setMenuState(context, menuState) { + context.commit('setMenuState', menuState) + }, + }, +}) diff --git a/src/store/player.js b/src/store/player.js new file mode 100644 index 0000000..c990e50 --- /dev/null +++ b/src/store/player.js @@ -0,0 +1,87 @@ +/* + * @copyright Copyright (c) 2021 Jonas Heinrich + * + * @author Jonas Heinrich + * + * @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 . + * + */ + +export default ({ + state: { + isPlaying: false, + isBuffering: false, + isMute: false, + isPaused: false, + volume: localStorage.getItem('radio.volume') || 0.5, + oldVolume: localStorage.getItem('radio.volume') || 0.5, + title: '', + }, + mutations: { + setPlaying(state, playerState) { + state.isPlaying = playerState + }, + setBuffering(state, bufferingState) { + state.isBuffering = bufferingState + }, + setVolume(state, volume) { + state.volume = volume + localStorage.setItem('radio.volume', volume) + }, + toggleMute(state) { + if (state.isMute) { + state.volume = state.player.oldVolume + state.isMute = false + } else { + state.oldVolume = state.player.volume + state.volume = 0 + state.isMute = true + } + }, + togglePlay(state) { + if (state.isPlaying) { + state.isPlaying = false + state.isPaused = true + } else { + state.isPlaying = true + state.isPaused = false + } + }, + setTitle(state, title) { + state.title = title + }, + }, + actions: { + setPlaying(context, playerState) { + context.commit('setPlaying', playerState) + }, + setBuffering(context, bufferingState) { + context.commit('setBuffering', bufferingState) + }, + setVolume(context, volume) { + context.commit('setVolume', volume) + }, + toggleMute(context) { + context.commit('toggleMute') + }, + togglePlay(context) { + context.commit('togglePlay') + }, + setTitle(context, title) { + context.commit('setTitle', title) + }, + }, +})