-
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.
- Loading branch information
Showing
11 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,61 @@ | ||
import { collection, doc, getDoc, getFirestore } from "@firebase/firestore" | ||
import { useEffect, useState } from "react" | ||
|
||
export const useTimer = () => { | ||
const [CTIME, setCT] = useState(0) | ||
const [OTIME, setOT] = useState(0) | ||
const [round, setRound] = useState(0) | ||
|
||
useEffect(() => { | ||
if (!localStorage.getItem("CLOSE_T")) { | ||
const getTimer = async () => { | ||
const timerRef = collection(getFirestore(), "configs") | ||
const docData = await getDoc(doc(timerRef, "timers")) | ||
const a = docData.get("REG_CLOSE_TIMESTAMP").toMillis() | ||
const b = docData.get("REG_OPEN_TIMESTAMP").toMillis() | ||
const r = docData.get("COMP_ROUND") | ||
setCT(a) | ||
setOT(b) | ||
setRound(r) | ||
|
||
localStorage.setItem( | ||
"CLOSE_T", | ||
docData.get("REG_CLOSE_TIMESTAMP").toMillis() | ||
) | ||
|
||
localStorage.setItem( | ||
"OPEN_T", | ||
docData.get("REG_OPEN_TIMESTAMP").toMillis() | ||
) | ||
localStorage.setItem("ROUND_C", docData.get("COMP_ROUND")) | ||
} | ||
|
||
getTimer() | ||
} | ||
|
||
const CLOSE_TIMESTAMP = parseInt(localStorage.getItem("CLOSE_T") || "0", 10) | ||
const OPEN_TIMESTAMP = parseInt(localStorage.getItem("OPEN_T") || "0", 10) | ||
setCT(CLOSE_TIMESTAMP) | ||
setOT(OPEN_TIMESTAMP) | ||
setRound(parseInt(localStorage.getItem("ROUND_C") || "0", 10)) | ||
}, []) | ||
|
||
const isClosed = (byPass: boolean | undefined): boolean => { | ||
if (byPass === true) { | ||
return false | ||
} | ||
return new Date().getTime() >= CTIME | ||
} | ||
|
||
const isStarted = () => { | ||
return new Date().getTime() >= OTIME | ||
} | ||
|
||
return { | ||
isStarted, | ||
isClosed, | ||
open: new Date(OTIME), | ||
close: new Date(CTIME), | ||
round | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,52 @@ | ||
const CLOSE_TIMESTAMP = 1873413200000 | ||
export const isClosed = (byPass: boolean | undefined): boolean => { | ||
if (byPass === true) { | ||
return false | ||
export const MONTH = [ | ||
"January", | ||
"February", | ||
"March", | ||
"April", | ||
"May", | ||
"June", | ||
"July", | ||
"August", | ||
"September", | ||
"October", | ||
"November", | ||
"December" | ||
] | ||
|
||
export function pad(num: number | undefined) { | ||
if (num === 0) return "00" | ||
if (!num) return "" | ||
let strNum = num.toString() | ||
while (strNum.length < 2) { | ||
strNum = `0${strNum}` | ||
} | ||
return strNum | ||
} | ||
export const THMONTH = [ | ||
"มกราคม", | ||
"กุมภาพันธ์", | ||
"มีนาคม", | ||
"เมษายน", | ||
"พฤษภาคม", | ||
"มิถุนายน", | ||
"กรกฎาคม", | ||
"สิงหาคม", | ||
"กันยายน", | ||
"ตุลาคม", | ||
"พฤศจิกายน", | ||
"ธันวาคม" | ||
] | ||
|
||
export const nth = (d: number) => { | ||
if (d > 3 && d < 21) return "th" | ||
switch (d % 10) { | ||
case 1: | ||
return "st" | ||
case 2: | ||
return "nd" | ||
case 3: | ||
return "rd" | ||
default: | ||
return "th" | ||
} | ||
return new Date().getTime() >= CLOSE_TIMESTAMP | ||
} |
24bf888
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.
Successfully deployed to the following URLs:
tumso-website – ./
tumso-website-git-main-pryter.vercel.app
tumso-website.vercel.app
tumso-website-pryter.vercel.app