feat: added functionality to remove saved user preferences#472
Conversation
Changed Files
|
|
There was a problem hiding this comment.
Works well when I test it.
I have some questions, see below.
I didn't dig enough to understand why most instances of this.X had to be replaced by this.userPreferences.X but it works.
I didn't test if we can still change settings in the html as attributes to the read-along element and have them reflected when you load a readalong. Did you exercise that?
Finally, I'm leaving comments but I'm not confident enough to really review, @deltork I'm hoping you'll do a code review too.
| */ | ||
| @Prop({ mutable: true, reflect: true }) scrollBehaviour: ScrollBehaviour = | ||
| "smooth"; | ||
| @Prop() scrollBehaviour: ScrollBehaviour = "smooth"; |
There was a problem hiding this comment.
Took me a while to figure out why this was still used -- it appears to just be the thing that sets the default. Is this also what gets modified if you set it in the HTML?
There was a problem hiding this comment.
Yes, it contains the value passed in the HTML <read-along scroll-behaviour="..." />, if this attribute (or property) is not used, it defaults to "smooth".
Answering the question about this.X vs this.userPreferences.X here also: this.X contains the initial state of the component, either the hard-coded value or the attribute value passed in <read-along />. The previous implementation directly modified this.X overwriting the component's initial state. This refactor makes this.X read-only and it is used only for setting the component's initial state and clearing the users's preferences (see: defaultUserPreferences() where this.X is used) .
| } else if (this.language.match("es") !== null) { | ||
| this.language = "spa"; | ||
| if (prefs.language.length < 3) { | ||
| if (prefs.language.match("fr") != null) { |
There was a problem hiding this comment.
This is weird code. Why not prefs.language !== "fr"? @deltork ? Is this case insensitive?
There was a problem hiding this comment.
This allows the app to support both ISO 639-3 and ISO 639-1 ("fra" and "fr") for maximum compatibility.
There was a problem hiding this comment.
This makes it case insensitive
| if (prefs.language.match("fr") != null) { | |
| if (prefs.language.match(/fr/i) != null) { |
If I'm understanding the use-case correctly something along the lines of? const el = document.getElementById("readalongInstance");
el.scrollBehaviour = "auto";Currently would not work. Neither would this: const el = document.getElementById("readalongInstance");
if(el.scrollBehaviour == "auto") {
...
}In the first case it would take effect only when/if the user performs a "Reset". In the second, the value returned would always reflect the component's initial state and not the current user defined preference. Both can be addressed. Is there an example of this or a test? |
c03c9c8 to
acf6526
Compare
|
What I meant by "setting the attributes" is right in the HTML itself, someone publishing a readalongs could set |
|
Thanks for the changes. Looks good to me, but I'll let Del approve once he's done his review. |
|
Yes, that has been implemented and manually tested. Values passed in HTML become the component's default values when "Reset" is used. |
5a7bd60 to
4e5b399
Compare
|
I have a minor tweak for the settings UI. see #475. |
| } else if (this.language.match("es") !== null) { | ||
| this.language = "spa"; | ||
| if (prefs.language.length < 3) { | ||
| if (prefs.language.match("fr") != null) { |
There was a problem hiding this comment.
This allows the app to support both ISO 639-3 and ISO 639-1 ("fra" and "fr") for maximum compatibility.
| } else if (this.language.match("es") !== null) { | ||
| this.language = "spa"; | ||
| if (prefs.language.length < 3) { | ||
| if (prefs.language.match("fr") != null) { |
There was a problem hiding this comment.
This makes it case insensitive
| if (prefs.language.match("fr") != null) { | |
| if (prefs.language.match(/fr/i) != null) { |
| if (prefs.language.length < 3) { | ||
| if (prefs.language.match("fr") != null) { | ||
| prefs.language = "fra"; | ||
| } else if (prefs.language.match("es") !== null) { |
There was a problem hiding this comment.
| } else if (prefs.language.match("es") !== null) { | |
| } else if (prefs.language.match(/es/i) !== null) { |
There was a problem hiding this comment.
I see some != with just one equal in there, should they not all be !==?
There was a problem hiding this comment.
Could we convert this to a data structure? Regex feels like an over kill and in this case not specific enough (abc_fr_abc would be accepted for French):
const acceptedLanguages = {
"en": "eng",
"eng": "eng",
"fr": "fra",
"fra": "fra",
"es": "spa",
"spa": "spa",
}
prefs.language = acceptedLanguages[prefs.language.toLowerCase()]||"eng";
There was a problem hiding this comment.
That's not quite accurate since the code is in a if block where len<3... which also points to overkill. :)
I like your map, though, seems like a good idea. In Python, [] with an unfound value would raise an exception, here would that return a falsy result instead?
There was a problem hiding this comment.
I see some
!=with just one equal in there, should they not all be!==?
yeh they should be !==
There was a problem hiding this comment.
That's not quite accurate since the code is in a if block where len<3... which also points to overkill. :)
Oops, I assumed there was an else clause hiding in all the short diff blocks. Since there are none, there's no 3-character language validation either. But getI18nString handles the bad language input.
I like your map, though, seems like a good idea. In Python, [] with an unfound value would raise an exception, here would that return a falsy result instead?
That's correct, and the || "eng" returns English in those cases (it does not throw an exception).
There was a problem hiding this comment.
I'll update the language validation code after Del merges PR #475 (which I've just accepted).
8902cd5 to
21491d1
Compare
PR Goal?
Removing stored user preferences required:
this PR adds a "Reset" button to the settings panel that will reset all configurations (including deleting the stored settings).
Fixes?
#462
Feedback sought?
i18n/folder.Also, additional minor improvements to the settings modal window:
Priority?
Medium, non blocker.
Tests added?
Yes
How to test?
Documented steps from the issue #472:
-❗ the web component interface is in Spanish
Other:
Confidence?
High.
Version change?