[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.

65 lines
1.8 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. import { Action } from 'redux'
  2. import { v1 } from 'uuid'
  3. import { AppThunkAction, NotificationType } from '../types'
  4. export interface AddNotificationAction extends Action {
  5. type: 'NOTIFICATIONS_ADD_NOTIFICATION'
  6. payload: {
  7. id: string
  8. type: NotificationType
  9. content: string
  10. }
  11. }
  12. export interface RemoveNotificationAction extends Action {
  13. type: 'NOTIFICATIONS_REMOVE_NOTIFICATION'
  14. payload: string
  15. }
  16. export interface ClearNotificationAction extends Action {
  17. type: 'NOTIFICATIONS_CLEAR_NOTIFICATION'
  18. payload: string
  19. }
  20. export interface SetNotificationAutoAction extends Action {
  21. type: 'NOTIFICATIONS_SET_AUTO'
  22. payload: string
  23. }
  24. export type NotificationActions = AddNotificationAction | RemoveNotificationAction | ClearNotificationAction | SetNotificationAutoAction
  25. export const addNotification = (id: string, type: NotificationType, content: string): AddNotificationAction => ({
  26. type: 'NOTIFICATIONS_ADD_NOTIFICATION',
  27. payload: {
  28. id,
  29. type,
  30. content,
  31. }
  32. })
  33. export const removeNotification = (id: string): RemoveNotificationAction => ({
  34. type: 'NOTIFICATIONS_REMOVE_NOTIFICATION',
  35. payload: id,
  36. })
  37. export const clearNotification = (id: string): ClearNotificationAction => ({
  38. type: 'NOTIFICATIONS_CLEAR_NOTIFICATION',
  39. payload: id,
  40. })
  41. export const setNotificationAuto = (id: string): SetNotificationAutoAction => ({
  42. type: 'NOTIFICATIONS_SET_AUTO',
  43. payload: id,
  44. })
  45. export const showNotification = (type: NotificationType, content: string, expiration: number = 5000): AppThunkAction => {
  46. return async dispatch => {
  47. const id = v1()
  48. dispatch(addNotification(id, type, content))
  49. setTimeout(() => {
  50. dispatch(clearNotification(id))
  51. }, expiration)
  52. }
  53. }