Skip to content

Commit

Permalink
chore: add dev time stamp component
Browse files Browse the repository at this point in the history
  • Loading branch information
devceline committed Feb 6, 2024
1 parent 0a90e99 commit dea4f3f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import W3iContext from '@/contexts/W3iContext/context'
import { useMobileResponsiveGrid } from '@/utils/hooks'

import './App.scss'
import DevTimeStamp from './components/dev/DevTimeStamp'

const App = () => {
const { uiEnabled } = useContext(W3iContext)
Expand All @@ -20,6 +21,7 @@ const App = () => {

return (
<AuthProtectedPage>
<DevTimeStamp />
<LazyMotion features={domAnimation}>
<m.div ref={ref} data-path={location.pathname} className="App">
<Fragment>
Expand Down
9 changes: 9 additions & 0 deletions src/components/dev/DevTimeStamp/DevTimeStamp.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DevTimeStamp {
color: var(--fg-color-1);
background: var(--bg-color-2);
display: flex;
justify-content: flex-end;
align-items: center;
padding: 0.25em;
z-index: 999;
}
30 changes: 30 additions & 0 deletions src/components/dev/DevTimeStamp/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useContext, useEffect, useState } from 'react';
import './DevTimeStamp.scss'
import SettingsContext from '@/contexts/SettingsContext/context';

const DevTimeStamp = () => {
const [timestamp, setTimestamp] = useState(Date.now())
const {isDevModeEnabled} = useContext(SettingsContext)

useEffect(() => {
if(isDevModeEnabled) {
const intervalId = setInterval(() => {
setTimestamp(Date.now())
}, 1)

return () => clearInterval(intervalId)
}
}, [setTimestamp, isDevModeEnabled])

if (!isDevModeEnabled) {
return null;
}

return (
<div className="DevTimeStamp">
<p>{timestamp}</p>
</div>
)
}

export default DevTimeStamp;

0 comments on commit dea4f3f

Please sign in to comment.