Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { type ProfileResponse, type UpdateUserProfileRequest } from './types';
export * from './types';

export const getProfileEdit = async (): Promise<ProfileResponse> => {
const { data } = await apiClient.get<ProfileResponse>('/users/profile/edit');
const { data } = await apiClient.get<ProfileResponse>('/users/me/profile/edit');
return data;
};

export const updateUserProfile = async (payload: UpdateUserProfileRequest) => {
const { data } = await apiClient.patch<ProfileResponse>('/users/profile', payload);
const { data } = await apiClient.patch<ProfileResponse>('/users/me/profile', payload);
return data;
};
4 changes: 2 additions & 2 deletions src/api/records/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { apiClient } from '@src/api/client_auth';
import { ActivityListResponse, RecordSummaryResponse } from '@src/api/records/types';

export const getActivityList = async (year: number, month: number) => {
const { data } = await apiClient.get<ActivityListResponse>('/users/stats/calendar', {
const { data } = await apiClient.get<ActivityListResponse>('/users/me/stats/calendar', {
params: { year, month },
});
return data;
};

export const getRecordSummary = async () => {
const { data } = await apiClient.get<RecordSummaryResponse>('/users/stats/summary');
const { data } = await apiClient.get<RecordSummaryResponse>('/users/me/stats/summary');
return data;
};
12 changes: 6 additions & 6 deletions src/api/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type GetProfileResponse = {

// 프로필 조회 (프로필 이미지 동기화용)
export async function getProfileImageAPI(): Promise<ProfileData> {
const { data } = await apiClient.get<GetProfileResponse>('/users/profile/edit');
const { data } = await apiClient.get<GetProfileResponse>('/users/me/profile/edit');
if (data.result !== 'SUCCESS' || !data.data) {
throw new Error(data.message ?? '프로필을 불러오지 못했습니다.');
}
Expand Down Expand Up @@ -92,7 +92,7 @@ function getServerMessage(error: unknown, fallbackMessage: string): string {
export async function updateProfile(payload: UpdateProfilePayload): Promise<void> {
try {
const { data } = await apiClient.patch<UpdateProfileResponse>(
'/users/profile',
'/users/me/profile',
payload,
);
if (data.result !== 'SUCCESS') {
Expand All @@ -111,13 +111,13 @@ export async function updateProfile(payload: UpdateProfilePayload): Promise<void
export * from '@src/api/users/types';

export const getMyProfile = async () => {
const { data } = await apiClient.get<UserProfileSummaryResponse>('/users');
const { data } = await apiClient.get<UserProfileSummaryResponse>('/users/me');
return data;
};

export const getMyProfileGallery = async (cursor?: number, size = 20) => {
const { data } = await apiClient.get<UserProfileGalleryResponse>(
'/users/profile/gallery',
'/users/me/profile/gallery',
{
params: {
...(cursor != null ? { cursor } : {}),
Expand All @@ -129,14 +129,14 @@ export const getMyProfileGallery = async (cursor?: number, size = 20) => {
};

export const getFollowings = async (params: GetFollowingsParams) => {
const { data } = await apiClient.get<FollowingsResponse>('/users/followings', {
const { data } = await apiClient.get<FollowingsResponse>('/users/me/followings', {
params,
});
return data;
};

export const getFollowers = async (params: GetFollowersParams) => {
const { data } = await apiClient.get<FollowersResponse>('/users/followers', {
const { data } = await apiClient.get<FollowersResponse>('/users/me/followers', {
params,
});
return data;
Expand Down
3 changes: 3 additions & 0 deletions src/components/CommentBottomSheet/CommentBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { PostCommentItem } from '@src/api/posts/types';
import { getProfileImageAPI } from '@src/api/users';
import { getProfileImageMMKV, NO_IMAGE_SENTINEL } from '@src/storage/profileStorage';
import { getUserId } from '@src/api/authStorage';
import { usePostSocialStore } from '@src/store/postSocialStore';
import { styles } from './CommentBottomSheet.styles';

export type CommentBottomSheetType = 'dark' | 'light';
Expand Down Expand Up @@ -245,6 +246,7 @@ const CommentBottomSheet = ({
try {
await deletePostComment(postId, selectedComment.id);
setComments((prev) => prev.filter((c) => c.id !== selectedComment.id));
usePostSocialStore.getState().decrementComment(postId);
handleCommentActionClose();
} catch {
handleCommentActionClose();
Expand Down Expand Up @@ -292,6 +294,7 @@ const CommentBottomSheet = ({
};

setComments((prev) => [newComment, ...prev]);
usePostSocialStore.getState().incrementComment(postId);
onCommentCreated?.(postId);

setTimeout(() => {
Expand Down
90 changes: 35 additions & 55 deletions src/screens/HomeScreen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ContentActionBottomSheet from '@src/components/ContentActionBottomSheet/C
import type { ContentActionBottomSheetMode } from '@src/components/ContentActionBottomSheet/ContentActionBottomSheet';
import { getAndClearPostEdited } from '@src/store/postEditedStore';
import { useNotificationCountStore } from '@src/store/notificationCountStore';
import { usePostSocialStore } from '@src/store/postSocialStore';
import { styles } from './HomeScreen.styles';

export default function HomeScreen() {
Expand All @@ -56,6 +57,8 @@ export default function HomeScreen() {

const activitySimplesRef = useRef<ActivitySimple[]>([]);
const notificationCount = useNotificationCountStore((state) => state.count);
const { setSocials, toggleLike, rollbackLike } = usePostSocialStore();
const socialMap = usePostSocialStore((state) => state.socials);
useEffect(() => {
activitySimplesRef.current = activitySimples;
}, [activitySimples]);
Expand All @@ -77,6 +80,16 @@ export default function HomeScreen() {
const res = await getHomePosts(pageToLoad, HOME_POST_PAGE_SIZE);
const list = res.data?.activitySimples ?? [];
setActivitySimples((prev) => (append ? [...prev, ...list] : list));
setSocials(
list.map((item) => ({
postId: item.id,
social: {
likeCount: item.social.likeCount,
commentCount: item.social.commentCount,
isLiked: item.social.isLiked,
},
})),
);
setPage(res.data.page);
setHasNext(res.data.hasNext);
} catch (e) {
Expand Down Expand Up @@ -155,45 +168,22 @@ export default function HomeScreen() {
void userId;
}, []);

const handleItemLikePress = useCallback(async (itemId: number) => {
const target = activitySimplesRef.current.find((item) => item.id === itemId);
if (!target) return;
const wasLiked = target.social.isLiked;

setActivitySimples((prev) =>
prev.map((item) =>
item.id === itemId
? {
...item,
social: {
...item.social,
isLiked: !wasLiked,
likeCount: item.social.likeCount + (wasLiked ? -1 : 1),
},
}
: item,
),
);
const handleItemLikePress = useCallback(
async (itemId: number) => {
const social = usePostSocialStore.getState().getSocial(itemId);
if (!social) return;
const wasLiked = social.isLiked;

try {
await (wasLiked ? unlikePost(itemId) : likePost(itemId));
} catch {
setActivitySimples((prev) =>
prev.map((item) =>
item.id === itemId // API 호출 실패시 UI 복구 처리
? {
...item,
social: {
...item.social,
isLiked: wasLiked,
likeCount: item.social.likeCount + (wasLiked ? 1 : -1),
},
}
: item,
),
);
}
}, []);
toggleLike(itemId);

try {
await (wasLiked ? unlikePost(itemId) : likePost(itemId));
} catch {
rollbackLike(itemId);
}
},
[toggleLike, rollbackLike],
);

const handleItemCommentPress = useCallback((itemId: number) => {
setSelectedPostId(itemId);
Expand Down Expand Up @@ -249,20 +239,8 @@ export default function HomeScreen() {
setSelectedPostId(null);
}, []);

const handleCommentCreated = useCallback((postId: number) => {
setActivitySimples((prev) =>
prev.map((item) =>
item.id === postId
? {
...item,
social: {
...item.social,
commentCount: item.social.commentCount + 1,
},
}
: item,
),
);
const handleCommentCreated = useCallback(() => {
// store에서 직접 처리됨 (CommentBottomSheet 내부)
}, []);

const handleItemSharePress = useCallback((itemId: number, url: string) => {
Expand Down Expand Up @@ -290,6 +268,7 @@ export default function HomeScreen() {

const renderActivityItem = useCallback<ListRenderItem<ActivitySimple>>(
({ item }) => {
const social = socialMap[item.id];
return (
<ActivityListItem
userName={item.author.nickname}
Expand All @@ -298,9 +277,9 @@ export default function HomeScreen() {
areaInfo={item.location.address}
title={item.activity.title}
body={item.activity.body}
likeCount={item.social.likeCount}
commentCount={item.social.commentCount}
isLiked={item.social.isLiked}
likeCount={social?.likeCount ?? item.social.likeCount}
commentCount={social?.commentCount ?? item.social.commentCount}
isLiked={social?.isLiked ?? item.social.isLiked}
stats={item.stats}
map={item.map ?? undefined}
itemId={item.id}
Expand All @@ -316,6 +295,7 @@ export default function HomeScreen() {
);
},
[
socialMap,
handleItemPress,
handleItemProfilePress,
handleItemLikePress,
Expand Down
Loading
Loading