Skip to content

Commit

Permalink
fix(redux): added Profile page
Browse files Browse the repository at this point in the history
fixing #109
  • Loading branch information
roman-ojha committed Jun 24, 2022
1 parent a6b76b1 commit 08f03a2
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/src/services/redux/action.ts
Expand Up @@ -5,3 +5,6 @@ export * from "./components/notificationBox/action";
export * from "./components/followedByUser/action";
export * from "./pages/video/action";
export * from "./pages/stories/action";
export * from "./pages/profile/profilePageData/action";
export * from "./pages/profile/rootUserProfileData/action";
export * from "./pages/profile/userProfilePost/action";
48 changes: 48 additions & 0 deletions client/src/services/redux/pages/profile/profilePageData/action.ts
@@ -0,0 +1,48 @@
import {
ProfilePageAction,
ProfilePageDataActionTypes,
ProfilePageDataState,
} from "./types";
import { Dispatch } from "react";

export const profilePageDataAction = (data: ProfilePageDataState) => {
return (dispatch: Dispatch<ProfilePageAction>) => {
dispatch({
type: ProfilePageDataActionTypes.PROFILE_PAGE_DATA_ACTION,
payload: data,
});
};
};

export const setProfilePageFriends = (
data: ProfilePageDataState["friends"]
) => {
return (dispatch: Dispatch<ProfilePageAction>) => {
dispatch({
type: ProfilePageDataActionTypes.SET_PROFILE_PAGE_FRIENDS,
payload: data,
});
};
};

export const setProfilePageFollowers = (
data: ProfilePageDataState["followers"]
) => {
return (dispatch: Dispatch<ProfilePageAction>) => {
dispatch({
type: ProfilePageDataActionTypes.SET_PROFILE_PAGE_FOLLOWERS,
payload: data,
});
};
};

export const setProfilePageFollowings = (
data: ProfilePageDataState["followings"]
) => {
return (dispatch: Dispatch<ProfilePageAction>) => {
dispatch({
type: ProfilePageDataActionTypes.SET_PROFILE_PAGE_FOLLOWINGS,
payload: data,
});
};
};
42 changes: 42 additions & 0 deletions client/src/services/redux/pages/profile/profilePageData/reducer.ts
@@ -0,0 +1,42 @@
import {
ProfilePageAction,
ProfilePageDataActionTypes,
ProfilePageDataState,
} from "./types";

const initialState: ProfilePageDataState = {
userID: "",
post: [],
friends: [],
followings: [],
followers: [],
};

const profilePageDataReducer = (
state: ProfilePageDataState = initialState,
action: ProfilePageAction
) => {
switch (action.type) {
case ProfilePageDataActionTypes.PROFILE_PAGE_DATA_ACTION:
return action.payload;
case ProfilePageDataActionTypes.SET_PROFILE_PAGE_FRIENDS:
return {
...state,
friends: action.payload,
};
case ProfilePageDataActionTypes.SET_PROFILE_PAGE_FOLLOWERS:
return {
...state,
followers: action.payload,
};
case ProfilePageDataActionTypes.SET_PROFILE_PAGE_FOLLOWINGS:
return {
...state,
followings: action.payload,
};
default:
return state;
}
};

export default profilePageDataReducer;
39 changes: 39 additions & 0 deletions client/src/services/redux/pages/profile/profilePageData/types.ts
@@ -0,0 +1,39 @@
export interface ProfilePageDataState {
userID: string;
post: [];
friends: [];
followings: [];
followers: [];
}

export enum ProfilePageDataActionTypes {
PROFILE_PAGE_DATA_ACTION = "profilePageDataAction",
SET_PROFILE_PAGE_FRIENDS = "setProfilePageFriends",
SET_PROFILE_PAGE_FOLLOWERS = "setProfilePageFollowers",
SET_PROFILE_PAGE_FOLLOWINGS = "setProfilePageFollowings",
}
export interface ProfilePageDataAction {
type: ProfilePageDataActionTypes.PROFILE_PAGE_DATA_ACTION;
payload: any;
}

export interface SetProfilePageFriendsAction {
type: ProfilePageDataActionTypes.SET_PROFILE_PAGE_FRIENDS;
payload: any;
}

export interface SetProfilePageFollowersAction {
type: ProfilePageDataActionTypes.SET_PROFILE_PAGE_FOLLOWERS;
payload: any;
}

export interface SetProfilePageFollowingAction {
type: ProfilePageDataActionTypes.SET_PROFILE_PAGE_FOLLOWINGS;
payload: any;
}

