Skip to content

Commit 433eb0d

Browse files
committed
* Update add to playlist prompt to add sort options
1 parent d6f2f5d commit 433eb0d

File tree

3 files changed

+79
-9
lines changed

3 files changed

+79
-9
lines changed

src/renderer/components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.js

+64-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,32 @@ import FtPrompt from '../ft-prompt/ft-prompt.vue'
66
import FtButton from '../ft-button/ft-button.vue'
77
import FtPlaylistSelector from '../ft-playlist-selector/ft-playlist-selector.vue'
88
import FtInput from '../../components/ft-input/ft-input.vue'
9+
import FtSelect from '../../components/ft-select/ft-select.vue'
910
import {
1011
showToast,
1112
} from '../../helpers/utils'
1213

14+
const SORT_BY_VALUES = {
15+
NameAscending: 'name_ascending',
16+
NameDescending: 'name_descending',
17+
18+
LatestCreatedFirst: 'latest_created_first',
19+
EarliestCreatedFirst: 'earliest_created_first',
20+
21+
LatestUpdatedFirst: 'latest_updated_first',
22+
EarliestUpdatedFirst: 'earliest_updated_first',
23+
}
24+
const SORT_BY_NAMES = {
25+
NameAscending: 'A-Z',
26+
NameDescending: 'Z-A',
27+
28+
LatestCreatedFirst: 'Recently Created',
29+
EarliestCreatedFirst: 'Earliest Created',
30+
31+
LatestUpdatedFirst: 'Recently Updated',
32+
EarliestUpdatedFirst: 'Earliest Updated',
33+
}
34+
1335
export default Vue.extend({
1436
name: 'FtPlaylistAddVideoPrompt',
1537
components: {
@@ -18,6 +40,7 @@ export default Vue.extend({
1840
'ft-button': FtButton,
1941
'ft-playlist-selector': FtPlaylistSelector,
2042
'ft-input': FtInput,
43+
'ft-select': FtSelect,
2144
},
2245
data: function () {
2346
return {
@@ -29,20 +52,46 @@ export default Vue.extend({
2952
lastActiveElement: null,
3053
interactionsLocked: false,
3154
preventOpenCreatePlaylistPromptOnce: false,
55+
sortBy: SORT_BY_VALUES.LatestUpdatedFirst,
3256
}
3357
},
3458
computed: {
3559
allPlaylists: function () {
3660
const playlists = this.$store.getters.getAllPlaylists
3761
return [].concat(playlists).sort((a, b) => {
38-
// Sort by `lastUpdatedAt`, then alphabetically
39-
if (a.lastUpdatedAt > b.lastUpdatedAt) {
40-
return -1
41-
} else if (b.lastUpdatedAt > a.lastUpdatedAt) {
42-
return 1
43-
}
62+
switch (this.sortBy) {
63+
case SORT_BY_VALUES.NameAscending:
64+
return a.playlistName.localeCompare(b.playlistName, this.locale)
65+
case SORT_BY_VALUES.NameDescending:
66+
return b.playlistName.localeCompare(a.playlistName, this.locale)
67+
case SORT_BY_VALUES.LatestCreatedFirst: {
68+
if (a.createdAt > b.createdAt) { return -1 }
69+
if (a.createdAt < b.createdAt) { return 1 }
70+
71+
return a.playlistName.localeCompare(b.playlistName, this.locale)
72+
}
73+
case SORT_BY_VALUES.EarliestCreatedFirst: {
74+
if (a.createdAt < b.createdAt) { return -1 }
75+
if (a.createdAt > b.createdAt) { return 1 }
76+
77+
return a.playlistName.localeCompare(b.playlistName, this.locale)
78+
}
79+
case SORT_BY_VALUES.LatestUpdatedFirst: {
80+
if (a.lastUpdatedAt > b.lastUpdatedAt) { return -1 }
81+
if (a.lastUpdatedAt < b.lastUpdatedAt) { return 1 }
4482

45-
return a.playlistName.localeCompare(b.playlistName, this.locale)
83+
return a.playlistName.localeCompare(b.playlistName, this.locale)
84+
}
85+
case SORT_BY_VALUES.EarliestUpdatedFirst: {
86+
if (a.lastUpdatedAt < b.lastUpdatedAt) { return -1 }
87+
if (a.lastUpdatedAt > b.lastUpdatedAt) { return 1 }
88+
89+
return a.playlistName.localeCompare(b.playlistName, this.locale)
90+
}
91+
default:
92+
console.error(`Unknown sortBy: ${this.sortBy}`)
93+
return 0
94+
}
4695
})
4796
},
4897
allPlaylistsLength() {
@@ -87,7 +136,14 @@ export default Vue.extend({
87136

88137
tabindex() {
89138
return this.interactionsLocked ? -1 : 0
90-
}
139+
},
140+
141+
sortBySelectNames() {
142+
return Object.keys(SORT_BY_VALUES).map(k => SORT_BY_NAMES[k])
143+
},
144+
sortBySelectValues() {
145+
return Object.values(SORT_BY_VALUES)
146+
},
91147
},
92148
watch: {
93149
allPlaylistsLength(val, oldVal) {

src/renderer/components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.scss

+5
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@
2929
right: $horizontal-margin;
3030
width: 100% - ($horizontal-margin * 2);
3131
}
32+
33+
.sortSelect {
34+
/* Put it on the right */
35+
margin-left: auto;
36+
}

src/renderer/components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{{ selectedPlaylistCount }} Selected
1010
</p>
1111
<ft-input
12-
v-show="allPlaylists.length > 0"
12+
v-show="allPlaylists.length > 1"
1313
ref="searchBar"
1414
placeholder="Search in Playlist"
1515
:show-clear-text-button="true"
@@ -18,6 +18,15 @@
1818
@input="(input) => updateQueryDebounce(input)"
1919
@clear="updateQueryDebounce('')"
2020
/>
21+
<ft-select
22+
v-if="allPlaylists.length > 1"
23+
class="sortSelect"
24+
:value="sortBy"
25+
:select-names="sortBySelectNames"
26+
:select-values="sortBySelectValues"
27+
:placeholder="'Sort By'"
28+
@change="sortBy = $event"
29+
/>
2130
<ft-flex-box>
2231
<ft-playlist-selector
2332
v-for="(playlist, index) in activePlaylists"

0 commit comments

Comments
 (0)