-
Notifications
You must be signed in to change notification settings - Fork 29
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
1 parent
5830fed
commit aeee0f3
Showing
4 changed files
with
56 additions
and
3 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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
'use client' | ||
import AdminCheckbox from '@zooniverse/react-components/AdminCheckbox' | ||
import ZooFooter from '@zooniverse/react-components/ZooFooter' | ||
|
||
import { usePanoptesUser } from '../hooks' | ||
import { useAdminMode, usePanoptesUser } from '../hooks' | ||
|
||
export default function PageFooter() { | ||
// we'll need the user in order to detect admin mode. | ||
const { data: user } = usePanoptesUser() | ||
const { data: user, isLoading } = usePanoptesUser() | ||
const { adminMode, toggleAdmin } = useAdminMode(user) | ||
|
||
return ( | ||
<ZooFooter /> | ||
<ZooFooter | ||
adminContainer={(!isLoading && user?.admin) ? <AdminCheckbox onChange={toggleAdmin} checked={adminMode} /> : null} | ||
/> | ||
) | ||
} |
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,3 +1,4 @@ | ||
export { default as useAdminMode } from './useAdminMode.js' | ||
export { default as usePanoptesUser } from './usePanoptesUser.js' | ||
export { default as useUnreadMessages } from './useUnreadMessages.js' | ||
export { default as useUnreadNotifications } from './useUnreadNotifications.js' |
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,45 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
const isBrowser = typeof window !== 'undefined' | ||
const localStorage = isBrowser ? window.localStorage : null | ||
const storedAdminFlag = !!localStorage?.getItem('adminFlag') | ||
const adminBorderImage = 'repeating-linear-gradient(45deg,#000,#000 25px,#ff0 25px,#ff0 50px) 5' | ||
|
||
export default function useAdminMode(user) { | ||
const [adminState, setAdminState] = useState(storedAdminFlag) | ||
const adminMode = user?.admin && adminState | ||
|
||
useEffect(function onUserChange() { | ||
const isAdmin = user?.admin | ||
if (isAdmin) { | ||
const adminFlag = !!localStorage?.getItem('adminFlag') | ||
setAdminState(adminFlag) | ||
} else { | ||
localStorage?.removeItem('adminFlag') | ||
} | ||
}, [user?.admin]) | ||
|
||
useEffect(function onAdminChange() { | ||
if (adminMode) { | ||
document.body.style.border = '5px solid' | ||
document.body.style.borderImage = adminBorderImage | ||
} | ||
return () => { | ||
document.body.style.border = '' | ||
document.body.style.borderImage = '' | ||
console.log(document.body.style) | ||
} | ||
}, [adminMode]) | ||
|
||
function toggleAdmin() { | ||
let newAdminState = !adminState | ||
setAdminState(newAdminState) | ||
if (newAdminState) { | ||
localStorage?.setItem('adminFlag', true) | ||
} else { | ||
localStorage?.removeItem('adminFlag') | ||
} | ||
} | ||
|
||
return { adminMode, toggleAdmin } | ||
} |