export type ProfilePageAction =
| ProfilePageDataAction
| SetProfilePageFollowersAction
| SetProfilePageFriendsAction
| SetProfilePageFollowingAction;
@@ -0,0 +1,15 @@
import {
RootUserProfileDataAction,
RootUserProfileDataActionTypes,
RootUserProfileDataState,
} from "./types";
import { Dispatch } from "react";

export const setRootUserProfileDataState = (data: RootUserProfileDataState) => {
return (dispatch: Dispatch<RootUserProfileDataAction>) => {
dispatch({
type: RootUserProfileDataActionTypes.SET_ROOT_USER_PROFILE_DATA_STATE,
payload: data,
});
};
};
@@ -0,0 +1,24 @@
import {
RootUserProfileDataAction,
RootUserProfileDataActionTypes,
RootUserProfileDataState,
} from "./types";

const initialState: RootUserProfileDataState = {
fetchedRootUserProfileData: false,
getRootUserProfileData: false,
};

const rootUserProfileDataState = (
state: RootUserProfileDataState = initialState,
action: RootUserProfileDataAction
) => {
switch (action.type) {
case RootUserProfileDataActionTypes.SET_ROOT_USER_PROFILE_DATA_STATE:
return action.payload;
default:
return state;
}
};

export default rootUserProfileDataState;
@@ -0,0 +1,14 @@
export interface RootUserProfileDataState {
fetchedRootUserProfileData: boolean;
getRootUserProfileData: boolean;
}

export enum RootUserProfileDataActionTypes {
SET_ROOT_USER_PROFILE_DATA_STATE = "setRootUserProfileDataState",
}
export interface SetRootUserProfileDataState {
type: RootUserProfileDataActionTypes.SET_ROOT_USER_PROFILE_DATA_STATE;
payload: RootUserProfileDataState;
}

export type RootUserProfileDataAction = SetRootUserProfileDataState;
15 changes: 15 additions & 0 deletions client/src/services/redux/pages/profile/userProfilePost/action.ts
@@ -0,0 +1,15 @@
import {
UserProfilePostActionTypes,
UserProfilePostState,
UserProfilePostAction,
} from "./types";
import { Dispatch } from "react";

export const userProfilePost = (data: UserProfilePostState) => {
return (dispatch: Dispatch<UserProfilePostAction>) => {
dispatch({
type: UserProfilePostActionTypes.SET_USER_PROFILE_POST,
payload: data,
});
};
};
21 changes: 21 additions & 0 deletions client/src/services/redux/pages/profile/userProfilePost/reducer.ts
@@ -0,0 +1,21 @@
import {
UserProfilePostAction,
UserProfilePostActionTypes,
UserProfilePostState,
} from "./types";

const initialState: UserProfilePostState = [];
// this store the user Post data
const setUserProfilePostReducer = (
state: UserProfilePostState = initialState,
action: UserProfilePostAction
) => {
switch (action.type) {
case UserProfilePostActionTypes.SET_USER_PROFILE_POST:
return action.payload;
default:
return state;
}
};

export default setUserProfilePostReducer;
12 changes: 12 additions & 0 deletions client/src/services/redux/pages/profile/userProfilePost/types.ts
@@ -0,0 +1,12 @@
export interface UserProfilePostState {}

export enum UserProfilePostActionTypes {
SET_USER_PROFILE_POST = "userProfilePost",
}

export interface SetUserProfilePostAction {
type: UserProfilePostActionTypes.SET_USER_PROFILE_POST;
payload: UserProfilePostState;
}

export type UserProfilePostAction = SetUserProfilePostAction;
2 changes: 0 additions & 2 deletions client/src/services/redux/pages/stories/types.ts
@@ -1,5 +1,3 @@
import { YoutubeVideos } from "../../../../interface/youtubeVideos";

export interface StoriesPageState {
storyIndex: number;
data: [];
Expand Down
6 changes: 6 additions & 0 deletions client/src/services/redux/reducer.ts
Expand Up @@ -6,6 +6,9 @@ import followedByUserReducer from "./components/followedByUser/reducer";
import notificationBoxReducer from "./components/notificationBox/reducer";
import videoPageDataReducer from "./pages/video/reducer";
import userStoriesReducer from "./pages/stories/reducer";
import profilePageDataReducer from "./pages/profile/profilePageData/reducer";
import rootUserProfileDataState from "./pages/profile/rootUserProfileData/reducer";
import setUserProfilePostReducer from "./pages/profile/userProfilePost/reducer";

const reducer = combineReducers({
setUserProfileDetailReducer,
Expand All @@ -15,6 +18,9 @@ const reducer = combineReducers({
videoPageDataReducer,
userStoriesReducer,
followedByUserReducer,
profilePageDataReducer,
rootUserProfileDataState,
setUserProfilePostReducer,
});

export default reducer;

0 comments on commit 08f03a2

Please sign in to comment.