Skip to content

Commit

Permalink
Merge pull request #153 from js43o/render-detail-buttons
Browse files Browse the repository at this point in the history
[Feat] 모각코 상세 게시글 페이지 API 일부 구현
  • Loading branch information
js43o authored Nov 23, 2023
2 parents e748923 + 8bbcf2c commit 0312890
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 213 deletions.
2 changes: 0 additions & 2 deletions app/frontend/src/components/Mogaco/MogacoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function MogacoList() {
title,
contents,
date,
participantList,
maxHumanCount,
address,
status,
Expand All @@ -32,7 +31,6 @@ export function MogacoList() {
title={title}
groupId={groupId}
contents={contents}
participantList={participantList}
maxHumanCount={maxHumanCount}
address={address}
date={date}
Expand Down
36 changes: 27 additions & 9 deletions app/frontend/src/components/MogacoDetail/DetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,56 @@ import { DetailHeaderButtons } from './DetailHeaderButtons';
import * as styles from './index.css';

type DetailHeaderProps = {
id: string;
memberId: string;
title: string;
status: '모집 중' | '마감' | '종료';
userHosted: boolean;
userParticipated: boolean;
};

export function DetailHeader({ memberId, title, status }: DetailHeaderProps) {
const [user, setUser] = useState<UserInfo | null>(null);
export function DetailHeader({
id,
memberId,
title,
status,
userHosted,
userParticipated,
}: DetailHeaderProps) {
const [hostUser, setHostUser] = useState<UserInfo | null>(null);

useEffect(() => {
if (user) {
if (hostUser) {
return;
}

const getUser = async () => {
const data = await member.userInfoById(memberId);
setUser(data);
setHostUser(data);
};

getUser();
}, [user, memberId]);
}, [hostUser, memberId]);

return (
<div className={styles.header}>
<div className={styles.title}>
<div className={sansBold24}>{title}</div>
<div className={styles.buttons}>
<DetailHeaderButtons status={status} />
<DetailHeaderButtons
id={id}
status={status}
userHosted={userHosted}
userParticipated={userParticipated}
/>
</div>
</div>
<div className={styles.writer}>
{user && (
<UserChip username={user.nickname} profileSrc={user.profilePicture} />
<div className={styles.hostUser}>
{hostUser && (
<UserChip
username={hostUser.nickname}
profileSrc={hostUser.profilePicture}
/>
)}
<span>부스트캠프 웹·모바일 8기</span>
</div>
Expand Down
87 changes: 46 additions & 41 deletions app/frontend/src/components/MogacoDetail/DetailHeaderButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,60 @@
import { Button } from '@/components';

const buttonComponents = {
participating: (
<Button theme="primary" shape="fill" size="large">
참석하기
</Button>
),
participated: (
<>
<Button theme="primary" shape="fill" size="large">
채팅
</Button>
<Button theme="danger" shape="fill" size="large">
참석 취소
</Button>
</>
),
hosted: (
<>
<Button theme="primary" shape="line" size="large">
수정
</Button>
<Button theme="danger" shape="line" size="large">
삭제
</Button>
</>
),
closed: (
<Button theme="primary" shape="fill" size="large" disabled>
마감
</Button>
),
};
import { mogaco } from '@/services';

type DetailHeaderButtonsProps = {
id: string;
userHosted: boolean;
userParticipated: boolean;
status: '모집 중' | '마감' | '종료';
};

export function DetailHeaderButtons({ status }: DetailHeaderButtonsProps) {
const userHosted = false;
const userParticipated = false;
export function DetailHeaderButtons({
id,
userHosted,
userParticipated,
status,
}: DetailHeaderButtonsProps) {
const onClickJoin = async () => {
await mogaco.join(id);
};

const onClickQuit = async () => {
await mogaco.quit(id);
};

if (userHosted) {
return buttonComponents.hosted;
return (
<>
<Button theme="primary" shape="line" size="large">
수정
</Button>
<Button theme="danger" shape="line" size="large">
삭제
</Button>
</>
);
}

if (status === '모집 중') {
return userParticipated
? buttonComponents.participated
: buttonComponents.participating;
return userParticipated ? (
<>
<Button theme="primary" shape="fill" size="large">
채팅
</Button>
<Button theme="danger" shape="fill" size="large" onClick={onClickQuit}>
참석 취소
</Button>
</>
) : (
<Button theme="primary" shape="fill" size="large" onClick={onClickJoin}>
참석하기
</Button>
);
}

return buttonComponents.closed;
return (
<Button theme="primary" shape="fill" size="large" disabled>
마감
</Button>
);
}
19 changes: 10 additions & 9 deletions app/frontend/src/components/MogacoDetail/DetailInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Participant } from '@/types';
import * as styles from './index.css';

type DetailInfoProps = {
participantList: Participant[];
participantList: Participant[] | null;
maxHumanCount: number;
date: string;
address: string;
Expand All @@ -36,7 +36,7 @@ export function DetailInfo({
<div className={styles.infoItem}>
<People fill={vars.color.grayscale200} />
<span>
<span>{participantList.length}</span>/<span>{maxHumanCount}</span>
<span>{participantList?.length}</span>/<span>{maxHumanCount}</span>
</span>
<button
type="button"
Expand All @@ -53,13 +53,14 @@ export function DetailInfo({
participantsShown ? styles.shown : ''
}`}
>
{participantList.map((participant) => (
<UserChip
key={participant.id}
username={participant.nickname}
profileSrc={participant.profile}
/>
))}
{!!participantList &&
participantList.map((participant) => (
<UserChip
key={participant.id}
username={participant.nickname}
profileSrc={participant.profilePicture}
/>
))}
</div>
<div className={styles.infoItem}>
<Calendar fill={vars.color.grayscale200} />
Expand Down
22 changes: 11 additions & 11 deletions app/frontend/src/components/MogacoDetail/index.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export const horizontalLine = style({
margin: 0,
});

export const hostUser = style([
sansBold16,
{
display: 'flex',
gap: '1.6rem',
color: vars.color.grayscale200,
},
]);

export const info = style({
display: 'flex',
flexDirection: 'column',
Expand All @@ -43,6 +52,8 @@ export const infoItem = style({
alignItems: 'center',
});

const shown = style({});

export const map = style({
width: '32rem',
height: '20rem',
Expand All @@ -51,8 +62,6 @@ export const map = style({
imageRendering: 'crisp-edges',
});

const shown = style({});

export const participants = style({
display: 'none',
gap: '0.8rem',
Expand Down Expand Up @@ -94,12 +103,3 @@ export const wrapper = style({
flexDirection: 'column',
alignItems: 'center',
});

export const writer = style([
sansBold16,
{
display: 'flex',
gap: '1.6rem',
color: vars.color.grayscale200,
},
]);
51 changes: 48 additions & 3 deletions app/frontend/src/components/MogacoDetail/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Mogaco } from '@/types';
import { useState, useEffect } from 'react';

import { mogaco } from '@/services';
import { useUserAtom } from '@/stores';
import { Mogaco, Participant } from '@/types';

import { DetailContents } from './DetailContents';
import { DetailHeader } from './DetailHeader';
Expand All @@ -8,19 +12,60 @@ import * as styles from './index.css';
type MogacoDetailProps = Mogaco;

export function MogacoDetailPage({
id,
memberId,
title,
maxHumanCount,
participantList,
date,
address,
contents,
status,
}: MogacoDetailProps) {
const [participantList, setParticipantList] = useState<Participant[] | null>(
null,
);
const [user, setUser] = useUserAtom();

if (!user)
setUser({
providerId: '1',
nickname: '지승',
profilePicture:
'https://avatars.githubusercontent.com/u/50646827?s=40&v=4',
email: '[email protected]',
});

const userHosted = user?.providerId === memberId;
const userParticipated = participantList
? !!participantList.find(
(participant) => participant.id === user?.providerId,
)
: false;

useEffect(() => {
if (participantList) {
return;
}

const getParticipantList = async () => {
const data = await mogaco.participants(id);
setParticipantList(data);
};

getParticipantList();
}, [id, participantList]);

return (
<div className={styles.wrapper}>
<div className={styles.container}>
<DetailHeader title={title} status={status} memberId={memberId} />
<DetailHeader
id={id}
title={title}
status={status}
memberId={memberId}
userHosted={userHosted}
userParticipated={userParticipated}
/>
<DetailInfo
participantList={participantList}
maxHumanCount={maxHumanCount}
Expand Down
9 changes: 0 additions & 9 deletions app/frontend/src/components/commons/MogacoItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import dayjs from 'dayjs';

import { ReactComponent as Calendar } from '@/assets/icons/calendar.svg';
import { ReactComponent as Map } from '@/assets/icons/map.svg';
import { ReactComponent as People } from '@/assets/icons/people.svg';
import { Label } from '@/components';
import { Mogaco } from '@/types';

Expand All @@ -18,8 +17,6 @@ export function MogacoItem({
title,
contents,
date,
participantList,
maxHumanCount,
address,
status,
}: MogacoProps) {
Expand All @@ -39,12 +36,6 @@ export function MogacoItem({
<div className={styles.content}>
<div className={styles.detail}>{contents}</div>
<div className={styles.info}>
<div className={styles.infoContent}>
<People className={styles.icon} />
<div className={styles.infoText}>
{participantList?.length || 0}/{maxHumanCount}
</div>
</div>
<div className={styles.infoContent}>
<Map className={styles.icon} />
<div className={styles.infoText}>{address}</div>
Expand Down
Loading

0 comments on commit 0312890

Please sign in to comment.