-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: FRON 38 initial selection lists for season and event (#43)
- Loading branch information
1 parent
ba9c46f
commit cf240e0
Showing
4 changed files
with
120 additions
and
2 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
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,5 +1,20 @@ | ||
// {serverError ? <Error statusCode={422} title={serverError} /> : children} | ||
|
||
import { Suspense } from 'react'; | ||
|
||
import { SelectionList } from '@/components/SelectionData/SelectionList'; | ||
|
||
export default function Page() { | ||
return <h1>Hello, Dashboard Page!</h1>; | ||
return ( | ||
<> | ||
<div className='grid grid-cols-3'> | ||
<div className='col-span-1 row-span-3'> | ||
<Suspense fallback={<div className='h-16 animate-pulse' />}> | ||
<SelectionList /> | ||
</Suspense> | ||
</div> | ||
<div>{/* Selection Query Action List Options goes here */}</div> | ||
</div> | ||
</> | ||
); | ||
} |
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,17 @@ | ||
export const SelectionItem = ({ | ||
children, | ||
clickHandler, | ||
}: { | ||
children: React.ReactNode | React.ReactNode[]; | ||
clickHandler: () => void; | ||
}) => { | ||
return ( | ||
<a | ||
onClick={clickHandler} | ||
tabIndex={0} | ||
className='cursor-pointer border-b bg-card px-4 py-2 text-card-foreground hover:bg-accent hover:text-accent-foreground' | ||
> | ||
{children} | ||
</a> | ||
); | ||
}; |
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,86 @@ | ||
'use client'; | ||
|
||
import { useAtom } from 'jotai'; | ||
import { usePathname, useRouter, useSearchParams } from 'next/navigation'; | ||
|
||
import { | ||
EventListState, | ||
EventState, | ||
SessionListState, | ||
SessionState, | ||
} from '@/state-mgmt/atoms'; | ||
|
||
import { SelectionItem } from './SelectionItem'; | ||
|
||
const titles: { [key: string]: string } = { | ||
Season: 'Season Events', | ||
Event: 'Event Sessions', | ||
}; | ||
|
||
export const SelectionList = () => { | ||
const searchParams = useSearchParams(); | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
|
||
// Default view is Season | ||
const view = searchParams.get('view') || 'Season'; | ||
|
||
// Event atoms | ||
const [, setEvent] = useAtom(EventState); | ||
const [eventList] = useAtom(EventListState); | ||
|
||
// Session atoms | ||
const [, setSession] = useAtom(SessionState); | ||
const [sessionList] = useAtom(SessionListState); | ||
|
||
const handleSelection = (value: string) => { | ||
const params = new URLSearchParams(searchParams); | ||
|
||
if (view === 'Season') { | ||
params.set('view', 'Event'); | ||
setEvent(value); | ||
} | ||
|
||
if (view === 'Event') { | ||
params.set('view', 'Session'); | ||
setSession(value); | ||
} | ||
|
||
router.push(`${pathname}?${params.toString()}`); | ||
}; | ||
|
||
const dataListComponents: { [key: string]: React.ReactNode[] } = { | ||
// Season view | ||
Season: eventList.map((event, i) => ( | ||
<SelectionItem | ||
key={event.EventDate} | ||
clickHandler={() => handleSelection(event.EventName)} | ||
> | ||
<h2> | ||
{i + 1}. {event.EventName} | ||
</h2> | ||
{/* <p>{event.EventDate}</p> */} | ||
</SelectionItem> | ||
)), | ||
// Event view | ||
Event: sessionList.map((session) => ( | ||
<SelectionItem | ||
key={session} | ||
clickHandler={() => handleSelection(session)} | ||
> | ||
<h2>{session}</h2> | ||
</SelectionItem> | ||
)), | ||
}; | ||
|
||
return ( | ||
<> | ||
<h1 className='px-4 text-2xl font-extrabold tracking-tight lg:text-3xl'> | ||
{titles[view] || 'Invalid view selected'} | ||
</h1> | ||
<div className='my-2 grid overflow-hidden rounded-xl border shadow'> | ||
{dataListComponents[view] || 'No data available'} | ||
</div> | ||
</> | ||
); | ||
}; |