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

fix readerSettings ranges to match options-values #2504

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

arthur-lemeur
Copy link
Collaborator

Fixes #2500

@@ -390,63 +390,65 @@ interface ITable {

const Slider = ({ value, option, set }: { value: string, option: ITable, set: (a: Pick<ReaderConfig, "pageMargins" | "wordSpacing" | "letterSpacing" | "paraSpacing" | "lineHeight">) => void }) => {
const [currentSliderValue, setCurrentSliderValue] = React.useState(option.defaultValue);
const [currentIndex, setCurrentIndex] = React.useState(() => optionsValues[option.parameter].findIndex((el) => el === option.defaultValue));
Copy link
Member

Choose a reason for hiding this comment

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

This would fail at compile time with TypeScript strictNullChecks (or strict) ... which is not yet activated in this project unfortunately.
I would recommend optionsValues[option.parameter] ==> (optionsValues[option.parameter] || []) and also .findIndex((el) => el === option.defaultValue) ==> .findIndex((el) => el === option.defaultValue) || 0

setCurrentSliderValue(value.replace(/rem/g, ""));
}, [value]);
setCurrentSliderValue(value);
const newIndex = optionsValues[option.parameter].findIndex((el) => el === value);
Copy link
Member

Choose a reason for hiding this comment

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

same remark as above regarding sanity-checking optionsValues[option.parameter] for undefined.

}, [value, option.parameter]);

const updateValue = (index: number) => {
const newValue = optionsValues[option.parameter][index];
Copy link
Member

Choose a reason for hiding this comment

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

Same sanity-checking remark.

set({ [option.parameter]: valueToString + (option.rem ? "rem" : "") } as Pick<ReaderConfig, "pageMargins" | "wordSpacing" | "letterSpacing" | "paraSpacing" | "lineHeight">);
setCurrentIndex((prevIndex) => {
const newIndex = direction === "out" ? prevIndex - 1 : prevIndex + 1;
if (newIndex >= 0 && newIndex < optionsValues[option.parameter].length) {
Copy link
Member

Choose a reason for hiding this comment

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

Same sanity-check workaround here ... unless we can "guarantee" through the TypeScript type system that option.parameter is within bounds of the optionsValues array range.

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.

Version 3 Line Spacing
2 participants