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

Allow setting of scroll position based on browser history state. #5006

Merged

Conversation

rtibbles
Copy link
Member

@rtibbles rtibbles commented Feb 11, 2019

Summary

Monitors CoreBase scrolling, and uses that information to update window.pageYOffset to update the history state.
Sets a vuex state element to indicate the desired starting scroll position for the core base - this might be better implemented as an event, but this was easier.
CoreBase adds a watcher to this vuex state in the created property to set the scrollTop to this value when the router has set it.

Reviewer guidance

Does it provide the intended scrolling behaviour?
Could this be implemented in a better way? In what way might this be brittle?

scrollmedo

References

Fixes #3659


Contributor Checklist

PR process:

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Testing:

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

Reviewer Checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.rst

@rtibbles rtibbles added the TODO: needs review Waiting for review label Feb 11, 2019
@rtibbles rtibbles added this to the 0.12.0 milestone Feb 11, 2019
@codecov
Copy link

codecov bot commented Feb 11, 2019

Codecov Report

❗ No coverage uploaded for pull request base (release-v0.12.x@4606cb3). Click here to learn what that means.
The diff coverage is 38.09%.

Impacted Files Coverage Δ
...ri/core/assets/src/state/modules/core/mutations.js 47.05% <100%> (ø)
kolibri/core/assets/src/router.js 38% <25%> (ø)
kolibri/core/assets/src/views/CoreBase/index.vue 43.29% <37.5%> (ø)

ralphiee22
ralphiee22 previously approved these changes Feb 11, 2019
Copy link
Contributor

@ralphiee22 ralphiee22 left a comment

Choose a reason for hiding this comment

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

Works great for coach pages, but not really for other pages. But hey, some working is better than none working?!

CoreBase is not reinitialized on navigation.
@rtibbles rtibbles dismissed ralphiee22’s stale review February 11, 2019 21:27

I updated behaviour after this review was submitted, so probably needs re-review!

@jonboiser
Copy link
Contributor

Is the scroll position supposed to be unique for each page? The current behavior seems to apply the same position to the previous page even if the position was set at an even earlier page. For example

  1. On Page A I go down 200 pixels, then click a link to Page B.
  2. On Page B I do not scroll, but click into Page C
  3. At Page C, I go back to Page B (where I did not scroll). On Page B, I am now down 200 pixels.
  4. I go back to Page A and have a Y position of 0 pixels (when it was 200 at the first step)

@rtibbles
Copy link
Member Author

Hrm, good point - need to clear the vuex data when leaving a page, so that it is only set from the history state.

@rtibbles
Copy link
Member Author

Or rather, not the vuex state, but the window offset value - if you navigate to pages without ever scrolling, that doesn't get reset.

// Create a watcher to monitor changes in loading
// to try to set the scrollHeight after the contents
// have loaded.
this.unwatchScrollHeight = this.$watch('loading', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if unwatchScrollHeight should be defined on data and initialized to undefined for explicitness? Seems a little weird to just slap it onto the view model.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? It doesn't need to be reactive, putting it on the view itself is exactly the right place for it, the only thing that might be better is prefixing it with an underscore, but I really don't see any benefit to having it be a watched bit of internal state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah agreed – I don't like the fact that it's reactive either. The thing that bothered me is to add it to the vm namespace without declaring it anywhere.

There's a lively discussion here so apparently this is something that keeps people up at night :)

Looks like the original strategy you used is likely fine, and another common pattern is to put it inside $options

Copy link
Member Author

Choose a reason for hiding this comment

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

I do find it a little odd that the github issue is so long. Either you put it in a namespace, or you put it right on the object. Vue doesn't, and shouldn't care!

Copy link
Contributor

@indirectlylit indirectlylit left a comment

Choose a reason for hiding this comment

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

added 1a27eb6 to your PR

@indirectlylit indirectlylit merged commit 0568516 into learningequality:release-v0.12.x Feb 14, 2019
@rtibbles rtibbles deleted the scroll_position branch February 14, 2019 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants