-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add dev time stamp component (#431)
* chore: add dev time stamp component * chore: add timestamp formatting * chore: decrease interval * Update src/components/dev/DevTimeStamp/DevTimeStamp.scss Co-authored-by: Chris Smith <[email protected]> * chore: move dev timestamp out of auth protected * chore: center timestamp * chore: place timestamp on top * chore: explain comment --------- Co-authored-by: Chris Smith <[email protected]>
- Loading branch information
1 parent
0a90e99
commit 4a2251d
Showing
3 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.DevTimeStamp { | ||
color: #888888; | ||
position: fixed; | ||
width: 100%; | ||
top: 0.5em; | ||
font-size: 11px; | ||
pointer-events: none; | ||
z-index: 999; | ||
|
||
span { | ||
display: block; | ||
width: fit-content; | ||
margin: auto; | ||
} | ||
} |
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,51 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
import './DevTimeStamp.scss' | ||
import SettingsContext from '@/contexts/SettingsContext/context'; | ||
|
||
const getTimeStampFormatted = (rawTimestamp: number) => { | ||
|
||
const timestamp = new Date(rawTimestamp) | ||
|
||
const year = timestamp.getFullYear(); | ||
|
||
// Months are zero-indexed | ||
const month = (timestamp.getMonth() + 1).toString().padStart(2, '0'); | ||
const day = timestamp.getDate().toString().padStart(2, '0'); | ||
const hours = timestamp.getHours().toString().padStart(2, '0'); | ||
const minutes = timestamp.getMinutes().toString().padStart(2, '0'); | ||
const seconds = timestamp.getSeconds().toString().padStart(2, '0'); | ||
|
||
const timeZone = new Intl.DateTimeFormat('en', { timeZoneName: 'short' }).formatToParts(timestamp).find(part => part.type === 'timeZoneName')!.value; | ||
|
||
const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${timeZone}`; | ||
|
||
return formattedDateTime | ||
|
||
} | ||
|
||
const DevTimeStamp = () => { | ||
const [timestamp, setTimestamp] = useState(Date.now()) | ||
const {isDevModeEnabled} = useContext(SettingsContext) | ||
|
||
useEffect(() => { | ||
if(isDevModeEnabled) { | ||
const intervalId = setInterval(() => { | ||
setTimestamp(Date.now()) | ||
}, 250) | ||
|
||
return () => clearInterval(intervalId) | ||
} | ||
}, [setTimestamp, isDevModeEnabled]) | ||
|
||
if (!isDevModeEnabled) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="DevTimeStamp"> | ||
<span>{getTimeStampFormatted(timestamp)}</span> | ||
</div> | ||
) | ||
} | ||
|
||
export default DevTimeStamp; |
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