-
Notifications
You must be signed in to change notification settings - Fork 716
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
PDF renderer completion fixes #8937
Conversation
@@ -323,8 +325,9 @@ | |||
// TODO: there is a miscalculation that causes a wrong position change on scale | |||
this.savePosition(this.calculatePosition()); | |||
|
|||
// determine how many pages user has viewed/visited | |||
let currentPage = parseInt(this.currentLocation * this.totalPages) + 1; | |||
// determine how many pages user has viewed/visited; fix edge case of 2 pages |
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.
What was the edge case here for 2 pages? Seems like both 1 and 2 are edge cases, which seems odd.
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.
My thought here is that the subsequent progress_delta fix might also fix this issue
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.
Ah, yes, it would make sense that it was both 1 and 2, but I didn't have a PDF that was only 1 page.
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.
Hmm, no, that doesn't seem to fix it. When there are two pages in the pdf, currentPage
seems to be constantly set to 1 because parseInt(this.currentLocation * this.totalPages)
always ends up at 0
because this.currentLocation
doesn't get high enough.
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.
Hrm - my I am curious why that is specific to 2 page PDFs, and why on a 3 page PDF '2' does become a currentPage at some point, makes me think there might be something slightly off about our currentLocation calculation.
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.
(this is just curiosity, not a blocker)
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.
Hello sir @rtibbles, I spent my time learning about the rendering of PDFs in Kolibri. I tried to understand the files LearnImmersivelayout
, LearningActivityBar
, ProgressIcon
etc. If I am not wrong the PDFs are rendered here on a canvas. I have a doubt, about how can we track the current page from the rendered canvas? , I think if we get to know which page the user is at then we can fix the ProgressIcon
not updating bug.
(I will try to research more about PDF.js to understand this problem more)
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.
We don't render every page at once (as this causes performance issues for larger PDFs) so we know which pages are currently rendered, and control that based on where the user is.
The component you linked to controls the rendering of a single page - it is then used inside a RecycleList
component that handles only actually rendering the pages that are visible by the user at the current time: https://github.com/learningequality/kolibri/blob/develop/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue#L47
It's in ^ this component that the progress tracking logic is happening, this is where the fix would almost certainly need to be.
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.
Hi @rtibbles and @sairina, thanks for all your help I found a solution but I am not sure it is correct.
Let me explain what I came up with...
In the <progressIcon>
we have a prop called "progress".
The value of "progress" determines the state of <progressIcon>
In React we use a hook useEffect
which lets you perform side effects in function components (I am new to vue.js so I don't know what features we have in vue.js, we can use something like that).
My Idea is when we scroll we can keep on updating the "progress" value maybe from the PdfRendererIndex.vue
(not sure from where) something like:
console output:
> 0.638
> 0.639
> 0.640
> 0.641
> 0.642
(this output is a simple console log of an onScroll event, all I wanted to show is my idea)
but I don't know how we can access the value of "this.progress" when we scroll
In the end when the "progress" value is equal to 1
. we can change the isComplete
value to True
and isInProgress
value to False
(I think, this part already exists in the code).
Thank you for reading this, please tell me if wrong, I will search for another way to fix it. Or maybe it's just a small bug that I need to find and don't need all the stuff I mentioned above (sorry 😛)
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.
Ooh, I never even considered looking at ProgressIcon
! @rtibbles would probably know more about whether this is the right way to go in terms of efficiency, but if you want to explore it a bit more (if you haven't already):
progress
is a prop, and its value is coming from thecontentProgress
prop in theLearningActivityBar
componentcontentProgress
is a computed prop coming fromcontentNodeProgress
in theLearnImmersiveLayout
componentuseContentNodeProgress.js
is where this is housed. It's called a composable, which is pretty similar to a React hook, you can see it in the code throughsetup()
and one of the difference between this and React hooks is that it is only run once (I believe).- you can see it in use in the
ProgressBar
and also in theLearnImmersiveLayout
- you can see it in use in the
Summary
References
Fixes #8868
Reviewer guidance
Testing checklist
PR process
Reviewer checklist
yarn
andpip
)