Move shared song logic to router

This commit is contained in:
An Phan 2016-07-11 02:05:18 +08:00
parent 60440a4578
commit 4f6226d224
No known key found for this signature in database
GPG key ID: 05536BB4BCDC02A2
2 changed files with 15 additions and 19 deletions

View file

@ -25,7 +25,6 @@
<script>
import Vue from 'vue';
import $ from 'jquery';
import isMobile from 'ismobilejs';
import siteHeader from './components/site-header/index.vue';
import siteFooter from './components/site-footer/index.vue';
@ -35,7 +34,7 @@ import loginForm from './components/auth/login-form.vue';
import editSongsForm from './components/modals/edit-songs-form.vue';
import { event, showOverlay, hideOverlay, loadMainView, forceReloadWindow, url } from './utils';
import { sharedStore, queueStore, songStore, userStore, preferenceStore as preferences } from './stores';
import { sharedStore, songStore, userStore, preferenceStore as preferences } from './stores';
import { playback, ls } from './services';
import { focusDirective, clickawayDirective } from './directives';
import router from './router';
@ -201,21 +200,6 @@ export default {
*/
'koel:ready': () => {
router.init();
const songId = url.parseSongId();
if (!songId) return;
const song = songStore.byId(songId);
if (!song) return;
if (isMobile.apple.device) {
// Mobile Safari doesn't allow autoplay, so we just queue.
queueStore.queue(song);
loadMainView('queue');
} else {
playback.queueAndPlay(song);
}
},
});
},

View file

@ -1,5 +1,8 @@
import isMobile from 'ismobilejs';
import { loadMainView } from './utils';
import { artistStore, albumStore, songStore, playlistStore } from './stores';
import { artistStore, albumStore, songStore, queueStore, playlistStore } from './stores';
import { playback } from './services';
export default {
routes: {
@ -65,7 +68,16 @@ export default {
},
'/song/([a-z0-9]{32})'(id) {
console.log(id)
const song = songStore.byId(id);
if (!song) return;
if (isMobile.apple.device) {
// Mobile Safari doesn't allow autoplay, so we just queue.
queueStore.queue(song);
this.go('/#!/queue');
} else {
playback.queueAndPlay(song);
}
},
},