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

Fix: 마이페이지 - 등록한 게시글 탭 수정사항 반영 #185

Merged
merged 4 commits into from
Mar 23, 2024
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
1 change: 0 additions & 1 deletion src/components/commons/Kebabmenu/Kebabmenu.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.kebabmenu {
position: relative;
z-index: $kebab-level;

&-more-btn {
text-align: right;
Expand Down
11 changes: 5 additions & 6 deletions src/components/commons/Kebabmenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type PopupRef = LegacyRef<HTMLUListElement> | undefined;
const Kebabmenu = ({ onClick }: KebabmenuProps) => {
const { isOpen, popupRef, buttonRef, togglePopup } = useTogglePopup();

const handleSetState = (event: MouseEvent<HTMLButtonElement>) => {
const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
event.preventDefault();

onClick(event.currentTarget.textContent ?? '');
};

Expand All @@ -31,15 +33,12 @@ const Kebabmenu = ({ onClick }: KebabmenuProps) => {
{isOpen && (
<ul className={cx('kebabmenu-dropdown-list')} ref={popupRef as unknown as PopupRef}>
<li className={cx('kebabmenu-dropdown-list-item')}>
<button className={cx('kebabmenu-dropdown-list-item-btn')} onClick={(event) => handleSetState(event)}>
<button className={cx('kebabmenu-dropdown-list-item-btn')} onClick={handleClick}>
수정
</button>
</li>
<li className={cx('kebabmenu-dropdown-list-item')}>
<button
className={cx('kebabmenu-dropdown-list-item-btn', 'delete')}
onClick={(event) => handleSetState(event)}
>
<button className={cx('kebabmenu-dropdown-list-item-btn', 'delete')} onClick={handleClick}>
삭제
</button>
</li>
Expand Down
12 changes: 9 additions & 3 deletions src/components/commons/buttons/MoreButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Image from 'next/image';

import { MouseEventHandler } from 'react';
import { MouseEvent } from 'react';

import classNames from 'classnames/bind';

Expand All @@ -11,15 +11,21 @@ import styles from './MoreButton.module.scss';
const cx = classNames.bind(styles);

type MoreButtonProps = {
onClick: MouseEventHandler<HTMLButtonElement>;
onClick: () => void;
isActive: boolean;
};

export const MoreButton = ({ onClick, isActive }: MoreButtonProps) => {
const { url, alt } = SVGS.button.more;

const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
event.preventDefault();

onClick();
};

return (
<button className={cx('btn-more')} aria-label='메뉴 더보기 버튼' aria-pressed={isActive} onClick={onClick}>
<button className={cx('btn-more')} aria-label='메뉴 더보기 버튼' aria-pressed={isActive} onClick={handleClick}>
<Image src={url} alt={alt} width={24} height={24} />
</button>
);
Expand Down
16 changes: 11 additions & 5 deletions src/components/mypage/MyPosts/MyPosts.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
@include responsive(M) {
gap: 1.6rem;
}
}

.title-area {
@include flexbox(between, center);
position: relative;
}

.selected-game {
@include flexbox(start, center, 0.8rem);

@include responsive(M) {
height: 4rem;
}

&-title {
@include text-style(18, $white);
}
Expand All @@ -34,11 +36,15 @@

.filter-sort {
@include flexbox(between, center);

position: relative;
}

.dropdown {
@include responsive(M) {
position: absolute;
top: 0;
right: 0;
}

flex-shrink: 0;
width: 12rem;
}
33 changes: 10 additions & 23 deletions src/components/mypage/MyPosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';

import classNames from 'classnames/bind';

import { GAME_FILTERS, PRICE_TO_POST_TYPES } from '@/constants';
import { GAME_FILTERS, PRICE_TO_POST_TYPES, SORT_OPTIONS } from '@/constants';
import { formatCategoryToGameNameKR } from '@/utils';
import { getPostPageSize } from '@/utils/getPageSize';

Expand Down Expand Up @@ -37,20 +37,12 @@ const initialSortOption: SortOption<ActivityResponse> = {
order: 'desc',
};

const dropdownOptions: {
title: string;
value: Order;
}[] = [
{ title: '최신순', value: 'desc' },
{ title: '오래된순', value: 'asc' },
];

const MyPosts = () => {
const [page, setPage] = useState(1);
const [selectFilter, setSelectFilter] = useState(initialFilter);
const [sortOption, setSortOption] = useState(initialSortOption);
const currentDeviceType = useDeviceType();

const currentDeviceType = useDeviceType();
const pageSize = getPostPageSize(currentDeviceType);

const { pagedDataList, totalCount } = useProcessedDataList({
Expand All @@ -63,27 +55,22 @@ const MyPosts = () => {
});

const handleClickPage = (pageNumber: number) => setPage(pageNumber);

const handleSelectFilter = (selectedId: string) => setSelectFilter({ category: selectedId });

const handleOptionChange = (value: string | number) => setSortOption((prev) => ({ ...prev, order: value as Order }));

return (
<div className={cx('mypost-container')}>
<div className={cx('title-area')}>
<h2 className={cx('selected-game')}>
<span className={cx('selected-game-title')}>
{formatCategoryToGameNameKR(selectFilter.category) ?? '전체'}
</span>
<span className={cx('selected-game-count')}>{totalCount}</span>
</h2>
<div className={cx('dropdown', 'sm-only')}>
<Dropdown options={dropdownOptions} onChange={handleOptionChange} isSmall color='yellow' />
</div>
</div>
<h2 className={cx('selected-game')}>
<span className={cx('selected-game-title')}>{formatCategoryToGameNameKR(selectFilter.category) ?? '전체'}</span>
<span className={cx('selected-game-count')}>{totalCount}</span>
</h2>
<div className={cx('card-area')}>
<div className={cx('filter-sort')}>
<Filter items={GAME_FILTERS} selectedFilterId={selectFilter.category} onChange={handleSelectFilter} />
<div className={cx('dropdown', 'sm-hidden')}>
<Dropdown options={dropdownOptions} onChange={handleOptionChange} isSmall color='yellow' />
<div className={cx('dropdown')}>
<Dropdown options={SORT_OPTIONS} onChange={handleOptionChange} isSmall color='yellow' />
</div>
</div>
{totalCount ? (
Expand Down