Skip to content

Commit

Permalink
fix: blocked page
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Nov 2, 2023
1 parent e93edf5 commit e0b5304
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
10 changes: 3 additions & 7 deletions src/components/Config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Utility from '@services/Utility'
import { deepMerge } from '@services/functions/deepMerge'
import { Navigate } from 'react-router-dom'
import { checkHoliday } from '@services/functions/checkHoliday'

const rootLoading = document.getElementById('loader')
import { useHideElement } from '@hooks/useHideElement'

export default function Config({ children }) {
const { t } = useTranslation()
Expand All @@ -20,11 +19,8 @@ export default function Config({ children }) {
fetched: false,
})

if (rootLoading) {
if (serverSettings.fetched) {
rootLoading.style.display = 'none'
}
}
useHideElement(serverSettings.fetched)

const getServerSettings = async () => {
const data = await Fetch.getSettings()

Expand Down
10 changes: 2 additions & 8 deletions src/components/Errors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import Grid from '@mui/material/Grid'
import Typography from '@mui/material/Typography'
import Button from '@mui/material/Button'
import { useTranslation } from 'react-i18next'

const rootLoading = document.getElementById('loader')
import { useHideElement } from '@hooks/useHideElement'

export default function Errors() {
const { t } = useTranslation()
const error = window.location.href.split('/').pop()

React.useEffect(() => {
if (rootLoading) {
rootLoading.style.display = 'none'
}
}, [])
useHideElement()

return (
<Grid
Expand Down
6 changes: 5 additions & 1 deletion src/components/ReactRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ const loginRoute = (
</Config>
)
const resetRoute = <ClearStorage />
const blockedRoute = <Blocked />
const blockedRoute = (
<Config>
<Blocked />
</Config>
)
const errorRoute = <Errors />

export default function ReactRouter() {
Expand Down
4 changes: 3 additions & 1 deletion src/components/layout/auth/Blocked.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import Grid from '@mui/material/Grid'
import Typography from '@mui/material/Typography'
import Button from '@mui/material/Button'
import { useStatic } from '@hooks/useStore'
import { useHideElement } from '@hooks/useHideElement'

import DiscordLogin from './Discord'

export default function Blocked() {
const { t } = useTranslation()
const { info } = useParams()
const discordInvite = useStatic((s) => s.config.links.discordInvite)
const discordInvite = useStatic((s) => s.config?.links?.discordInvite)
useHideElement()

const queryParams = new URLSearchParams(info)

Expand Down
11 changes: 11 additions & 0 deletions src/hooks/useHideElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useEffect } from 'react'

const rootLoading = document.getElementById('loader')

export function useHideElement(ready = true) {
useEffect(() => {
if (rootLoading && ready) {
rootLoading.style.display = 'none'
}
}, [])
}

0 comments on commit e0b5304

Please sign in to comment.