Skip to content

Commit

Permalink
app
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Aug 14, 2024
1 parent e517db6 commit 82c05c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
28 changes: 11 additions & 17 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { CssBaseline, ThemeProvider } from "@mui/material"
import { type ThemeProviderProps } from "@mui/material/styles/ThemeProvider"
import React, { useCallback } from "react"
import { type ReactNode, useCallback } from "react"
import { Provider, type ProviderProps } from "react-redux"
import { type Action } from "redux"

import { InactiveDialog, ScreenTimeDialog } from "../features"
import { useCountdown, useEventListener } from "../hooks"
import "../scripts"
import {
// configureFreshworksWidget,
toggleOneTrustInfoDisplay,
} from "../utils/window"
// import "../scripts"
// import {
// configureFreshworksWidget,
// toggleOneTrustInfoDisplay,
// } from "../utils/window"

export interface AppProps<A extends Action = Action, S = unknown> {
theme: ThemeProviderProps["theme"]
store: ProviderProps<A, S>["store"]
children: React.ReactNode
children: ReactNode
maxIdleSeconds?: number
maxTotalSeconds?: number
}
Expand All @@ -29,31 +29,25 @@ const App = <A extends Action = Action, S = unknown>({
}: AppProps<A, S>): JSX.Element => {
const root = document.getElementById("root") as HTMLElement

// TODO: dynamically check if user is authenticated.
const isAuthenticated = true
const [idleSeconds, setIdleSeconds] = useCountdown(maxIdleSeconds)
const [totalSeconds, setTotalSeconds] = useCountdown(maxTotalSeconds)
const resetIdleSeconds = useCallback(() => {
setIdleSeconds(maxIdleSeconds)
}, [setIdleSeconds, maxIdleSeconds])

const isIdle = isAuthenticated && idleSeconds === 0
const isIdle = idleSeconds === 0
const tooMuchScreenTime = totalSeconds === 0

useEventListener(root, "mousemove", resetIdleSeconds)
useEventListener(root, "keypress", resetIdleSeconds)

React.useEffect(() => {
if (isAuthenticated) resetIdleSeconds()
}, [isAuthenticated, resetIdleSeconds])

// React.useEffect(() => {
// configureFreshworksWidget("hide")
// }, [])

if (import.meta.env.PROD) {
toggleOneTrustInfoDisplay()
}
// if (import.meta.env.PROD) {
// toggleOneTrustInfoDisplay()
// }

return (
<ThemeProvider theme={theme}>
Expand Down
7 changes: 2 additions & 5 deletions src/hooks/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ export function useCountdown(
seconds: number,
interval: number = 1,
): [number, Dispatch<SetStateAction<number>>] {
if (seconds <= 0) {
throw Error("seconds must be > 0")
} else if (interval <= 0) {
throw Error("interval must be > 0")
}
if (seconds <= 0) throw Error("seconds must be > 0")
if (interval <= 0) throw Error("interval must be > 0")

const [_seconds, _setSeconds] = useState(seconds)

Expand Down

0 comments on commit 82c05c5

Please sign in to comment.