-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Created custom hook for lockout to be usable across the applicat…
…ion.
- Loading branch information
1 parent
b97abe0
commit 3730ab6
Showing
3 changed files
with
52 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Gridiron Survivor. | ||
// Licensed under the MIT License. | ||
|
||
import { useEffect, useState } from 'react'; | ||
|
||
/** | ||
* Function to constantly check the current time every hour and set the lockout accordingly. | ||
* @returns - The value of lockedOut. | ||
*/ | ||
const useLockout = (): boolean => { | ||
const [lockedOut, setLockedOut] = useState<boolean>(false); | ||
useEffect(() => { | ||
/** | ||
* Checks if the user is locked out from making a pick. | ||
*/ | ||
const checkLockout = (): void => { | ||
const currentDateAndTime = new Date(); | ||
const day = currentDateAndTime.getUTCDay(); | ||
const hours = currentDateAndTime.getUTCHours(); | ||
if ( | ||
(day === 5 && hours >= 0) || // Friday at 12am UTC (Thurs 8pm CT) | ||
day > 5 || // Friday and Saturday | ||
day === 0 || // Sunday | ||
day === 1 || // Monday | ||
(day === 2 && hours < 12) // Tuesday at 12pm UTC (8am CT) | ||
) { | ||
setLockedOut(true); | ||
} else { | ||
setLockedOut(false); | ||
} | ||
}; | ||
|
||
checkLockout(); | ||
|
||
const intervalId = setInterval(checkLockout, 60 * 60 * 1000); | ||
|
||
return (): void => clearInterval(intervalId); | ||
}, []); | ||
|
||
return lockedOut; | ||
}; | ||
|
||
export default useLockout; |