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

사용자 프로필 바 컴포넌트 구현 #152

Merged
merged 24 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
33ea651
chore: svg import 방식 url 추가
jaeml06 Jul 30, 2024
695204d
fix: storybook 설정에 svg 처리 방식 추가
jaeml06 Jul 30, 2024
4cafa68
feat: empty_profile.svg추가
jaeml06 Jul 30, 2024
843415d
feat: ProfileFrame 구현
jaeml06 Jul 30, 2024
f40582b
test: ProfileFrame Storybook 작성
jaeml06 Jul 30, 2024
f298758
feat: ProfileBox 컴포넌트 구현
jaeml06 Jul 30, 2024
c4270c4
test: ProfileBox Storybook 코드 작성
jaeml06 Jul 30, 2024
b42900e
faet: ProfileList 컴포넌트 구현
jaeml06 Jul 31, 2024
f381ccc
test: ProfileList Storybook 테스트 작성
jaeml06 Jul 31, 2024
e394169
feat: Participation 타입 추가
jaeml06 Jul 31, 2024
173743e
feat: ProfileList가 participants배열 정보를 렌더링하도록 변경
jaeml06 Jul 31, 2024
c86e5f7
refactor: ProfileBox 컴포넌트 명 변경
jaeml06 Jul 31, 2024
eba83fc
feat: crown.svg 추가
jaeml06 Jul 31, 2024
8b6f68d
feat: role에 따른 crown 이미지 추가
jaeml06 Jul 31, 2024
f847e03
test: crown 이미지 테스트 추가
jaeml06 Jul 31, 2024
9ed261c
feat : Participation 타입에 role 타입 추가
jaeml06 Jul 31, 2024
14ae4ee
refactor: ProfileCardProps 변경
jaeml06 Jul 31, 2024
0ac6d4d
test: ProfileCardProps 타입 변경에 따른 수정
jaeml06 Jul 31, 2024
be06975
refactor: Participation 타입의 profile을 src로 변경
jaeml06 Jul 31, 2024
262b51b
test: Participation 타입의 profile을 src로 변경
jaeml06 Jul 31, 2024
b397214
feat: ProfileCard의 item 정렬 방식 변경
jaeml06 Jul 31, 2024
2539e3f
refactor: profileCrown 설명 주석 추가
jaeml06 Jul 31, 2024
4f27148
refactor: ProfileBox 컴포넌트 ProfileCard로 이름 변경
jaeml06 Jul 31, 2024
b5eb8bd
feat: TODO 주석 추가
jaeml06 Jul 31, 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
25 changes: 24 additions & 1 deletion frontend/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@ const config: StorybookConfig = {
presets: [require.resolve('@emotion/babel-preset-css-prop')],
},
});

if (config.module?.rules) {
config.module = config.module || {};
config.module.rules = config.module.rules || [];
const imageRule = config.module.rules.find((rule) =>
rule?.['test']?.test('.svg'),
);
if (imageRule) {
imageRule['exclude'] = /\.svg$/;
}
config.module.rules.push({
test: /\.svg$/i,
oneOf: [
{
use: ['@svgr/webpack'],
issuer: /\.[jt]sx?$/,
resourceQuery: { not: [/url/] },
},
{
type: 'asset/resource',
resourceQuery: /url/,
},
],
});
}
return config;
},
};
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/common/assets/crown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/common/assets/empty_profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions frontend/src/components/Profile/ProfileCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Meta, StoryObj } from '@storybook/react';
import ProfileCard from './ProfileCard';
import EmptyProfile from '@_common/assets/empty_profile.svg';
import Plus from '@_common/assets/tabler_plus.svg?url';

const meta = {
component: ProfileCard,
title: 'Components/ProfileCard',
} satisfies Meta<typeof ProfileCard>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
profile: {
nickname: '치코',
src: EmptyProfile,
role: 'moimee',
},
},
render: (args) => <ProfileCard {...args} />,
};

export const WithCustomImage: Story = {
args: {
profile: {
nickname: '치코',
src: Plus,
role: 'moimee',
},
},
render: (args) => <ProfileCard {...args} />,
};

