[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. // notifications.ts
  2. // Copyright (C) 2020 Dwayne Harris
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. import { Action } from 'redux'
  14. import { v1 } from 'uuid'
  15. import { AppThunkAction, NotificationType } from '../types'
  16. export interface AddNotificationAction extends Action {
  17. type: 'NOTIFICATIONS_ADD_NOTIFICATION'
  18. payload: {
  19. id: string
  20. type: NotificationType
  21. content: string
  22. }
  23. }
  24. export interface RemoveNotificationAction extends Action {
  25. type: 'NOTIFICATIONS_REMOVE_NOTIFICATION'
  26. payload: string
  27. }
  28. export interface ClearNotificationAction extends Action {
  29. type: 'NOTIFICATIONS_CLEAR_NOTIFICATION'
  30. payload: string
  31. }
  32. export interface SetNotificationAutoAction extends Action {
  33. type: 'NOTIFICATIONS_SET_AUTO'
  34. payload: string
  35. }
  36. export type NotificationActions = AddNotificationAction | RemoveNotificationAction | ClearNotificationAction | SetNotificationAutoAction
  37. export const addNotification = (id: string, type: NotificationType, content: string): AddNotificationAction => ({
  38. type: 'NOTIFICATIONS_ADD_NOTIFICATION',
  39. payload: {
  40. id,
  41. type,
  42. content,
  43. }
  44. })
  45. export const removeNotification = (id: string): RemoveNotificationAction => ({
  46. type: 'NOTIFICATIONS_REMOVE_NOTIFICATION',
  47. payload: id,
  48. })
  49. export const clearNotification = (id: string): ClearNotificationAction => ({
  50. type: 'NOTIFICATIONS_CLEAR_NOTIFICATION',
  51. payload: id,
  52. })
  53. export const setNotificationAuto = (id: string): SetNotificationAutoAction => ({
  54. type: 'NOTIFICATIONS_SET_AUTO',
  55. payload: id,
  56. })
  57. export const showNotification = (type: NotificationType, content: string, expiration: number = 5000): AppThunkAction => {
  58. return async dispatch => {
  59. const id = v1()
  60. dispatch(addNotification(id, type, content))
  61. setTimeout(() => {
  62. dispatch(clearNotification(id))
  63. }, expiration)
  64. }
  65. }