Skip to content

Commit d267eae

Browse files
authored
Refactor code, selectIndex => compareType. (#15)
1 parent c1d5ddd commit d267eae

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/components/Playlist.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,19 @@
133133
jumpToFile() {
134134
window.pyobject.eval_emacs_function("eaf-open-in-file-manager", [this.currentTrack]);
135135
},
136+
136137
sortByTitle() {
137-
this.$store.commit("changeSort", 0);
138+
this.$store.commit("changeSort", "title");
138139
window.pyobject.eval_emacs_function("message", ["Sort by title."]);
139140
},
141+
140142
sortByArtist() {
141-
this.$store.commit("changeSort", 1);
143+
this.$store.commit("changeSort", "artist");
142144
window.pyobject.eval_emacs_function("message", ["Sort by artist."]);
143145
},
146+
144147
sortByAlbum() {
145-
this.$store.commit("changeSort", 2);
148+
this.$store.commit("changeSort", "album");
146149
window.pyobject.eval_emacs_function("message", ["Sort by album."]);
147150
}
148151
}

src/store/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,17 @@ const store = new Vuex.Store({
3232
state.fileInfos = infos;
3333
state.numberWidth = state.fileInfos.length.toString().length;
3434
},
35-
/*
36-
* 0 : sort by name
37-
* 1 : sort by artist
38-
* 2 : sort by album
39-
*/
40-
changeSort(state, selectIndex) {
35+
changeSort(state, compareType) {
4136
var currentSong = state.fileInfos[state.currentTrackIndex];
4237
state.fileInfos.sort(function (a, b) {
4338
var compareA, compareB;
44-
if (selectIndex === 0) {
39+
if (compareType === "title") {
4540
compareA = a.name;
4641
compareB = b.name;
47-
} else if (selectIndex === 1) {
42+
} else if (compareType === "artist") {
4843
compareA = a.artist;
4944
compareB = b.artist;
50-
} else {
45+
} else if (compareType === "album") {
5146
compareA = a.album;
5247
compareB = b.album;
5348
}

0 commit comments

Comments
 (0)