-
Notifications
You must be signed in to change notification settings - Fork 153
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
base: develop
Are you sure you want to change the base?
Conversation
@@ -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)); |
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 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); |
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.
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]; |
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.
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) { |
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.
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.
Fixes #2500