Skip to content
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

Sort by date on the history page #6214

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

jlvivero
Copy link

@jlvivero jlvivero commented Nov 22, 2024

Sortbydate

Pull Request Type

  • Bugfix
  • Feature Implementation
  • Documentation
  • Other

Related issue

Initial addition to #5595 (not sure it would be considered closed and we just make a new issue for future changes)

Description

Adds a sort by date ascending/descending toggle to the history page, this is a stopgap to adding a more fully fledged filter by setting, but I wanted to keep the changes small and incremental since design wise, some decisions have to be made and I'm not sure I'm the one that should make those decisions. (like other kinds of sorting/filtering in history page)

I also removed the second sorting it does when it does the search, since the array it uses is already sorted (in whichever order we choose), and the filter method I believe does a linear scan, it seemed unnecessary to sort twice, if we think it's necessary I can add it back and just add a condition to sort whichever way we need it to (But I don't think it's needed)

Screenshots

freetubesortby

Testing

I tested by adding random videos to history, sorting it back and forth, then doing search and sorting back and forth as well

possibly with a huge history we'd like to view how the sorting performs... I don't have a huge history at the moment, so it's hard to tell. it's expected to a certain degree

Desktop

Additional context

I stuck to the simple toggle since I was only going to do the asc/desc sorting on this PR

@github-actions github-actions bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Nov 22, 2024
@FreeTubeBot FreeTubeBot enabled auto-merge (squash) November 22, 2024 20:13
auto-merge was automatically disabled November 22, 2024 20:16

Head branch was pushed to by a user without write access

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) November 22, 2024 20:16
@PikachuEXE PikachuEXE requested a review from absidue November 22, 2024 22:14
@jlvivero
Copy link
Author

jlvivero commented Dec 3, 2024

o: it's been two weeks, hopefully this get reviewed soon so I can make any fixes necessary and/or start work on follow ups

src/renderer/views/History/History.js Show resolved Hide resolved
src/renderer/views/History/History.js Outdated Show resolved Hide resolved
@@ -44,14 +41,15 @@ export default defineComponent({
dataLimit: 100,
searchDataLimit: 100,
doCaseSensitiveSearch: false,
ascending: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ascending: false,
useAscendingOrder: false,

Recommend adjusting the variable name to be more specific.

Copy link
Author

Choose a reason for hiding this comment

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

sounds good, I'll change it

@@ -28,6 +28,13 @@
:default-value="doCaseSensitiveSearch"
@change="doCaseSensitiveSearch = !doCaseSensitiveSearch"
/>
<ft-toggle-switch
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): We do tend to use ft-selects for sort selections, and we may have more options for this in the future, so you may want to consider changing it. Not incredibly important at this point, though, aside from making the current labeling more likely to be temporary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Better have consistent UI unless there is a good reason

Copy link
Author

Choose a reason for hiding this comment

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

ft-select will probably require me to make change to the store, not a problem, but I'm debating then, if I'm using ft-select I should stop using a boolean for this then, I didn't want to use an enum yet, since I don't even know if we will have sorting of anything besides date. (and if we are never sorting by anything else an enum feels unnecessary)

what are your thoughts on using an enum instead?

I can also add boolean as a type to ft-select, but I'm not sure what is the desired approach here

@@ -269,6 +269,7 @@ History:
Empty Search Message: There are no videos in your history that match your search
Search bar placeholder: "Search in History"
Case Sensitive Search: Case Sensitive Search
Sort By Date ASC: Sort By Date ASC
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: Related to the above, not a fan of this label, but hard to know of a better alternative without switching to ft-select. If you do do that, looking at the other sorting labels we have, more consistent ones would be DateWatchedOldest: Earliest Watched First and DateWatchedNewest: Latest Watched First

Copy link
Author

Choose a reason for hiding this comment

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

I was also not a big fan of the label, but I also wasn't sure what to write, I'll look into ft-select and update the label accordingly (I like the Latest/Earliest watched first label more)

Copy link
Author

Choose a reason for hiding this comment

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

I changed the sort by texts please take a look

auto-merge was automatically disabled December 7, 2024 17:30

Head branch was pushed to by a user without write access

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) December 7, 2024 17:30
Copy link
Contributor

github-actions bot commented Dec 7, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added PR: merge conflicts / rebase needed and removed PR: waiting for review For PRs that are complete, tested, and ready for review labels Dec 7, 2024
@jlvivero
Copy link
Author

jlvivero commented Dec 7, 2024

I made some changes based on feedback, I switched to ft-select, I prepared the store to prepare for more sort options, when more sort options are added, historyCacheSorted would be the place to change things

(instead of just an inline if a case and calls to different sorting would be necessary).

in the case of this sort, it's just reversing the list not actually sorting, if other sorts would be added, we would need to stop doing that and actually sort, so a decision would have to be made if it's worth adding more sorting possibilities that would obviously make sorting slower, particularly with people with huge histories.

auto-merge was automatically disabled December 7, 2024 17:48

Head branch was pushed to by a user without write access

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) December 7, 2024 17:48
Copy link
Contributor

github-actions bot commented Dec 7, 2024

Conflicts have been resolved. A maintainer will review the pull request shortly.

@jlvivero
Copy link
Author

jlvivero commented Dec 7, 2024

I might have messed up the way I solved the conflicts (let me know if you prefer a clean PR again :(, or if something else)

@absidue
Copy link
Member

absidue commented Dec 7, 2024

Please solve the conflicts properly, you seem to have pulled in all the commits from the development branch so now it is really difficult to tell what changes are yours and merging this PR will then reland all of the existing changes on the development branch a second time.

The two usual approaches are:

  • git rebase development: That resets the starting point of your branch back to the current head of the development branch and recommits all of commits from this branch on top of it
  • git merge development: This merges in the changes from the development branch in a single commit that git recognises as a merge commit so ignores when comparing the changes and when this branch is merged into development

As for how to fix what you have done here, I'm not sure.

auto-merge was automatically disabled December 7, 2024 18:08

Head branch was pushed to by a user without write access

Copy link
Contributor

github-actions bot commented Dec 7, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@jlvivero
Copy link
Author

jlvivero commented Dec 7, 2024

I reset to my latest commit, I used rebase, but I think I messed it up somehow, unsure how it ended that way you can see only my changes now, I'll try to fix the merge conflicts in a bit... HOPEFULLY not messing everything up again lol

had to reset HEAD --hard <my_last_commit>

then I did the rebase properly after that

EDIT. that should have fixed it, sorry about the random trouble... please review when you have the chance

auto-merge was automatically disabled December 7, 2024 18:17

Head branch was pushed to by a user without write access

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) December 7, 2024 18:17
Copy link
Contributor

github-actions bot commented Dec 7, 2024

Conflicts have been resolved. A maintainer will review the pull request shortly.

@efb4f5ff-1298-471a-8973-3d47447115dc
Copy link
Member

efb4f5ff-1298-471a-8973-3d47447115dc commented Dec 8, 2024

lets emulate the view of the Playlists page, toggle left, dropdown right

image

change the icon like its done here

VirtualBoxVM_Q9QR4nuIRH.mp4

