Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why not use
getAnswerGiven
(in the main instance class, here h5p-crossword.js) that's defined in the H5P question type contract and that should be implemented in most content types? It is supposed to provide logic that tells you whether an answer was given by the user. No need to check how that specific information can be retrieved by a content type and then needing to add extra implementation togetCurrentState
for every content type. That might help to keep this handling uniform across content types, easier to change later on.The one thing that would not be covered is if when the user added an answer but then wiped the slate clean again -
getAnswerGiven
would still returntrue
. Don't know what exactly the rules are here ...Why are you checking for the focus position here? Does setting focus also count as relevant for the restart button? One can well argue: yes. Just want try to find out what the non-written guideline is.
And a little nitpicking now:
if (cells.every((item) => item === undefined))
feels easier to understand without a double negation. Make thatif (!cells.some((item) => item !== undefined))
if you want to exit early without having to always traverse all the items.A comment would also be helpful, as this expected behavior in not obvious IMHO, cmp. otacke/h5p-sort-paragraphs@03785a6
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.
If the user, for example, moves to a slide in course presentation, then that interaction should be restored on page refresh and
getAnswerGiven
does not help us in this case. It also would forever return true even if the user deletes the input so, for consistency, we're going with a custom approach for every content type library.It would have been nice to have dealt with this only once in a top level library but such a solution has not presented itself. :)
It's part of the to be restored user input just like how moving to a new slide is in CP.
It might be considered a bit overzealous but it's useful for accessibility reasons.
cells.every
would iterate through all entries and that isn't required.Array.find stops iterating & returns the first item that satisfies the given condition.
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.
Sorry, I fail to see what
getAnswerGiven
in Crossword has to do with CoursePresentation. But yes,getAnswerGiven
in CoursePresentation may not be what you're looking for there. And again: There's no publicly available documentation, and I don't know the hard rules that should determine whether that H5P.com restart button should show or not. That's why I asked about the focus, for instance. If the requirement is just some letter entered into the grid or text input fields, then that is whatgetAnswerGiven
will tell you here.I listed
cells.every
as a way to prevent double negation and to make the code clearer as mentioned, not to speed things up, andcells.some
as an alternative tocells.every
- also more clear thanfind
, but with the same traversal logic that doesn't necessarily look at all the items.