-
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.
- Loading branch information
Showing
7 changed files
with
95 additions
and
66 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
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,39 @@ | ||
import React, { | ||
createContext, useContext, useState, ReactNode, | ||
} from 'react'; | ||
import { Gradebook, Task, Timetable } from '../../../shared'; | ||
|
||
interface ModalData { | ||
name: string; | ||
endTime: string; | ||
startTime: string; | ||
timetable: Timetable; | ||
gradebook?: Gradebook | undefined; | ||
tasks?: Task[] | undefined; | ||
lessonId: string; | ||
} | ||
|
||
const ModalContext = createContext<{ modalData: ModalData | null; openModal:(data: { name: string; lessonId: string; startTime: string; endTime: string; gradebook: Gradebook | undefined; tasks: Task[] | undefined; timetable: Timetable }) => void } | undefined>( | ||
undefined); | ||
|
||
export const ModalProvider: React.FC<{ children: ReactNode }> = ({ children }) => { | ||
const [modalData, setModalData] = useState<ModalData | null>(null); | ||
|
||
const openModal = (data: ModalData) => { | ||
setModalData(data); | ||
}; | ||
|
||
return ( | ||
<ModalContext.Provider value={{ modalData, openModal }}> | ||
{children} | ||
</ModalContext.Provider> | ||
); | ||
}; | ||
|
||
export const useModal = () => { | ||
const context = useContext(ModalContext); | ||
if (context === undefined) { | ||
throw new Error('useModal must be used within a ModalProvider'); | ||
} | ||
return context; | ||
}; |
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