-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from suren-atoyan/notifications
Integrate notifications
- Loading branch information
Showing
18 changed files
with
221 additions
and
18 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,14 @@ | ||
### Releases | ||
|
||
## v1.0.0 | ||
###### *June 19, 2020* | ||
|
||
It's the first stable version of the template. It's going to become a solid foundation for your next React project. | ||
|
||
- features: add notifications 🎉 | ||
- readme: update bundle size, fix image titles, add section for notifications, add examples | ||
|
||
## v0.1.0 | ||
###### *June 19, 2020* | ||
|
||
🎉 First release 🎉 |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { isMobile } from 'utils'; | ||
|
||
/* set your data here */ | ||
const email = '[email protected]'; | ||
const domain = 'your-project-domain.com' | ||
|
@@ -68,6 +70,17 @@ const title = 'React PWA'; | |
|
||
const themePair = ['dark', 'light']; | ||
|
||
const notifications = { | ||
options: { | ||
anchorOrigin: { | ||
vertical: 'bottom', | ||
horizontal: 'left', | ||
}, | ||
autoHideDuration: 3000, | ||
}, | ||
maxSnack: isMobile ? 3 : 4, | ||
}; | ||
|
||
export { | ||
messages, | ||
cancelationMessage, | ||
|
@@ -78,5 +91,6 @@ export { | |
repository, | ||
title, | ||
themePair, | ||
notifications, | ||
themes, | ||
}; |
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,17 @@ | ||
import React from 'react'; | ||
|
||
import { SnackbarProvider } from 'notistack'; | ||
|
||
import Notifier from './Notifier'; | ||
|
||
import { notifications } from 'config'; | ||
|
||
function Notifications() { | ||
return ( | ||
<SnackbarProvider maxSnack={notifications.maxSnack}> | ||
<Notifier /> | ||
</SnackbarProvider> | ||
); | ||
} | ||
|
||
export default Notifications; |
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,49 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
import { useSnackbar } from 'notistack'; | ||
|
||
import { useStore } from 'store'; | ||
|
||
function Notifier() { | ||
const { state: { notifications }, actions } = useStore(); | ||
const { enqueueSnackbar, closeSnackbar } = useSnackbar(); | ||
const displayed = useRef([]); | ||
|
||
function storeDisplayed(key) { | ||
displayed.current = [...displayed.current, key]; | ||
} | ||
|
||
function removeDisplayed(key) { | ||
displayed.current = [...displayed.current.filter(_key => key !== _key)]; | ||
} | ||
|
||
useEffect(_ => { | ||
notifications.forEach(({ message, options, dismissed }) => { | ||
if (dismissed) { | ||
// dismiss snackbar using notistack | ||
closeSnackbar(options.key); | ||
return; | ||
} | ||
|
||
// do nothing if snackbar is already displayed | ||
if (displayed.current.includes(options.key)) return; | ||
|
||
// display snackbar using notistack | ||
enqueueSnackbar(message, { | ||
...options, | ||
onExited(event, key) { | ||
// removen this snackbar from the store | ||
actions.notifications.remove(key); | ||
removeDisplayed(key); | ||
}, | ||
}); | ||
|
||
// keep track of snackbars that we've displayed | ||
storeDisplayed(options.key); | ||
}); | ||
}); | ||
|
||
return null; | ||
} | ||
|
||
export default Notifier; |
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,3 @@ | ||
import Component from './Component'; | ||
|
||
export default Component; |
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,3 @@ | ||
import Component from './Component'; | ||
|
||
export default Component; |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ const initialState = { | |
isUpdated: false, | ||
registration: null, | ||
}, | ||
notifications: [], | ||
}; | ||
|
||
export { initialState }; |
Oops, something went wrong.