-
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.
Add more apis to fetch agenda and display them
- Loading branch information
Showing
7 changed files
with
227 additions
and
99 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { | ||
Drawer, | ||
IconButton, | ||
List, | ||
ListItem, | ||
ListItemText, | ||
Typography, | ||
useMediaQuery, | ||
useTheme, | ||
} from "@mui/material"; | ||
import FormatListBulletedIcon from "@mui/icons-material/FormatListBulleted"; | ||
import { useAgenda } from "../../utils/meetingAgenda"; | ||
|
||
|
||
export const AgendaDrawer: React.FC = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const theme = useTheme(); | ||
const isMobile = useMediaQuery(theme.breakpoints.down("sm")); | ||
|
||
const { agendaItems } = useAgenda(); | ||
|
||
const toggleDrawer = (open: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => { | ||
if ( | ||
event.type === "keydown" && | ||
((event as React.KeyboardEvent).key === "Tab" || (event as React.KeyboardEvent).key === "Shift") | ||
) { | ||
return; | ||
} | ||
setIsOpen(open); | ||
}; | ||
|
||
useEffect(() => { | ||
if (agendaItems.length > 0 && !isMobile) { | ||
setIsOpen(true); | ||
} | ||
}, [agendaItems]); | ||
|
||
const drawerContent = ( | ||
<List> | ||
<Typography variant="h6" sx={{ p: 2 }}> | ||
Agenda | ||
</Typography> | ||
{agendaItems.map((item, index) => ( | ||
<ListItem key={index}> | ||
<ListItemText primary={item} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
); | ||
|
||
return ( | ||
<> | ||
{isMobile && ( | ||
<IconButton | ||
onClick={toggleDrawer(true)} | ||
sx={{ position: "fixed", right: 16, top: 16, zIndex: 1100 }} | ||
> | ||
<FormatListBulletedIcon /> | ||
</IconButton> | ||
)} | ||
<Drawer | ||
anchor="right" | ||
open={isMobile ? isOpen : true} | ||
onClose={toggleDrawer(false)} | ||
variant={isMobile ? "temporary" : "permanent"} | ||
sx={{ | ||
width: 150, | ||
flexShrink: 0, | ||
"& .MuiDrawer-paper": { | ||
width: 150, | ||
boxSizing: "border-box", | ||
}, | ||
}} | ||
> | ||
{drawerContent} | ||
</Drawer> | ||
</> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { createContext, useState, useContext, ReactNode } from 'react'; | ||
|
||
interface AgendaContextType { | ||
agendaItems: string[]; | ||
setAgendaItems: React.Dispatch<React.SetStateAction<string[]>>; | ||
} | ||
|
||
const AgendaContext = createContext<AgendaContextType | undefined>(undefined); | ||
|
||
interface AgendaProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const AgendaProvider: React.FC<AgendaProviderProps> = ({ children }) => { | ||
const [agendaItems, setAgendaItems] = useState<string[]>([]); | ||
|
||
return ( | ||
<AgendaContext.Provider value={{ agendaItems, setAgendaItems }}> | ||
{children} | ||
</AgendaContext.Provider> | ||
); | ||
}; | ||
|
||
export const useAgenda = (): AgendaContextType => { | ||
const context = useContext(AgendaContext); | ||
if (context === undefined) { | ||
throw new Error('useAgenda must be used within an AgendaProvider'); | ||
} | ||
return context; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import React, { createContext, useState, useContext, ReactNode } from 'react'; | ||
|
||
interface UserContextType { | ||
userId: number; | ||
setUserId: React.Dispatch<React.SetStateAction<number>>; | ||
} | ||
|
||
interface UserProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
const UserContext = createContext<UserContextType | undefined>(undefined); | ||
|
||
export const UserProvider = ({ children }: UserProviderProps) => { | ||
const [userId, setUserId] = useState(2); | ||
|
||
return ( | ||
<UserContext.Provider value={{ userId, setUserId }}> | ||
{children} | ||
</UserContext.Provider> | ||
); | ||
}; | ||
|
||
export const useUser = (): UserContextType => { | ||
const context = useContext(UserContext); | ||
if (context === undefined) { | ||
throw new Error('useUser must be used within a UserProvider'); | ||
} | ||
return context; | ||
}; |