@@ -6,10 +6,32 @@ import FtPrompt from '../ft-prompt/ft-prompt.vue'
6
6
import FtButton from '../ft-button/ft-button.vue'
7
7
import FtPlaylistSelector from '../ft-playlist-selector/ft-playlist-selector.vue'
8
8
import FtInput from '../../components/ft-input/ft-input.vue'
9
+ import FtSelect from '../../components/ft-select/ft-select.vue'
9
10
import {
10
11
showToast ,
11
12
} from '../../helpers/utils'
12
13
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
+
13
35
export default Vue . extend ( {
14
36
name : 'FtPlaylistAddVideoPrompt' ,
15
37
components : {
@@ -18,6 +40,7 @@ export default Vue.extend({
18
40
'ft-button' : FtButton ,
19
41
'ft-playlist-selector' : FtPlaylistSelector ,
20
42
'ft-input' : FtInput ,
43
+ 'ft-select' : FtSelect ,
21
44
} ,
22
45
data : function ( ) {
23
46
return {
@@ -29,20 +52,46 @@ export default Vue.extend({
29
52
lastActiveElement : null ,
30
53
interactionsLocked : false ,
31
54
preventOpenCreatePlaylistPromptOnce : false ,
55
+ sortBy : SORT_BY_VALUES . LatestUpdatedFirst ,
32
56
}
33
57
} ,
34
58
computed : {
35
59
allPlaylists : function ( ) {
36
60
const playlists = this . $store . getters . getAllPlaylists
37
61
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 }
44
82
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
+ }
46
95
} )
47
96
} ,
48
97
allPlaylistsLength ( ) {
@@ -87,7 +136,14 @@ export default Vue.extend({
87
136
88
137
tabindex ( ) {
89
138
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
+ } ,
91
147
} ,
92
148
watch : {
93
149
allPlaylistsLength ( val , oldVal ) {
0 commit comments