export const WithErrorHandling: Story = {
args: {
profile: {
nickname: '치코',
src: 'invalid-url.jpg', // 오류를 발생시키기 위한 잘못된 URL
role: 'moimee',
},
},
render: (args) => <ProfileCard {...args} />,
};
16 changes: 16 additions & 0 deletions frontend/src/components/Profile/ProfileCard.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { css, Theme } from '@emotion/react';

export const ProfileCard = css`
display: flex;
flex-direction: column;
gap: 0.4rem;
align-items: center;
justify-content: flex-end;

width: auto;
width: fit-content;
`;

export const ProfileName = (props: { theme: Theme }) => css`
${props.theme.typography.s2}
`;
23 changes: 23 additions & 0 deletions frontend/src/components/Profile/ProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ProfileFrame from './ProfileFrame';
import * as S from './ProfileCard.style';
import { useTheme } from '@emotion/react';
import { Participation } from '@_types/index';

interface ProfileCardProps {
profile: Participation;
}
export default function ProfileBox(props: ProfileCardProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProfileBox -> ProfileCard
컴포넌트 이름이 수정이 안돼있어요!!!!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정했습니다.

const { profile } = props;
const theme = useTheme();
return (
<div css={S.ProfileCard}>
<ProfileFrame
width={7}
height={7}
src={profile.src}
role={profile.role}
/>
<div css={S.ProfileName({ theme })}>{profile.nickname}</div>
</div>
);
}
50 changes: 50 additions & 0 deletions frontend/src/components/Profile/ProfileFrame.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Meta, StoryObj } from '@storybook/react';
import ProfileFrame from './ProfileFrame';
import EmptyProfile from '@_common/assets/empty_profile.svg';
import Plus from '@_common/assets/tabler_plus.svg?url';

const meta = {
component: ProfileFrame,
title: 'Components/ProfileFrame',
} satisfies Meta<typeof ProfileFrame>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
width: 7,
height: 7,
src: EmptyProfile,
},
render: (args) => <ProfileFrame {...args} />,
};

export const WithCustomImageAndCrown: Story = {
args: {
width: 7,
height: 7,
src: Plus,
role: 'moimer',
},
render: (args) => <ProfileFrame {...args} />,
};

export const WithCustomImage: Story = {
args: {
width: 7,
height: 7,
src: Plus,
},
render: (args) => <ProfileFrame {...args} />,
};

export const WithErrorHandling: Story = {
args: {
width: 7,
height: 7,
src: 'invalid-url.jpg', // 오류를 발생시키기 위한 잘못된 URL
},
render: (args) => <ProfileFrame {...args} />,
};
42 changes: 42 additions & 0 deletions frontend/src/components/Profile/ProfileFrame.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { css } from '@emotion/react';

type Size = number;

export const profileBox = () => {
return css`
width: fit-content;
`;
};

export const profileFrame = (width: Size, height: Size) => {
return css`
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;

width: ${width}rem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 아예 문자에 rem을 박아버렸는데요
예를 들어 width:'7rem'과 같이요

이 부분을 조정해보면 좋을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

밑에 width을 계산하는 부분이 있어서 rem으로 받으면 rem을 분리하고 숫자로 만든 다음 계산을 해야해서 일단 구현의 편의상 이와 같은 방식으로 구현했습니다. 다음 구현때 수정하도록 하겠습니다.

height: ${height}rem;

border: 0.5rem solid orange;
border-radius: 300rem;
`;
};

export const profileImage = () => {
return css`
width: 100%;
height: 100%;
object-fit: cover;
`;
};

// 크라운 이미지를 가운데 정렬하기 위한 css
export const profileCrown = (width: Size) => {
return css`
position: relative;
top: 1rem;
left: ${width / 2 - (3 * (width / 8)) / 2}rem;
width: ${3 * (width / 8)}rem;
`;
};
32 changes: 32 additions & 0 deletions frontend/src/components/Profile/ProfileFrame.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ImgHTMLAttributes } from 'react';
import * as S from './ProfileFrame.style';
import EmptyProfile from '@_common/assets/empty_profile.svg?url';
import Crown from '@_common/assets/crown.svg?url';
import { Role } from '@_types/index';

