-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into homepage-groups-preview
- Loading branch information
Showing
57 changed files
with
1,119 additions
and
251 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
35 changes: 35 additions & 0 deletions
35
packages/app-root/src/app/users/[login]/stats/certificate/CertificateContainer.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,35 @@ | ||
'use client' | ||
|
||
import { Certificate } from '@zooniverse/user' | ||
import { useContext } from 'react' | ||
|
||
import { PanoptesAuthContext, UserStatsContext } from '../../../../../contexts' | ||
import AuthenticatedUsersPageContainer from '../../../../../components/AuthenticatedUsersPageContainer' | ||
|
||
function CertificateContainer({ | ||
login | ||
}) { | ||
const { adminMode, isLoading, user } = useContext(PanoptesAuthContext) | ||
const { | ||
selectedDateRange, | ||
selectedProject | ||
} = useContext(UserStatsContext) | ||
|
||
return ( | ||
<AuthenticatedUsersPageContainer | ||
adminMode={adminMode} | ||
isLoading={isLoading} | ||
login={login} | ||
user={user} | ||
> | ||
<Certificate | ||
authUser={user} | ||
login={login} | ||
selectedDateRange={selectedDateRange} | ||
selectedProject={selectedProject} | ||
/> | ||
</AuthenticatedUsersPageContainer> | ||
) | ||
} | ||
|
||
export default CertificateContainer |
14 changes: 14 additions & 0 deletions
14
packages/app-root/src/app/users/[login]/stats/certificate/page.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,14 @@ | ||
import CertificateContainer from './CertificateContainer' | ||
|
||
export const metadata = { | ||
title: 'Certificate', | ||
description: 'My Zooniverse certificate page' | ||
} | ||
|
||
export default function Certificate({ params }) { | ||
return ( | ||
<CertificateContainer | ||
login={params.login} | ||
/> | ||
) | ||
} |
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,9 @@ | ||
import UserStatsContextProvider from '../../../../components/UserStatsContextProvider' | ||
|
||
export default function UserStatsLayout({ children }) { | ||
return ( | ||
<UserStatsContextProvider> | ||
{children} | ||
</UserStatsContextProvider> | ||
) | ||
} |
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
packages/app-root/src/components/UserStatsContextProvider.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,27 @@ | ||
'use client' | ||
|
||
import { useContext } from 'react' | ||
|
||
import { PanoptesAuthContext, UserStatsContext } from '../contexts' | ||
import { useStatsDateRange, useStatsProject } from '../hooks' | ||
|
||
function UserStatsContextProvider({ children }) { | ||
const { isLoading, user } = useContext(PanoptesAuthContext) | ||
const { selectedDateRange, setSelectedDateRange } = useStatsDateRange({ isLoading, user }) | ||
const { selectedProject, setSelectedProject } = useStatsProject({ isLoading, user }) | ||
|
||
const statsContext = { | ||
selectedDateRange, | ||
selectedProject, | ||
setSelectedDateRange, | ||
setSelectedProject | ||
} | ||
|
||
return ( | ||
<UserStatsContext.Provider value={statsContext}> | ||
{children} | ||
</UserStatsContext.Provider> | ||
) | ||
} | ||
|
||
export default UserStatsContextProvider |
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,5 @@ | ||
import { createContext } from 'react' | ||
|
||
const UserStatsContext = createContext({}) | ||
|
||
export default UserStatsContext |
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,2 +1,3 @@ | ||
export { default as PanoptesAuthContext } from './PanoptesAuthContext.js' | ||
export { default as ThemeModeContext } from './ThemeModeContext.js' | ||
export { default as UserStatsContext } from './UserStatsContext.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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { default as useAdminMode } from './useAdminMode.js' | ||
export { default as usePreferredTheme } from './usePreferredTheme.js' | ||
export { default as useStatsDateRange } from './useStatsDateRange.js' | ||
export { default as useStatsProject } from './useStatsProject.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,26 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
const isBrowser = typeof window !== 'undefined' | ||
const localStorage = isBrowser ? window.localStorage : null | ||
|
||
let initialDateRange = 'Last7Days' | ||
if (isBrowser) { | ||
initialDateRange = localStorage?.getItem('selectedDateRange') || initialDateRange | ||
} | ||
|
||
export default function useStatsDateRange({ isLoading, user }) { | ||
const [selectedDateRange, setSelectedDateRange] = useState(initialDateRange) | ||
|
||
useEffect(function onDateRangeChange() { | ||
localStorage?.setItem('selectedDateRange', selectedDateRange) | ||
}, [selectedDateRange]) | ||
|
||
useEffect(function onUserChange() { | ||
// when a user successfully logs out isLoading is false and user is undefined | ||
if (!isLoading && !user?.login) { | ||
setSelectedDateRange('Last7Days') | ||
} | ||
}, [isLoading, user?.login]) | ||
|
||
return { selectedDateRange, setSelectedDateRange } | ||
} |
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,26 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
const isBrowser = typeof window !== 'undefined' | ||
const localStorage = isBrowser ? window.localStorage : null | ||
|
||
let initialProject = 'AllProjects' | ||
if (isBrowser) { | ||
initialProject = localStorage?.getItem('selectedProject') || initialProject | ||
} | ||
|
||
export default function useStatsProject({ isLoading, user }) { | ||
const [selectedProject, setSelectedProject] = useState(initialProject) | ||
|
||
useEffect(function onProjectChange() { | ||
localStorage?.setItem('selectedProject', selectedProject) | ||
}, [selectedProject]) | ||
|
||
useEffect(function onUserChange() { | ||
// when a user successfully logs out isLoading is false and user is undefined | ||
if (!isLoading && !user?.login) { | ||
setSelectedProject('AllProjects') | ||
} | ||
}, [isLoading, user?.login]) | ||
|
||
return { selectedProject, setSelectedProject } | ||
} |
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
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
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
Oops, something went wrong.