Skip to content

Commit

Permalink
issue #138 refactor: group post info api change, unused state delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sikkzz committed Feb 26, 2024
1 parent c4e6b58 commit 4092e94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/components/Group/GroupFeed/GroupFeed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FeedSection } from "./GroupFeed.styles";
const GroupFeed = ({ groupId, leaderName }) => {
const dispatch = useDispatch();

const { allGroupPosts, allGroupPostsIsEnd, isLoading } = useSelector(
const { allGroupPosts, allGroupPostsIsEnd } = useSelector(
(state) => state.post,
);

Expand All @@ -28,10 +28,6 @@ const GroupFeed = ({ groupId, leaderName }) => {
}
};

if (isLoading) {
return <div>피드 정보 불러오는 중...</div>;
}

if (allGroupPosts.length === 0) {
return <EmptyFeed />;
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/post/post-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const getGroupAllPosts = createAsyncThunk(
},
);

export const getGroupPosts = createAsyncThunk(
"post/getGroupPosts",
export const getGroupPostInfo = createAsyncThunk(
"post/getGroupPostInfo",
async ({ groupId, postId }, thunkAPI) => {
const data = await commonThunk(
{
Expand Down
15 changes: 7 additions & 8 deletions src/features/post/post-slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,30 @@ import { createSlice, isAnyOf } from "@reduxjs/toolkit";

import {
getGroupAllPosts,
getGroupPosts,
getGroupPostInfo,
getMyGroupPosts,
likeGroupPost,
cancelLikeGroupPost,
deleteGroupPost,
} from "./post-service";

const initialState = {
currentGroupPost: null,
postInfo: null,
allGroupPosts: [],
myGroupPosts: [],
allGroupPostslastRecordId: 0,
allGroupPostsIsEnd: false,
myGroupPostslastRecordId: 0,
isLoading: true,
isEnd: false,
isEmpty: false,
};

const postSlice = createSlice({
name: "post",
initialState,
reducers: {
resetPostStateForGroupPage: (state) => {
state.currentGroupPost = null;
state.postInfo = null;
state.allGroupPosts = [];
state.allGroupPostslastRecordId = 0;
state.allGroupPostsIsEnd = false;
Expand All @@ -47,9 +46,9 @@ const postSlice = createSlice({
payload.feed[payload.feed.length - 1].postId;
}
})
.addCase(getGroupPosts.fulfilled, (state, { payload }) => {
.addCase(getGroupPostInfo.fulfilled, (state, { payload }) => {
state.isLoading = false;
state.currentGroupPost = payload;
state.postInfo = payload;
})
.addCase(getMyGroupPosts.fulfilled, (state, { payload }) => {
state.isLoading = false;
Expand Down Expand Up @@ -84,7 +83,7 @@ const postSlice = createSlice({
.addMatcher(
isAnyOf(
getGroupAllPosts.pending,
getGroupPosts.pending,
getGroupPostInfo.pending,
getMyGroupPosts.pending,
likeGroupPost.pending,
cancelLikeGroupPost.pending,
Expand All @@ -97,7 +96,7 @@ const postSlice = createSlice({
.addMatcher(
isAnyOf(
getGroupAllPosts.rejected,
getGroupPosts.rejected,
getGroupPostInfo.rejected,
getMyGroupPosts.rejected,
likeGroupPost.rejected,
cancelLikeGroupPost.rejected,
Expand Down

0 comments on commit 4092e94

Please sign in to comment.