Skip to content

useThisRunStore

This store is responsible for handling the data related to the current run.

📄 View source on GitHub

Used by

State

NameTypeDescription
runDaterefHolds the date of the next (Wednesday's) run
haresPwdrefHolds the password for the hare for the next run (changed weekly)
todaysRunrefHolds the data of the next (Wednesday) run
isHarerefStores if a login is coming from a hare which removes all functionality not allowed
isOnCashrefStores if a login is coming from OnCash which adds the 'Reports' tab to the Sign-In App
runInfoLoadedrefLoading state of todaysRun

Initialization

initializeThisRunsStore 🚀

Initializes the ThisRunStore by loading the state from local storage and attempting to fetch the next Wednesday's run date and the run data for the current run if skipFetch is not set to true.

Actions

persist

Persist the state of the ThisRunStore to the persistent store.

fetchNextWednesday

Fetches the next Wednesday's run date and hare's password. It fetches the data from the /hashes endpoint and updates the runDate and haresPwd states. It also persists the state with the persist method.

setHareFlag

Sets the isHare state to the given value and persists it to the persistent store.

setOnCashFlag

Sets the isOnCash state to the given value and persists it to the persistent store.

fetchThisRunsData

Fetches data for the current run using the backend /members/getsigninjson endpoint. If the runDate is not set, it attempts to fetch the next Wednesday's date and hare's password. If the runDate is still not determined after that, it logs a warning and exits the function. Upon successful data retrieval, it updates the todaysRun and runInfoLoaded states and persists the state to the persistent store. Logs an error if the data cannot be fetched.

setRunDateManually

Manually sets the date for the current run and resets the haresPwd, isHare, isOnCash, and runInfoLoaded states. It then fetches the run data for the given date and persists the state. This supports the backdoor to enter run data using the SignIn-App for historic runs.

Released under the MIT License.