-
Notifications
You must be signed in to change notification settings - Fork 1
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
3eaaa92
commit c5a2c45
Showing
4 changed files
with
56 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { Alert } from 'react-bootstrap'; | ||
import { useNotificationsSystem } from '../contexts/NotificationsContext'; | ||
|
||
function NotificationsArea() { | ||
const NotificationsSystem = useNotificationsSystem(); | ||
const { currentNotifications } = NotificationsSystem; | ||
if(!currentNotifications) return null; | ||
|
||
const hideNotifications = () => { NotificationsSystem.clear(); }; | ||
|
||
return ( | ||
<Alert variant="info" onClose={hideNotifications} dismissible> | ||
{currentNotifications.message} | ||
</Alert> | ||
); | ||
} | ||
|
||
export default NotificationsArea; |
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,23 @@ | ||
import React from 'react'; | ||
|
||
const NotificationsContext = React.createContext(); | ||
|
||
export function useNotificationsSystem() { | ||
return React.useContext(NotificationsContext); | ||
} | ||
|
||
export function NotificationsProvider({ children }) { | ||
const [notifications, setNotifications] = React.useState(null); | ||
|
||
const value = { | ||
alert: (message) => { setNotifications({ message }); }, | ||
clear: () => { setNotifications(null); }, | ||
currentNotifications: notifications, | ||
}; | ||
|
||
return ( | ||
<NotificationsContext.Provider value={value}> | ||
{children} | ||
</NotificationsContext.Provider> | ||
); | ||
} |
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