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

Update: Thumbnails sidebar images #887

Merged

Conversation

ConradJChan
Copy link
Contributor

thumbnails sidebar images

Tests to follow

src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/VirtualScroller.js Outdated Show resolved Hide resolved
src/lib/VirtualScroller.js Outdated Show resolved Hide resolved
src/lib/VirtualScroller.js Show resolved Hide resolved
src/lib/VirtualScroller.js Outdated Show resolved Hide resolved
src/lib/viewers/doc/DocBaseViewer.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Outdated Show resolved Hide resolved
src/lib/ThumbnailsSidebar.js Show resolved Hide resolved
src/lib/viewers/doc/_docBase.scss Outdated Show resolved Hide resolved
@@ -134,6 +153,7 @@ class VirtualScroller {
*/
bindDOMListeners() {
this.scrollingEl.addEventListener('scroll', this.throttledOnScrollHandler, { passive: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

These are both bound to the scroll event but one is an end handler and the other is just a handler. scroll fires on scroll end?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah one is a throttled scroll handler which will be used to render the placeholder thumbnails. The debounced scroll handler is for when scrolling has finished so we can determine which thumbnail images to render

// and what needs to be rendered
const { startOffset: curStartOffset, endOffset: curEndOffset } = this.getInfo();

if (curStartOffset === offset) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we haven't hit our maxRenderedItems? Even if we're starting from the same place could we want to render additional stuff? This might not be an issue now, but if we later add resizing maybe more thumbnails could be visible after a resize but we're still starting from the same spot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well right now we always try to render maxRenderedItems unless it surpasses the totalItems so this seems to be ok. I'll keep an eye on it when we get to the resize stuff

src/lib/VirtualScroller.js Show resolved Hide resolved
src/lib/VirtualScroller.js Outdated Show resolved Hide resolved
src/lib/VirtualScroller.js Outdated Show resolved Hide resolved
margin: THUMBNAIL_MARGIN,
renderItemFn: this.createPlaceholderThumbnail,
onScrollEnd: this.generateThumbnailImages,
onInit: this.generateThumbnailImages
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor, but the name makes it seem like this should be passed into the constructor.

* The newList element is modified.
*
* @param {HTMLElement} newList - the new `li` element
* @param {Array<HTMLElement>} oldList - the children of the old `li` element
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor, but it seems inconsistent to have newList represent a parent ol, but oldList is the children of the old ol. It also looks like the comments may need to be corrected from li -> ol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this consistent now

@ConradJChan
Copy link
Contributor Author

I'll add unit tests in a follow up PR, I just made the existing tests pass for now

@ConradJChan ConradJChan merged commit 650f2d3 into box:thumbnails-sidebar Jan 10, 2019
@ConradJChan ConradJChan deleted the thumbnails-sidebar-images branch January 10, 2019 00:37
ConradJChan pushed a commit that referenced this pull request Feb 1, 2019
Now cuts thumbnail images to insert into sidebar.

Current approach as to *when* to render thumbnail images is to introduce a `onScrollEnd` callback from the `VirtualScroller` so that when scrolling ends, we look at what list items are rendered and then ask PDFJS to generate the thumbnail image.

The `VirtualScroller` `renderItemFn` is invoked by a throttled scroll event handler which is used to create a placeholder thumbnail which includes the page number indicator
ConradJChan pushed a commit that referenced this pull request Feb 5, 2019
Now cuts thumbnail images to insert into sidebar.

Current approach as to *when* to render thumbnail images is to introduce a `onScrollEnd` callback from the `VirtualScroller` so that when scrolling ends, we look at what list items are rendered and then ask PDFJS to generate the thumbnail image.

The `VirtualScroller` `renderItemFn` is invoked by a throttled scroll event handler which is used to create a placeholder thumbnail which includes the page number indicator
ConradJChan pushed a commit to ConradJChan/box-content-preview that referenced this pull request Feb 19, 2019
Now cuts thumbnail images to insert into sidebar.

Current approach as to *when* to render thumbnail images is to introduce a `onScrollEnd` callback from the `VirtualScroller` so that when scrolling ends, we look at what list items are rendered and then ask PDFJS to generate the thumbnail image.

The `VirtualScroller` `renderItemFn` is invoked by a throttled scroll event handler which is used to create a placeholder thumbnail which includes the page number indicator
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.

3 participants