-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Desktop: Added arrows to go front and back through note history #2563
Conversation
Note: we don't review incomplete PRs. |
Hi @naviji and welcome to the Joplin-Community. I saw your PR in the forum and was interested. So I just want to bring up my opinion about the position of the arrows. (I'm no designer nor developer) But I think the arrows shouldn't be placed there for some reason
A suggestion could be - in my opinion - next to the search bar as this functions are somewhat related (I search for a note and want to go back to the previous) Thanks anyway and the last word belongs to @laurent22 and @PackElend |
@naviji I think you should squash your commits into fewer commits |
@Rishgod Yes, I'll do that. But I want to wait until I get a review first. |
@laurent22 I've implemented all the functionality requested in the issue. Please take a look. |
It's a bit hard to follow the PR and I don't understand what "preHistoryNotes" means. History is always "previous" by definition. As you've noticed there's also already an "historyNotes" state so I'm concerned we might be duplicating state here. Could you explain your reasoning please? |
Sorry. I should have named it better. My reasoning was that as you go backwards, the previous notes in historyNotes gets pushed into this stack so that you can go forward. Hence "prevHistoryNotes". https://stackoverflow.com/questions/6869476/how-to-implement-back-and-forward-functionality-like-browser Should I rename it like this? |
Thanks for the explanation @naviji, it makes sense. Based on the link you've provided and explanation, please could you rename it like below? historyNotes => backwardHistoryNotes |
Add forward and backward jumps through note list Note history updated when notes deleted Fixed note history when searching Rename historyNotes to backwardHistoryNotes, prevHistoryNotes to forwardHistoryNotes Removed invalid formatting
I did the renaming. I also did a rebase and squashed everything (Which maybe wasn't a good idea). |
I've refactored the code. It should be more readable now. @laurent22 |
Yes, before this feature can be merged, there should be full tests added. For example,
|
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.
Thanks for the update @naviji. The code is well written and I didn't notice any big issue. Could you also please add the tests as asked by @mic704b?
ReactNativeClient/lib/reducer.js
Outdated
|
||
if (JSON.stringify(newState.selectedNoteIds) === JSON.stringify(noteIds)) return newState; | ||
|
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.
Could you explain the logic here please? For me it means "if the selection hasn't changed, return the modified state", which is no logical. If nothing has changed, we should return the same state (i.e. the state
variable).
But maybe it's an incorrect copy/paste from the previous code and you have something else in mind.
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.
It should just be return newState
JSON.stringify(newState.selectedNoteIds) === JSON.stringify(noteIds)
will always be true since I am assigning newState.selectedNoteIds = noteIds
before the if condition.
I removed if (JSON.stringify(newState.selectedNoteIds) === JSON.stringify(noteIds)) return state;
because of this situation:
Suppose we are in note1. We then search for note1 again. Now when we press the back button,
JSON.stringify(newState.selectedNoteIds) === JSON.stringify(noteIds)
will be true and the old state will be returned without doing the pop operation.
The history operations should be performed irrespective of JSON.stringify(newState.selectedNoteIds) === JSON.stringify(noteIds)
Add skeleton integration test
btw how can I understand pop, goto is clear, push can makes sense, how to explain pop? |
Ok all good now, thanks @naviji! |
@PackElend Look at this post. |
@naviji I haven't reviewed the code, but I was wondering what the limit was. e.g. I have Joplin running for weeks before I install a new version and restart. What would happen, if I switched between 100,000 notes in that time? Just an exaggeration, but you'll see where I'm going with this. Will it really add 100,000 entries onto a stack? Also, is there some sort of optimization? e.g. if I switched between 2 notes for a few (N) times, would only be those 2 notes on the stack, or the notes * N switches? |
@@ -104,6 +105,20 @@ stateUtils.lastSelectedNoteIds = function(state) { | |||
return output ? output : []; | |||
}; | |||
|
|||
stateUtils.getLastSeenNote = function(state) { |
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.
More generally, it gets the current note
}; | ||
} | ||
} | ||
}; |
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.
Missing explicit return for when no note found
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.
Good catch, and that makes me think I'll add an eslint rule for explicit returns as I believe there's one.
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.
Sounds good. The eqeqeq
rule might be worth a look too.
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.
Yes, I didn't include it because when I started I didn't always use ===
and I'm concerned that changing everything to it now might create subtle bugs. New code should indeed use strict equality/inequality. Might still be worth reviewing at some point if we can enable it though.
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.
So no explicit return statement is bad style. Got it.
|
||
// Update history when searching |
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.
Missing test
@mic704b the code has already been merged |
My mistake, I missed that. |
BTW there is also an issue if an un-selected note is deleted. |
It's strange it lets me enter new review comments after merge |
Those are good points regardless. @naviji, please could you check Mic's comments and see if you can address them? |
I guess we could limit the history to 100 notes or so, what you think @naviji?
When I've tested I noticed that it would keep pushing the notes on the stack. That could be improved, for example by having a function that detects sequences in the history and remove successive duplicates, but it could be for another PR |
I think 1,000 would be fine too. Not that someone would really go back 1,000 notes. I only meant that there should be a limit. I actually don't really care what it is. For me 20 is probably enough, others might need more. 50, 100, 250. I'm fine with any number.
A new PR is perfectly fine. It also allows for another |
@mic704b
I think anything is fair game as long as the issue hasn't been locked. But even then collaborators can add/edit comments. |
@naviji whatever you do, do not use this branch. Please work off a new branch from the latest git master |
@mic704b How can I replicate it?
@laurent22 Firefox has a default value of 50 for its back button. I'd say 250 is more than enough.
@tessus Firefox and google chrome do no such optimization when clicking between two links repeatedly. I think it wouldn't be worth the trouble. |
Maybe we should use less then?
Well, we have a slight problem though. Our situation is different than on browsers. As soon as a we switch to a different notebook, a note is always selected automatically. Therefore the list we build has potentially notes in there, which we actually do not want. But this is probably not something we can fix. |
Observed: Expected: |
Neither can I anymore! I should have noted the commit number. Sorry. |
Is it possible to link these buttons to the back and forward buttons of my mouse? |
Add forward and backward arrows to go through note history.
#2409