interface ProfileFrameProps extends ImgHTMLAttributes<HTMLImageElement> {
role?: Role;
width: number;
height: number;
}
export default function ProfileFrame(props: ProfileFrameProps) {
const { width, height, onError, role, ...args } = props;

const handleError = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 이게 싫어서 빈 프로필을 png로 두었어요.

이미지가 없는 에러가 나면 이미지 에러=>js 단에서 onError 수행=>이미지 변경된 컴포넌트 변경=>재렌더링=>재패칭 인데

background로 url을 두 개 두게되면

css에서 이미지 에러=>바로 재패칭 이렇게 되니깐요

물론 svg가 가벼워서 이 방식이 처음에는 더 이득일 수도 있겠네요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 한번 다시 생각해볼 필요가 있겠네요. 아마 지금은 svg를 url로 사용할 수 있으니 가능할 것 같아요

event: React.SyntheticEvent<HTMLImageElement, Event>,
) => {
if (onError) {
onError(event);
}
event.currentTarget.src = EmptyProfile;
};

return (
<div css={S.profileBox()}>
{role === 'moimer' ? <img src={Crown} css={S.profileCrown(width)} /> : ''}
<div css={S.profileFrame(width, height)}>
<img css={S.profileImage} {...args} onError={handleError} />
</div>
</div>
);
}
59 changes: 59 additions & 0 deletions frontend/src/components/ProfileList/ProfileList.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Meta, StoryObj } from '@storybook/react/*';
import ProfileList from './ProfileList';

const meta = {
title: 'components/ProfileList',
component: ProfileList,
} satisfies Meta<typeof ProfileList>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
participants: [
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 이 부분을 상수화해서 배열에 우겨넣으면 가독성이 좋더라구요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그런 방법도 있네요. refact 과정에 반영하도록 하겠습니다.

nickname: '치코',
src: '',
role: 'moimer',
},
{
nickname: '치코',
src: '',
role: 'moimee',
},
{
nickname: '치코',
src: '',
role: 'moimer',
},
{
nickname: '치코',
src: '',
role: 'moimer',
},
{
nickname: '치코',
src: '',
role: 'moimer',
},
{
nickname: '치코',
src: '',
role: 'moimer',
},
{
nickname: '치코',
src: '',
role: 'moimer',
},
{
nickname: '치코',
src: '',
role: 'moimer',
},
],
},
render: (args) => <ProfileList {...args} />,
};
17 changes: 17 additions & 0 deletions frontend/src/components/ProfileList/ProfileList.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { css } from '@emotion/react';

export const ProfileContanier = css`
scrollbar-width: none; /* TODO Firefox 현재 no-unsupported-browser-features 경고 발생 중 추후 확인 필요 */

overflow: auto hidden;
display: flex;
gap: 20px;

width: auto;

-ms-overflow-style: none;

&::-webkit-scrollbar {
display: none;
}
`;
19 changes: 19 additions & 0 deletions frontend/src/components/ProfileList/ProfileList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ProfileCard from '@_components/Profile/ProfileCard';
import * as S from './ProfileList.style';
import { Participation } from '@_types/index';

interface ProfileListProps {
participants: Participation[];
}

export default function ProfileList(props: ProfileListProps) {
const { participants } = props;

return (
<div css={S.ProfileContanier}>
{participants.map((participant) => {
return <ProfileCard key={participant.nickname} profile={participant} />;
})}
</div>
);
}
5 changes: 5 additions & 0 deletions frontend/src/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ declare module '*.woff2' {
const src: string;
export default src;
}

declare module '*.svg?url' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const content: string;
export default content;
}
declare module '*.svg' {
import React = require('react');
export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export interface MoimInfo {
description?: string;
}

export interface Participation {
nickname: string;
src: string;
role: Role;
}

export type Role = 'moimer' | 'moimee';

export type MoimInputInfo = Omit<
MoimInfo,
'moimId' | 'currentPeople' | 'participants'
Expand Down
12 changes: 11 additions & 1 deletion frontend/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ module.exports = {
rules: [
{
test: /\.svg$/i,
use: ['@svgr/webpack'],
oneOf: [
{
use: ['@svgr/webpack'],
issuer: /\.[jt]sx?$/,
resourceQuery: { not: [/url/] },
},
{
type: 'asset/resource',
resourceQuery: /url/,
}
]
},
{
test: /\.(png|jpe?g|gif|webp|woff2)$/i,
Expand Down
Loading