Skip to content

Commit

Permalink
fix(redux): added ts on notificationBox
Browse files Browse the repository at this point in the history
fixing #109
  • Loading branch information
roman-ojha committed Jun 24, 2022
1 parent 3fc39b9 commit b5641f7
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/src/services/redux/action.ts
@@ -1,3 +1,4 @@
export * from "./global/rootUserFriends/action";
export * from "./global/rootUserProfileDetail/action";
export * from "./components/commentBox/action";
export * from "./components/notificationBox/action";
2 changes: 0 additions & 2 deletions client/src/services/redux/components/followedByUser/types.ts
@@ -1,5 +1,3 @@
import { UserDocumentFollower } from "../../../../interface/userDocument";

export interface FollowedByState {
userID: "";
followed: "";
Expand Down
27 changes: 27 additions & 0 deletions client/src/services/redux/components/notificationBox/action.ts
@@ -0,0 +1,27 @@
import {
// NotificationBoxState,
NotificationBoxActionTypes,
NotificationBoxAction,
NotificationBoxState,
} from "./types";
import { Dispatch } from "react";

export const openNotificationBox = (data: NotificationBoxState["open"]) => {
return (dispatch: Dispatch<NotificationBoxAction>) => {
dispatch({
type: NotificationBoxActionTypes.OPEN_NOTIFICATION_BOX,
payload: data,
});
};
};

export const setNotificationData = (
data: NotificationBoxState["notificationData"]
) => {
return (dispatch: Dispatch<NotificationBoxAction>) => {
dispatch({
type: NotificationBoxActionTypes.SET_NOTIFICATION_DATA,
payload: data,
});
};
};
32 changes: 32 additions & 0 deletions client/src/services/redux/components/notificationBox/reducer.ts
@@ -0,0 +1,32 @@
import {
NotificationBoxState,
NotificationBoxAction,
NotificationBoxActionTypes,
} from "./types";

const initialState: NotificationBoxState = {
notificationData: [],
open: false,
};

const notificationBoxReducer = (
state: NotificationBoxState = initialState,
action: NotificationBoxAction
): NotificationBoxState => {
switch (action.type) {
case NotificationBoxActionTypes.OPEN_NOTIFICATION_BOX:
return {
...state,
open: action.payload,
};
case NotificationBoxActionTypes.SET_NOTIFICATION_DATA:
return {
...state,
notificationData: action.payload,
};
default:
return state;
}
};

export default notificationBoxReducer;
20 changes: 20 additions & 0 deletions client/src/services/redux/components/notificationBox/types.ts
@@ -0,0 +1,20 @@
export interface NotificationBoxState {
notificationData: [];
open: boolean;
}

export enum NotificationBoxActionTypes {
OPEN_NOTIFICATION_BOX = "openNotificationBox",
SET_NOTIFICATION_DATA = "setNotificationData",
}
export interface OpenNotificationBox {
type: NotificationBoxActionTypes.OPEN_NOTIFICATION_BOX;
payload: any;
}

export interface SetNotificationData {
type: NotificationBoxActionTypes.SET_NOTIFICATION_DATA;
payload: any;
}

export type NotificationBoxAction = OpenNotificationBox | SetNotificationData;
2 changes: 2 additions & 0 deletions client/src/services/redux/reducer.ts
Expand Up @@ -2,11 +2,13 @@ import { combineReducers } from "redux";
import rootUserProfileDetailReducer from "./global/rootUserProfileDetail/reducer";
import rootUserFriendsReducer from "./global/rootUserFriends/reducer";
import commentBoxReducer from "./components/commentBox/reducer";
import notificationBoxReducer from "./components/notificationBox/reducer";

const reducer = combineReducers({
rootUserProfileDetailReducer,
rootUserFriendsReducer,
commentBoxReducer,
notificationBoxReducer,
});

export default reducer;

0 comments on commit b5641f7

Please sign in to comment.