david-allison / manx-corpus-search

MIT License
2 stars 1 forks source link

Add Time increment buttons #196

Closed lauterb closed 2 months ago

lauterb commented 2 months ago
lauterb commented 2 months ago

Conflicts. Think I need to rebase

lauterb commented 2 months ago

Either of these sort of works for validation when the times are numbers, kind of slightly prefer the set to 0 version, it's a bit more intuitive when typing. Should maybe also check for less than zero or greater than the duration.

const validNum = (value: number ) => isNaN(value) ? 0 : value
    const onSChange = (e: React.ChangeEvent<HTMLInputElement>) => {
        setStartTime(validNum(parseFloat(e.target.value)))
    }
    const onEChange = (e: React.ChangeEvent<HTMLInputElement>) => {
        const newVal = parseFloat(e.target.value)
        setEndTime(val=> !isNaN(newVal) ? newVal : val )
lauterb commented 2 months ago

Now I remember since I just retried it that trying to format like this

<input type={"number"} step={"0.01"} value={startTime.toFixed(2)} onChange={onSChange}/>

gives some weird slightly counterintuitive behavior when typing.

lauterb commented 2 months ago

In the stored-as-a-number version without formatting I can also get this kind of stuff when I decrement

Nedecimal
lauterb commented 2 months ago

We can go with formatting, but then the user has to highlight the part they want to change to be able to type properly.

Nedhighlight
lauterb commented 2 months ago

Okay, tinkered some more and reasonably happy with this version. Waiting for the test to pass.

lauterb commented 2 months ago

Still some tiny bit of weirdness about re-rendering when Nan that I will try not to worry about. See also https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/

lauterb commented 2 months ago

It actually returns an empty string if it doesn't like something but doesn't re-render when I try to set the value

NedMinus
lauterb commented 2 months ago

Ah, I can force a re-render by returning a string with a blank in it, " "

lauterb commented 2 months ago

image One key thing is rounding the number as above, instead of formatting at display time or not rounding at all.

lauterb commented 2 months ago

I don't think anyone wants 3dp

If somebody wants more or less we can always make another number input box to set the precision.