Skip to content

Commit

Permalink
fix(redux); added ts on stories
Browse files Browse the repository at this point in the history
fixing #109
  • Loading branch information
roman-ojha committed Jun 24, 2022
1 parent 1b6e55c commit b0e667c
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 18 deletions.
4 changes: 2 additions & 2 deletions client/src/components/MainPageStoryComp/FriendStory.jsx
Expand Up @@ -13,7 +13,7 @@ const FriendStory = (props) => {
<div
onClick={() => {
dispatch(storyIndex(props.index));
history.push("/u/story");
history.push("/u/stories");
}}
className="Friends_Story_Picutre_Container"
>
Expand All @@ -31,7 +31,7 @@ const FriendStory = (props) => {
className="Friend_Story_Name"
onClick={() => {
dispatch(storyIndex(props.index));
history.push("/u/story");
history.push("/u/stories");
}}
>
{props.storiesInformation.name.split(" ")[0]}
Expand Down
4 changes: 1 addition & 3 deletions client/src/index.tsx
Expand Up @@ -12,9 +12,7 @@ import tsStore from "./services/redux/store";
ReactDOM.render(
<BrowserRouter>
<Provider store={store}>
<Provider store={tsStore}>
<App />
</Provider>
<App />
</Provider>
</BrowserRouter>,

Expand Down
12 changes: 6 additions & 6 deletions client/src/services/redux-actions/index.js
Expand Up @@ -299,9 +299,9 @@ export const showLoadingSpinner = (bool) => {
};
};

export const setVideoPageData = (data) => {
return {
type: "setVideoPageData",
payload: data,
};
};
// export const setVideoPageData = (data) => {
// return {
// type: "setVideoPageData",
// payload: data,
// };
// };
6 changes: 4 additions & 2 deletions client/src/services/redux-reducer/index.js
Expand Up @@ -22,13 +22,14 @@ import homePagePostFieldViewValue from "./page/home/homePagePostFieldViewValue";
import notificationBox from "./components/notificationBox";
import moreProfileBoxReducer from "./components/moreProfile";
import showLoadingSpinnerReducer from "./components/showLoadingSpinner";
import videoPageDataReducer from "./page/video";
// import videoPageDataReducer from "./page/video";
import rootUserFriends from "./global/rootUserFriends";
import rootUserProfileDataState from "./page/profile/rootUserProfileDataState";
import displayEmojiPicker from "./page/home/displayEmojiPicker";
// Typescript
// import userProfileDetailReducer from "./global/rootUserProfileDetail/reducer";
// import rootUserFriends from "./global/rootUserFriends/reducer";
import videoPageDataReducer from "../redux/pages/video/reducer";

const rootReducers = combineReducers({
// Javascript
Expand All @@ -55,12 +56,13 @@ const rootReducers = combineReducers({
notificationBox,
moreProfileBoxReducer,
showLoadingSpinnerReducer,
videoPageDataReducer,
// videoPageDataReducer,
rootUserProfileDataState,
displayEmojiPicker,
// Typescript
// userProfileDetailReducer,
// rootUserFriends,
videoPageDataReducer,
});

export default rootReducers;
1 change: 1 addition & 0 deletions client/src/services/redux/action.ts
Expand Up @@ -3,3 +3,4 @@ export * from "./global/rootUserProfileDetail/action";
export * from "./components/commentBox/action";
export * from "./components/notificationBox/action";
export * from "./pages/video/action";
export * from "./pages/stories/action";
24 changes: 24 additions & 0 deletions client/src/services/redux/pages/stories/action.ts
@@ -0,0 +1,24 @@
import {
StoriesPageAction,
StoriesPageState,
StoriesPageActionTypes,
} from "./types";
import { Dispatch } from "react";

export const setUserStories = (data: any) => {
return (dispatch: Dispatch<StoriesPageAction>) => {
dispatch({
type: StoriesPageActionTypes.SET_USER_STORIES,
payload: data,
});
};
};

export const setStoryIndex = (data: StoriesPageState["storyIndex"]) => {
return (dispatch: Dispatch<StoriesPageAction>) => {
dispatch({
type: StoriesPageActionTypes.SET_STORY_INDEX,
payload: data,
});
};
};
38 changes: 38 additions & 0 deletions client/src/services/redux/pages/stories/reducer.ts
@@ -0,0 +1,38 @@
import {
StoriesPageAction,
StoriesPageState,
StoriesPageActionTypes,
} from "./types";

const initialState: StoriesPageState = {
storyIndex: 0,
data: [],
};

const userStoriesReducer = (
state: StoriesPageState = initialState,
action: StoriesPageAction
) => {
switch (action.type) {
case StoriesPageActionTypes.SET_USER_STORIES:
return {
...state,
data: action.payload.sort((a, b) => {
if (a.type !== "bot" || b.type !== "bot") {
return;
} else {
return Math.random() - 0.5;
}
}),
};
case StoriesPageActionTypes.SET_STORY_INDEX:
return {
...state,
storyIndex: action.payload,
};
default:
return state;
}
};

export default userStoriesReducer;
22 changes: 22 additions & 0 deletions client/src/services/redux/pages/stories/types.ts
@@ -0,0 +1,22 @@
import { YoutubeVideos } from "../../../../interface/youtubeVideos";

export interface StoriesPageState {
storyIndex: number;
data: [];
}

export enum StoriesPageActionTypes {
SET_USER_STORIES = "setUserStories",
SET_STORY_INDEX = "setStoryIndex",
}
export interface SetUserStoriesAction {
type: StoriesPageActionTypes.SET_USER_STORIES;
payload: any;
}

export interface SetStoriesIndexAction {
type: StoriesPageActionTypes.SET_STORY_INDEX;
payload: number;
}

export type StoriesPageAction = SetUserStoriesAction | SetStoriesIndexAction;
6 changes: 1 addition & 5 deletions client/src/services/redux/pages/video/types.ts
@@ -1,10 +1,6 @@
import { YoutubeVideos } from "../../../../interface/youtubeVideos";

export interface VideoPageState extends YoutubeVideos {
// videoId: string;
// title: string;
// thumbnail: string;
}
export interface VideoPageState extends YoutubeVideos {}

export enum VideoPageActionTypes {
SET_VIDEO_PAGE_DATA = "setVideoPageData",
Expand Down
2 changes: 2 additions & 0 deletions client/src/services/redux/reducer.ts
Expand Up @@ -4,13 +4,15 @@ import rootUserFriendsReducer from "./global/rootUserFriends/reducer";
import commentBoxReducer from "./components/commentBox/reducer";
import notificationBoxReducer from "./components/notificationBox/reducer";
import videoPageDataReducer from "./pages/video/reducer";
import userStoriesReducer from "./pages/stories/reducer";

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

export default reducer;

0 comments on commit b0e667c

Please sign in to comment.