-
Notifications
You must be signed in to change notification settings - Fork 884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect playlist sort order in watch-video-playlist
#5013
Merged
FreeTubeBot
merged 18 commits into
FreeTubeApp:development
from
kommunarr:feat/add-playlist-sort-order-2
Jun 12, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c07dfb9
Implement playlist sorting
kommunarr 5c03d60
Hide sort menu for remote playlists
kommunarr d91792a
Remove 'Custom (descending)' sort order
kommunarr 318fe08
Adjust sort order & align dropdown with 'More Options' button
kommunarr 9db7e48
Make 'Latest added first' default option instead of custom
kommunarr 95a6403
Remove unlikely-to-be-implemented 'Date published' sorting options
kommunarr b2b77eb
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr 10aac78
Update to use sortOrder as main variable throughout
kommunarr 8fd5055
Hide sort menu for playlists of length <2
kommunarr af09a76
Send sorted user playlist to watch-video-playlist
kommunarr c589aba
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr 4028551
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr 61a5885
Implement minor reversing optimization / cleanup
kommunarr 1cf9f7e
Update src/renderer/helpers/playlists.js
kommunarr 33399a1
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr d4124a1
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr b91d925
Change Playlist.js logic to cache user playlists, and pass the sorted…
kommunarr 093c3e6
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export const SORT_BY_VALUES = { | ||
DateAddedNewest: 'date_added_descending', | ||
DateAddedOldest: 'date_added_ascending', | ||
AuthorAscending: 'author_ascending', | ||
AuthorDescending: 'author_descending', | ||
VideoTitleAscending: 'video_title_ascending', | ||
VideoTitleDescending: 'video_title_descending', | ||
Custom: 'custom' | ||
} | ||
|
||
export function getSortedPlaylistItems(playlistItems, sortOrder, locale, reversed = false) { | ||
if (sortOrder === SORT_BY_VALUES.Custom) { | ||
return reversed ? playlistItems.toReversed() : playlistItems | ||
} | ||
|
||
let collator | ||
|
||
if ( | ||
sortOrder === SORT_BY_VALUES.VideoTitleAscending || | ||
sortOrder === SORT_BY_VALUES.VideoTitleDescending || | ||
sortOrder === SORT_BY_VALUES.AuthorAscending || | ||
sortOrder === SORT_BY_VALUES.AuthorDescending | ||
) { | ||
collator = new Intl.Collator([locale, 'en']) | ||
} | ||
|
||
return playlistItems.toSorted((a, b) => { | ||
const first = !reversed ? a : b | ||
const second = !reversed ? b : a | ||
return compareTwoPlaylistItems(first, second, sortOrder, collator) | ||
}) | ||
} | ||
|
||
function compareTwoPlaylistItems(a, b, sortOrder, collator) { | ||
switch (sortOrder) { | ||
case SORT_BY_VALUES.DateAddedNewest: | ||
return b.timeAdded - a.timeAdded | ||
case SORT_BY_VALUES.DateAddedOldest: | ||
return a.timeAdded - b.timeAdded | ||
case SORT_BY_VALUES.VideoTitleAscending: | ||
return collator.compare(a.title, b.title) | ||
case SORT_BY_VALUES.VideoTitleDescending: | ||
return collator.compare(b.title, a.title) | ||
case SORT_BY_VALUES.AuthorAscending: | ||
return collator.compare(a.author, b.author) | ||
case SORT_BY_VALUES.AuthorDescending: | ||
return collator.compare(b.author, a.author) | ||
default: | ||
console.error(`Unknown sortOrder: ${sortOrder}`) | ||
return 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Optional) I know nothing about
Intl.Collator
But I would like to know if using a constant object be possible (map of
locale
toCollator
objects lazily created)(No idea how much it helps, if too complicated might not worth it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll mark it as a chore, although I'm skeptical if the access time would be considerably less than the creation time of this