@@ -16,6 +18,10 @@ const getters = {

getHistoryCacheById(state) {
return state.historyCacheById
},

getSortOrder(state) {
Copy link
Member

Choose a reason for hiding this comment

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

Getters, mutations and actions are global in the store, please use namespaced names whenever possible (tells other developers where it comes from and avoids name conflicts).

Suggested change
getSortOrder(state) {
getHistorySortOrder(state) {

@@ -109,6 +124,11 @@ const mutations = {
state.historyCacheSorted = historyCacheSorted
},

setSortOrder(state, order) {
state.useAscendingOrder = order
return state.useAscendingOrder
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary return.

Suggested change
return state.useAscendingOrder

@@ -109,6 +124,11 @@ const mutations = {
state.historyCacheSorted = historyCacheSorted
},

setSortOrder(state, order) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
setSortOrder(state, order) {
setHistorySortOrder(state, order) {

Comment on lines +202 to +205
getIconForSortPreference: (s) => getIconForSortPreference(s),
...mapActions([
'selectSort'
])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
getIconForSortPreference: (s) => getIconForSortPreference(s),
...mapActions([
'selectSort'
])
getIconForSortPreference,
...mapMutations([
'setHistorySortOrder'
])

historyCacheSorted: function () {
return this.$store.getters.getHistoryCacheSorted
return this.sortOrder === SORT_BY_VALUES['DateAddedNewest'] ? this.$store.getters.getHistoryCacheSorted : this.$store.getters.getHistoryCacheSorted.toReversed()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return this.sortOrder === SORT_BY_VALUES['DateAddedNewest'] ? this.$store.getters.getHistoryCacheSorted : this.$store.getters.getHistoryCacheSorted.toReversed()
return this.sortOrder === SORT_BY_VALUES.DateAddedNewest ? this.$store.getters.getHistoryCacheSorted : this.$store.getters.getHistoryCacheSorted.toReversed()

Comment on lines +45 to +53
async selectSort({ commit }, sort) {
try {
const order = sort
commit('setSortOrder', order)
} catch (errMessage) {
console.error(errMessage)
}
},

Copy link
Member

Choose a reason for hiding this comment

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

As this action is just a plain wrapper, there isn't any benefit to using it compared to just calling the mutation directly, so it's better to just call the mutation directly in this case.

Suggested change
async selectSort({ commit }, sort) {
try {
const order = sort
commit('setSortOrder', order)
} catch (errMessage) {
console.error(errMessage)
}
},

Comment on lines +1 to +4
export const SORT_BY_VALUES = {
DateAddedNewest: 'newestFirst',
DateAddedOldest: 'oldestFirst',
}
Copy link
Member

Choose a reason for hiding this comment

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

Please move this constant into the src/constants.js file and add HISTORY to its name (not worth creating a new file for a single constant, especially when we already have a file for constants that are used in multiple places).


const state = {
historyCacheSorted: [],
useAscendingOrder: SORT_BY_VALUES['DateAddedNewest'],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
useAscendingOrder: SORT_BY_VALUES['DateAddedNewest'],
useAscendingOrder: SORT_BY_VALUES.DateAddedNewest,

@@ -10,6 +11,9 @@ import FtInput from '../../components/ft-input/ft-input.vue'
import FtAutoLoadNextPageWrapper from '../../components/ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
import FtToggleSwitch from '../../components/ft-toggle-switch/ft-toggle-switch.vue'
import { ctrlFHandler } from '../../helpers/utils'
import { mapActions } from 'vuex'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import { mapActions } from 'vuex'
import { mapMutations } from 'vuex'

@@ -270,6 +270,10 @@ History:
Empty Search Message: There are no videos in your history that match your search
Search bar placeholder: "Search in History"
Case Sensitive Search: Case Sensitive Search
Sort By:
Sort By: Sort By
Copy link
Member

Choose a reason for hiding this comment

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

We really need to deduplicate this string, as this pull request will add the 6th Sort By string/text, I'll do a separate pull request for that though.

Copy link
Author

@jlvivero jlvivero Dec 27, 2024

Choose a reason for hiding this comment

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

do I

  • leave it like this for now then?
  • hard code the string for now (since this string doesn't have translation yet for this specific instance anyways?)
  • maybe reference another string for now?

Copy link
Member

Choose a reason for hiding this comment

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

I've opened #6495 to deduplicate the strings, if you are willing to wait until that pull request is merged and rebase, you'll be able to use the Global.Sort By string that that pull request adds.

Copy link
Author

Choose a reason for hiding this comment

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

I don't mind, since it's the holidays haven't had time to finish my changes, so I can wait and rebase

@absidue absidue changed the title Sortbydate Sort by date on the history page Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants