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

Desktop: Added arrows to go front and back through note history #2563

Merged
merged 19 commits into from
Mar 15, 2020
Merged

Desktop: Added arrows to go front and back through note history #2563

merged 19 commits into from
Mar 15, 2020

Conversation

naviji
Copy link
Contributor

@naviji naviji commented Feb 23, 2020

Add forward and backward arrows to go through note history.

ezgif com-video-to-gif

#2409

@laurent22
Copy link
Owner

Note: we don't review incomplete PRs.

@naviji naviji changed the title Desktop: Added arrows to go front and back through note links Desktop: Added arrows to go front and back through note history Feb 24, 2020
@ghost
Copy link

ghost commented Feb 24, 2020

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

  • In the viewer mode there is no need for a toolbar (there is also an issue for that) and without toolbar no going forwards and backwards in the viewer mode
  • this is a toolbar so I would expect clicking this button that some markdown magic is inserted

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 naviji requested a review from laurent22 February 25, 2020 19:19
@Rishabh-malhotraa
Copy link
Contributor

@naviji I think you should squash your commits into fewer commits

@naviji
Copy link
Contributor Author

naviji commented Feb 26, 2020

@Rishgod Yes, I'll do that. But I want to wait until I get a review first.

@naviji
Copy link
Contributor Author

naviji commented Feb 26, 2020

@laurent22 I've implemented all the functionality requested in the issue. Please take a look.

@laurent22
Copy link
Owner

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?

@naviji
Copy link
Contributor Author

naviji commented Feb 27, 2020

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
historyNotes is the back stack and prevHistoryNotes is the next stack in this recipe. The two stacks have different uses. One keeps track of where to go back. And the other where to go forward. So there is no duplicate state.

Should I rename it like this?
historyNotes -> previousNotes
prevHistoryNotes -> nextNotes

@laurent22
Copy link
Owner

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
prevHistoryNotes => forwardHistoryNotes

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
@naviji
Copy link
Contributor Author

naviji commented Feb 28, 2020

I did the renaming. I also did a rebase and squashed everything (Which maybe wasn't a good idea).
Should I add some tests or additional comments?

@naviji
Copy link
Contributor Author

naviji commented Mar 1, 2020

I've refactored the code. It should be more readable now. @laurent22

@miciasto
Copy link
Contributor

miciasto commented Mar 3, 2020

Should I add some tests

Yes, before this feature can be merged, there should be full tests added.

For example,

  • For the reducer handleItemDelete and changeSelected folder, there should be unit tests added to the reducer.js unit test file.

  • For HistoryHelper there should be unit tests added to new services_HistoryHelper.js file. (Actually is this really a service? may be this will end up elsewhere)

  • For the changes to reducer function itself, and overall feature testing, there should be new integration feature tests created in integration_ForwardBackwardNoteHistory.js.

Copy link
Owner

@laurent22 laurent22 left a 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?

Comment on lines 343 to 345

if (JSON.stringify(newState.selectedNoteIds) === JSON.stringify(noteIds)) return newState;

Copy link
Owner

@laurent22 laurent22 Mar 5, 2020

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.

Copy link
Contributor Author

@naviji naviji Mar 6, 2020

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)

@PackElend
Copy link
Collaborator

There's only one case where it's "pop"

btw how can I understand pop, goto is clear, push can makes sense, how to explain pop?

@laurent22
Copy link
Owner

Ok all good now, thanks @naviji!

@laurent22 laurent22 merged commit d049b88 into laurent22:master Mar 15, 2020
laurent22 added a commit that referenced this pull request Mar 15, 2020
…ough note history (#2563)"

Fixing merge issue...

This reverts commit d049b88.
@naviji
Copy link
Contributor Author

naviji commented Mar 15, 2020

There's only one case where it's "pop"

btw how can I understand pop, goto is clear, push can makes sense, how to explain pop?

@PackElend Look at this post.
push and pop refer to what action needs to take place on the backStack.

@naviji naviji deleted the jump-notes branch March 15, 2020 14:32
@tessus
Copy link
Collaborator

tessus commented Mar 17, 2020

@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) {
Copy link
Contributor

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

};
}
}
};
Copy link
Contributor

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

Copy link
Owner

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.

Copy link
Contributor

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.

Copy link
Owner

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.

Copy link
Contributor Author

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.

Comment on lines +795 to +796

// Update history when searching
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing test

@tessus
Copy link
Collaborator

tessus commented Mar 17, 2020

@mic704b the code has already been merged

@miciasto
Copy link
Contributor

@mic704b the code has already been merged

My mistake, I missed that.

@miciasto
Copy link
Contributor

BTW there is also an issue if an un-selected note is deleted.

@miciasto
Copy link
Contributor

@mic704b the code has already been merged

My mistake, I missed that.

It's strange it lets me enter new review comments after merge

@laurent22
Copy link
Owner

Those are good points regardless. @naviji, please could you check Mic's comments and see if you can address them?

@laurent22
Copy link
Owner

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?

I guess we could limit the history to 100 notes or so, what you think @naviji?

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?

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

@tessus
Copy link
Collaborator

tessus commented Mar 17, 2020

I guess we could limit the history to 100 notes or so, what you think @naviji?

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.

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

A new PR is perfectly fine. It also allows for another good first issue. I just wanted to bring this up, that's all.

@tessus
Copy link
Collaborator

tessus commented Mar 17, 2020

@mic704b

It's strange it lets me enter new review comments after merge

I think anything is fair game as long as the issue hasn't been locked. But even then collaborators can add/edit comments.

@tessus
Copy link
Collaborator

tessus commented Mar 18, 2020

@naviji whatever you do, do not use this branch. Please work off a new branch from the latest git master

@naviji
Copy link
Contributor Author

naviji commented Mar 18, 2020

BTW there is also an issue if an un-selected note is deleted.

@mic704b How can I replicate it?

we could limit the history to 100 notes or so,

@laurent22 Firefox has a default value of 50 for its back button. I'd say 250 is more than enough.

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?

having a function that detects sequences in the history and remove successive duplicates

@tessus Firefox and google chrome do no such optimization when clicking between two links repeatedly. I think it wouldn't be worth the trouble.

@tessus
Copy link
Collaborator

tessus commented Mar 19, 2020

@naviji

I'd say 250 is more than enough.

Maybe we should use less then?

Firefox and google chrome do no such optimization when clicking between two links repeatedly. I think it wouldn't be worth the trouble.

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.
However, I think this PR caused another issue: #2803

@miciasto
Copy link
Contributor

miciasto commented Mar 19, 2020

How can I replicate it?

  1. Make a folder with some notes
  2. Navigate through them to make some history
  3. Select a note
  4. Right-click another note in the list and delete it (but do not select it)
  5. Use the back button to step backwards through the history

Observed:
When you navigate back over where the note was, the focus disappears completely, as if we have navigated to a hidden note.

Expected:
The navigation should skip the missing note and jump to the next on in the history.

@naviji
Copy link
Contributor Author

naviji commented Mar 20, 2020

@mic704b
I can't replicate it.
5e747d5269eff010901835

@miciasto
Copy link
Contributor

miciasto commented Mar 22, 2020

I can't replicate it.

Neither can I anymore! I should have noted the commit number. Sorry.

@steenstra
Copy link

Is it possible to link these buttons to the back and forward buttons of my mouse?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants