Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Profile User Api #79

Merged
merged 26 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
76f9206
feat: PageHeader.scss 수정
Legitgoons May 24, 2024
3efc682
feat: useGetUser hook 구현
Legitgoons May 24, 2024
6d20865
feat: ProfileUser useGetUser 사용
Legitgoons May 24, 2024
d4621ef
feat: user.ts Fetch interface 구현
Legitgoons May 24, 2024
eac07d4
feat: profileImage Link 경로 수정
Legitgoons May 24, 2024
fa5756c
feat: Feed 내 Profile 경로 props 추가
Legitgoons May 24, 2024
0e4beb4
feat: types/index.ts 수정
Legitgoons May 24, 2024
36ce49d
feat: ProfileMainPage 수정
Legitgoons May 24, 2024
3cb4e26
feat: Router index 수정
Legitgoons May 24, 2024
5019432
fix: ProfileUser 컴포넌트 수정
Legitgoons May 24, 2024
6289ee5
fix: shared/consts/types/index.ts 수정
Legitgoons May 26, 2024
7e847ae
Merge branch 'feature/PW-346-profile-api' of https://github.com/Colla…
Legitgoons May 26, 2024
19cbeec
feat: ProfileMainPage useEffect 삭제
Legitgoons May 26, 2024
3a9cef7
feat: ProfileUser 수정
Legitgoons May 26, 2024
9ffbabf
feat: ProfileUser 컴포넌트 icon 추가
Legitgoons May 26, 2024
21d195f
feat: ProfileUserImage 컴포넌트 구현
Legitgoons May 29, 2024
4594567
feat: ProfileUser에서 ProfileUserImage 컴포넌트 분리 적용
Legitgoons May 29, 2024
4efb10c
refactor: ProfileMainPage 분기처리 리팩토링
Legitgoons May 29, 2024
8512416
feat: shared/ProfileImage 컴포넌트 구현
Legitgoons May 29, 2024
b70eef2
feat: shared/Profile ProfileImage컴포넌트 적용 및 isLink prop 추가
Legitgoons May 29, 2024
eb8b944
feat: Feed 컴포넌트 isLink prop 추가
Legitgoons May 29, 2024
4531af2
feat: FeedMainList 내부 Feed 컴포넌트에 isLink prop 설정
Legitgoons May 29, 2024
f5cbb5d
feat: ProfileFeedList 내부 Feed 컴포넌트에 isLink prop 설정
Legitgoons May 29, 2024
f98f6bf
feat: ProfileUserImage 내 NoProfileIcon SVG 추가
Legitgoons May 29, 2024
6a734f9
feat: useGetUser enalbed 삭제
Legitgoons May 29, 2024
fe4a12c
feat: ProfileMainPage 내 ProfileFeedList 제거
Legitgoons May 29, 2024
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
2 changes: 1 addition & 1 deletion src/app/routers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const root: RouteObject[] = [
element: <IPhoneLayout />,
children: [
{ index: true, element: <FeedMainPage /> },
{ path: 'user', element: <ProfileMainPage /> },
{ path: 'users/:userId', element: <ProfileMainPage /> },
],
},
];
Expand Down
18 changes: 13 additions & 5 deletions src/pages/profile/ui/ProfileMainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { ProfileFeedList } from '@/widgets/profile-feed-list';
import { ProfileHeader } from '@/widgets/profile-header';
import { useParams } from 'react-router-dom';

import { ProfileUser } from '@/widgets/profile-user';

/**
* @todo userPK값 가져와서 판별하도록 구현
* @todo ProfileFeed Api 구현 후, ProfileFeedList 컴포넌트 연결
*/

export const ProfileMainPage = () => {
const { userId } = useParams<{ userId: string }>();
const formattedUserId = Number(userId);

const owner = formattedUserId === 1 ? true : false;

return (
<main>
<ProfileHeader name='2weeksone' />
<ProfileUser />
<ProfileFeedList />
<ProfileUser userId={formattedUserId} isOwner={owner} />
</main>
);
};
2 changes: 1 addition & 1 deletion src/shared/consts/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type * from './feed';
export type { Comment } from './comment';
export type { Like } from './like';
export type { User, RelationshipStatus } from './user';
export type * from './user';
export type { ProfileFeed } from './profileFeed';
24 changes: 24 additions & 0 deletions src/shared/consts/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,28 @@ export interface User {
followerCount: number;
}

export interface FetchUser {
code: string;
data: {
user: {
id: number;
profileImage: string;
name: string;
content: string;
locked: boolean;

feedCount: number;
followingCount: number;
followerCount: number;
};
};
}

export type RelationshipStatus = 'self' | 'following' | 'none' | 'pending';

export interface FetchRelationshipStatus {
code: string;
data: {
relationshipStatus: RelationshipStatus;
};
}
1 change: 1 addition & 0 deletions src/shared/react-query/consts/keys.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const QUERY_KEYS = Object.freeze({
feeds: 'feeds',
users: 'users',
});
2 changes: 1 addition & 1 deletion src/shared/ui/header/PageHeader.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.page-header {
width: 320px;
width: 100%;
height: 44px;
display: flex;
align-items: center;
Expand Down
24 changes: 0 additions & 24 deletions src/shared/ui/profile/Profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,6 @@
border: none;
background-color: white;

.profile-image {
width: 32px;
height: 32px;

border-radius: 50%;
overflow: hidden;
}

.no-proile-background {
position: relative;
width: 32px;
height: 32px;
border-radius: 50%;
overflow: hidden;

background: $gray3;

svg {
z-index: 1;
position: absolute;
bottom: 0;
}
}

.name-section {
margin-left: 8px;

Expand Down
36 changes: 17 additions & 19 deletions src/shared/ui/profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import { Link } from 'react-router-dom';

import { Icon } from '..';
import ProfileImage from './ProfileImage';
import './Profile.scss';

interface ProfileProps {
profileImage: string;
name: string;
content: string;
userId: number;
isLink: boolean;
}

/**
* @todo 임시로 구현된 Link, 추후 적절한 user로 이동하도록 수정
*/

export const Profile = ({ profileImage, name, content }: ProfileProps) => {
export const Profile = ({
profileImage,
name,
content,
userId,
isLink,
}: ProfileProps) => {
return (
<div className='profile'>
<Link to={'/user'}>
{profileImage ? (
<img
className='profile-image'
src={profileImage}
alt={`${name} profile image`}
/>
) : (
<div className='no-proile-background'>
<Icon name='no-profile' width='32' height='32' />
</div>
)}
</Link>
{isLink ? (
<Link to={`/users/${userId}`}>
<ProfileImage profileImage={profileImage} name={name} />
</Link>
) : (
<ProfileImage profileImage={profileImage} name={name} />
)}
<div className='name-section'>
<h5 className='name b1semi'>{name}</h5>
<p className='content b3md'>{content}</p>
Expand Down
23 changes: 23 additions & 0 deletions src/shared/ui/profile/ProfileImage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.profile-image {
width: 32px;
height: 32px;

border-radius: 50%;
overflow: hidden;
}

.no-proile-background {
position: relative;
width: 32px;
height: 32px;
border-radius: 50%;
overflow: hidden;

background: $gray3;

svg {
z-index: 1;
position: absolute;
bottom: 0;
}
}
22 changes: 22 additions & 0 deletions src/shared/ui/profile/ProfileImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Icon } from '..';
import './ProfileImage.scss';

interface ProfileImageProps {
profileImage: string;
name: string;
}

const ProfileImage = ({ profileImage, name }: ProfileImageProps) => {
return profileImage ? (
<img
className='profile-image'
src={profileImage}
alt={`${name} profile image`}
/>
) : (
<div className='no-proile-background'>
<Icon name='no-profile' width='32' height='32' />
</div>
);
};
export default ProfileImage;
7 changes: 6 additions & 1 deletion src/widgets/feed-main-list/ui/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { FeedKebabButton } from '@/widgets/feed-kebab';

import './Feed.scss';

export const Feed: React.FC<{ feed: FeedProps }> = ({ feed }) => {
export const Feed: React.FC<{ isLink: boolean; feed: FeedProps }> = ({
feed,
isLink,
}) => {
const {
id,
user,
Expand All @@ -29,6 +32,8 @@ export const Feed: React.FC<{ feed: FeedProps }> = ({ feed }) => {
profileImage={user.profileImage}
name={user.name}
content={calculateElapsedTime(updatedAt)}
userId={user.id}
isLink={isLink}
/>

<FeedKebabButton feedId={id} />
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/feed-main-list/ui/FeedMainList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const FeedMainList = () => {
return hiddenType ? (
<HiddenFeed key={feed.id} feedId={feed.id} type={hiddenType} />
) : (
<Feed key={feed.id} feed={feed} />
<Feed key={feed.id} feed={feed} isLink />
);
});
})}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/profile-feed-list/ui/ProfileFeedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const ProfileFeedList = () => {
<h3 className='feed-list-title b1md'>내 게시글</h3>
{dummyFeeds.map((dummyFeed) => (
<div className='profile-feed' key={dummyFeed.id}>
<Feed feed={dummyFeed} />
<Feed feed={dummyFeed} isLink={false} />
</div>
))}
</section>
Expand Down
1 change: 1 addition & 0 deletions src/widgets/profile-user/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useGetUser } from './useGetUser';
29 changes: 29 additions & 0 deletions src/widgets/profile-user/api/useGetUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useQuery } from '@tanstack/react-query';

import { axiosInstance } from '@/shared/axios';
import { FetchUser } from '@/shared/consts';
import { QUERY_KEYS } from '@/shared/react-query';

async function fetchUser(userId: number): Promise<FetchUser> {
const { data } = await axiosInstance.get(`/users/${userId}`);
return data;
}

export const useGetUser = (userId: number) => {
const {
data,
isLoading,
isError,
refetch: refetchUser,
} = useQuery({
queryKey: [QUERY_KEYS.users, userId],
queryFn: () => fetchUser(userId),
});

return {
data,
isLoading,
isError,
refetchUser,
};
};
17 changes: 17 additions & 0 deletions src/widgets/profile-user/assets/no-profile-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/widgets/profile-user/assets/profile-change-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 9 additions & 36 deletions src/widgets/profile-user/ui/ProfileUser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,6 @@
align-items: center;
box-shadow: 0px 20px 34.5px 0px #dddddd40;

.profile-image-box {
position: relative;

.profile-image {
width: 81px;
height: 81px;
border-radius: 50%;
overflow: hidden;
padding-bottom: 5px;
}

.no-proile-background {
position: relative;
width: 81px;
height: 81px;
border-radius: 50%;
overflow: hidden;
background: $gray3;

svg {
z-index: 1;
position: absolute;
bottom: 0;
}
}

.profile-change-btn {
position: absolute;
bottom: 4px;
right: -8px;
width: 24px;
height: 24px;
}
}

.profile-top-container {
height: 148px;
display: flex;
Expand All @@ -52,13 +17,21 @@
text-align: center;
}

.user-follow-btn {
.nickname-change-btn {
width: 67px;
height: 26px;
border-radius: 5px;
color: white;
background-color: $mint3;
}

.user-follow-btn {
width: 46px;
height: 26px;
border-radius: 5px;
color: white;
background-color: $mint3;
}
}

.profile-count-container {
Expand Down
Loading
Loading