Skip to content

Commit

Permalink
FOCUS_DELAY_SECONDARY (because multiple places 🤦‍♂️)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarrenSem authored Jul 17, 2023
1 parent d8ba4e7 commit 158a88a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const LABEL_REMOVE = index => `Remove ${ordinal(index + 1)} place`;
const LABEL_APPEND = "Add new place to bottom of list";
const FOCUS_DELAY_DEFAULT = 4;
const FOCUS_DELAY_SECONDARY = FOCUS_DELAY_DEFAULT + 250;
const APP_KEY = "prize-pool-chop-minus-5%";

const zero_our = (_ = [
Expand Down Expand Up @@ -46,26 +47,26 @@
const focusIndex = (index, delay) => setTimeout( () => inputRefs.current[index]?.focus(), delay || FOCUS_DELAY_DEFAULT );

const insertNewPlace = () => {
focusIndex(0, FOCUS_DELAY_DEFAULT + 250);
focusIndex(0, FOCUS_DELAY_SECONDARY);
setPlaces(["", ...places]);
};

const removePlace = (index) => {
const newPlaces = [...places];
newPlaces.splice(index, 1);
focusIndex(index, FOCUS_DELAY_DEFAULT + 1);
focusIndex(index, FOCUS_DELAY_SECONDARY);
setPlaces(newPlaces);
};

const appendNewPlace = () => {
focusIndex(places.length, FOCUS_DELAY_DEFAULT + 1);
focusIndex(places.length, FOCUS_DELAY_SECONDARY);
setPlaces([...places, ""]);
};

const updatePlace = (index, value) => {
const newPlaces = [...places];
newPlaces[index] = value <= 0 ? 0 : Number(value);
focusIndex(index, FOCUS_DELAY_DEFAULT + 1);
focusIndex(index, FOCUS_DELAY_SECONDARY);
setPlaces(newPlaces);
};

Expand Down

0 comments on commit 158a88a

Please sign in to comment.