koel/resources/assets/js/components/shared/view-mode-switch.vue

93 lines
1.9 KiB
Vue
Raw Normal View History

<template>
2016-06-25 16:05:24 +00:00
<span class="view-modes">
<a :class="{ active: mutatedMode === 'thumbnails' }"
title="View as thumbnails"
@click.prevent="setMode('thumbnails')"><i class="fa fa-th-large"></i></a>
<a :class="{ active: mutatedMode === 'list' }"
title="View as list"
@click.prevent="setMode('list')"><i class="fa fa-list"></i></a>
</span>
</template>
<script>
2016-06-25 16:05:24 +00:00
import isMobile from 'ismobilejs';
2016-06-25 16:05:24 +00:00
import { event } from '../../utils';
import { preferenceStore as preferences } from '../../stores';
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
export default {
props: ['mode', 'for'],
2016-06-25 16:05:24 +00:00
data() {
return {
mutatedMode: this.mode,
};
},
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
computed: {
/**
* The preference key for local storage for persistent mode.
*
* @return {string}
*/
preferenceKey() {
return `${this.for}ViewMode`;
},
},
2016-06-25 16:05:24 +00:00
methods: {
setMode(mode) {
preferences[this.preferenceKey] = this.mutatedMode = mode;
this.$parent.changeViewMode(mode);
},
},
2016-06-25 16:05:24 +00:00
created() {
event.on('koel:ready', () => {
this.mutatedMode = preferences[this.preferenceKey];
2016-06-25 16:05:24 +00:00
// If the value is empty, we set a default mode.
// On mobile, the mode should be 'listing'.
// For desktop, 'thumbnails'.
if (!this.mutatedMode) {
this.mutatedMode = isMobile.phone ? 'list' : 'thumbnails';
}
2016-06-25 10:20:30 +00:00
2016-06-25 16:05:24 +00:00
this.setMode(this.mutatedMode);
});
},
};
</script>
<style lang="sass" scoped>
2016-06-25 16:05:24 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
2016-06-25 16:05:24 +00:00
.view-modes {
display: flex;
flex: 0 0 64px;
border: 1px solid rgba(255, 255, 255, .2);
height: 2rem;
border-radius: 5px;
overflow: hidden;
2016-06-25 16:05:24 +00:00
a {
width: 50%;
text-align: center;
line-height: 2rem;
font-size: 1rem;
2016-06-25 16:05:24 +00:00
&.active {
background: #fff;
color: #111;
}
2016-06-25 16:05:24 +00:00
}
@media only screen and(max-width: 768px) {
flex: auto;
width: 64px;
margin-top: 8px;
}
}
</style>