Skip to content

Commit

Permalink
refactor: explore category
Browse files Browse the repository at this point in the history
  • Loading branch information
qier222 committed Apr 20, 2021
1 parent 2f0e8e1 commit f16d08a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
7 changes: 6 additions & 1 deletion src/store/initLocalStorage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { playlistCategories } from "@/utils/staticData";

console.log("[debug][initLocalStorage.js]");
const enabledPlaylistCategories = playlistCategories
.filter((c) => c.enable)
.map((c) => c.name);

let localStorage = {
player: {},
settings: {
playlistCategories,
lang: null,
appearance: "auto",
musicQuality: 320000,
Expand All @@ -20,6 +24,7 @@ let localStorage = {
enableDiscordRichPresence: false,
enableGlobalShortcut: true,
showLibraryDefault: false,
enabledPlaylistCategories,
},
data: {
user: {},
Expand Down
18 changes: 9 additions & 9 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export default {
state.data[key] = value;
},
togglePlaylistCategory(state, name) {
let cat = state.settings.playlistCategories.find((c) => c.name === name);
cat.enable = !cat.enable;
state.settings.playlistCategories = state.settings.playlistCategories.map(
(c) => {
if (c.name === name) {
return cat;
}
return c;
}
const index = state.settings.enabledPlaylistCategories.findIndex(
(c) => c.name === name
);
if (index !== -1) {
state.settings.enabledPlaylistCategories = state.settings.enabledPlaylistCategories.filter(
(c) => c.name !== name
);
} else {
state.settings.enabledPlaylistCategories.push(name);
}
},
updateToast(state, toast) {
state.toast = toast;
Expand Down
6 changes: 5 additions & 1 deletion src/utils/staticData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const byAppleMusic = [
name: "\u4e2d\u563b\u5408\u74a7",
id: 5277771961,
},

{
coverImgUrl:
"https://p1.music.126.net/cPaBXr1wZSg86ddl47AK7Q==/109951165375130918.jpg",
Expand All @@ -38,6 +37,11 @@ export const playlistCategories = [
enable: true,
bigCat: "static",
},
// {
// name: "For You",
// enable: true,
// bigCat: "static",
// },
{
name: "推荐歌单",
enable: true,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/updateApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import pkg from "../../package.json";
const updateSetting = () => {
const parsedSettings = JSON.parse(localStorage.getItem("settings"));
const {
playlistCategories,
showUnavailableSongInGreyStyle,
automaticallyCacheSongs,
nyancatStyle,
showLyricsTranslation,
minimizeToTray,
enabledPlaylistCategories,
} = initLocalStorage.settings;
const settings = {
playlistCategories,
showUnavailableSongInGreyStyle,
automaticallyCacheSongs,
nyancatStyle,
showLyricsTranslation,
minimizeToTray,
enabledPlaylistCategories,
...parsedSettings,
};

Expand Down
41 changes: 22 additions & 19 deletions src/views/explore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<h1>{{ $t("explore.explore") }}</h1>
<div class="buttons">
<div
v-for="category in settings.enabledPlaylistCategories"
:key="category"
class="button"
v-for="cat in settings.playlistCategories.filter((p) => p.enable)"
:key="cat.name"
:class="{ active: cat.name === activeCategory && !showCatOptions }"
@click="goToCategory(cat.name)"
:class="{ active: category === activeCategory && !showCatOptions }"
@click="goToCategory(category)"
>
{{ cat.name }}
{{ category }}
</div>
<div
class="button more"
Expand All @@ -20,15 +20,17 @@
</div>
</div>

<div class="panel" v-show="showCatOptions">
<div class="big-cat" v-for="bigCat in allBigCats" :key="bigCat">
<div v-show="showCatOptions" class="panel">
<div v-for="bigCat in allBigCats" :key="bigCat" class="big-cat">
<div class="name">{{ bigCat }}</div>
<div class="cats">
<div
class="cat"
:class="{ active: cat.enable }"
v-for="cat in getCatsByBigCat(bigCat)"
:key="cat.name"
class="cat"
:class="{
active: settings.enabledPlaylistCategories.includes(cat.name),
}"
@click="toggleCat(cat.name)"
><span>{{ cat.name }}</span></div
>
Expand All @@ -40,21 +42,21 @@
<CoverRow
type="playlist"
:items="playlists"
:subText="subText"
:showPlayButton="true"
:showPlayCount="activeCategory !== '排行榜' ? true : false"
:imageSize="activeCategory !== '排行榜' ? 512 : 1024"
:sub-text="subText"
:show-play-button="true"
:show-play-count="activeCategory !== '排行榜' ? true : false"
:image-size="activeCategory !== '排行榜' ? 512 : 1024"
/>
</div>
<div
class="load-more"
v-show="['推荐歌单', '排行榜'].includes(activeCategory) === false"
class="load-more"
>
<ButtonTwoTone
v-show="showLoadMoreButton && hasMore"
@click.native="getPlaylist"
color="grey"
:loading="loadingMore"
@click.native="getPlaylist"
>{{ $t("explore.loadMore") }}</ButtonTwoTone
>
</div>
Expand All @@ -70,6 +72,7 @@ import {
recommendPlaylist,
toplists,
} from "@/api/playlist";
import { playlistCategories } from "@/utils/staticData";
import ButtonTwoTone from "@/components/ButtonTwoTone.vue";
import CoverRow from "@/components/CoverRow.vue";
Expand Down Expand Up @@ -102,6 +105,9 @@ export default {
return "none";
},
},
activated() {
this.loadData();
},
methods: {
...mapMutations(["togglePlaylistCategory"]),
loadData() {
Expand Down Expand Up @@ -167,15 +173,12 @@ export default {
});
},
getCatsByBigCat(name) {
return this.settings.playlistCategories.filter((c) => c.bigCat === name);
return playlistCategories.filter((c) => c.bigCat === name);
},
toggleCat(name) {
this.togglePlaylistCategory(name);
},
},
activated() {
this.loadData();
},
beforeRouteUpdate(to, from, next) {
NProgress.start();
this.showLoadMoreButton = false;
Expand Down

1 comment on commit f16d08a

@vercel
Copy link

@vercel vercel bot commented on f16d08a Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.