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

[Feature/BAR-155] 참고하는 레이아웃 수정 및 폴더 저장 삭제 기능 추가 #63

Merged
merged 6 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@svgr/webpack": "^8.1.0",
"@tanstack/react-query": "^5.17.9",
"@types/js-cookie": "^3.0.6",
"@types/react-responsive-masonry": "^2.1.3",
"@vanilla-extract/css": "^1.14.0",
"@vanilla-extract/dynamic": "^2.1.0",
"@vanilla-extract/recipes": "^0.5.1",
Expand All @@ -37,6 +38,7 @@
"react": "^18",
"react-dom": "^18",
"react-notion-x": "^6.16.0",
"react-responsive-masonry": "^2.1.7",
"zustand": "^4.4.7"
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/components/Card/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const header = style([
export const body = style([
sprinkles({ typography: '15/Body/Regular' }),
{
whiteSpace: 'pre-wrap',
wordBreak: 'keep-all',
},
]);
Expand Down
3 changes: 3 additions & 0 deletions src/domain/참고하는/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ export const postSaveTemplate = ({
memoFolderId,
}: PostSaveTemplateParams) =>
http.post(`/templates/${templateId}/archive`, { memoFolderId });

export const deleteTemplate = (templateId: number) =>
http.delete(`/templates/${templateId}/archive`);
7 changes: 7 additions & 0 deletions src/domain/참고하는/components/FolderDialog.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ export const hover = style({
fill: COLORS['Grey/600'],
},
});

export const hoverBlue = style({
transition: 'fill 100ms ease-in-out',
':hover': {
fill: COLORS['Blue/Default'],
},
});
51 changes: 48 additions & 3 deletions src/domain/참고하는/components/FolderDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,68 @@
import { useQueryClient } from '@tanstack/react-query';

import { type Folder } from '@api/memoFolder/types';
import Button from '@components/Button';
import Dropdown from '@components/Dropdown';
import Icon from '@components/Icon';
import * as styles from '@domain/참고하는/components/FolderDialog.css';
import { useModalStore } from '@stores/modal';
import { useToastStore } from '@stores/toast';
import { COLORS } from '@styles/tokens';

import useDeleteTemplate from '../queries/useDeleteTemplate';
import useSaveTemplate from '../queries/useSaveTemplate';

interface FolderDialogProps {
templateId: number;
Copy link
Member

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.

해당 부분 반영해보았습니다 감사합니다 ㅎㅎ

isArchived: boolean;
memoFolders: Folder[];
}

const FolderDialog = ({ templateId, memoFolders }: FolderDialogProps) => {
const FolderDialog = ({
templateId,
isArchived,
memoFolders,
}: FolderDialogProps) => {
const { openModal } = useModalStore();
const { mutateAsync } = useSaveTemplate();
const { mutateAsync: saveTemplate } = useSaveTemplate();
const { mutateAsync: deleteTemplate } = useDeleteTemplate();

const queryClient = useQueryClient();
const { showToast } = useToastStore();

const handleFolderClick = (memoFolderId: number) => async () =>
await mutateAsync({ templateId, memoFolderId });
await saveTemplate(
{ templateId, memoFolderId },
{
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['templates'],
});
showToast({ message: '글이 저장됐어요.' });
},
},
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 useSaveTemplate 내부에 작성해도 되지 않을까요?
그리고 onSuccess에 async, await 키워드는 없어도 됩니다!

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 handleDeleteTemplateClick = async () => {
await deleteTemplate(templateId, {
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['templates'],
});
},
});
};

if (isArchived)
return (
<Button onClick={handleDeleteTemplateClick}>
<Icon
icon="bookmarkRefer"
className={styles.hoverBlue}
color={COLORS['Grey/300']}
/>
</Button>
);

return (
<Dropdown size="medium" placement="bottom-center">
Expand Down
23 changes: 14 additions & 9 deletions src/domain/참고하는/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import Masonry, { ResponsiveMasonry } from 'react-responsive-masonry';

import FilterButtons from '@domain/참고하는/components/FilterButtons';
import FilterHeader from '@domain/참고하는/components/FilterHeader';
Expand Down Expand Up @@ -28,6 +29,8 @@ const 참고하는TabContent = () => {
const handleFilterButtonSelect = (type: FilterButton) => () =>
setSelectedFilterButton(type);

if (!data) return null;

return (
<div className={styles.referPageTabWrapper}>
<FilterHeader
Expand All @@ -38,15 +41,17 @@ const 참고하는TabContent = () => {
selectedFilterButton={selectedFilterButton}
handleFilterButtonSelect={handleFilterButtonSelect}
/>
<ul className={styles.referCardsWrapper}>
{data?.content.map((data) => (
<참고하는TemplateCard
key={data.templateId}
data={data}
memoFolders={memoFoldersData}
/>
))}
</ul>
<ResponsiveMasonry columnsCountBreakPoints={{ 768: 2, 1080: 3 }}>
Copy link
Member

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.

@dmswl98
기존 Card 컴포넌트 내부에 해당 요소를 넣자는 말씀이실까요?

Copy link
Member

Choose a reason for hiding this comment

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

엇 아뇨!!

다른 페이지도 768px일 때 2줄, 1080일 때 3줄이라

const Responsive = ({ children }) => {
  return <ResponsiveMasonry columnsCountBreakPoints={{ 768: 2, 1080: 3 }}>{children}</ResponsiveMasonry>
}

이렇게 구현해두면 어디에서든 쓸 수 있을 것 같아서요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmswl98
아아 해당 부분도 반영해두었습니다 !! ㅎㅎ

<Masonry className={styles.referCardsWrapper} gutter="16px">
{data.content.map((data) => (
Copy link
Member

Choose a reason for hiding this comment

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

어떤 코드인지 불명확해서...! 아래처럼 변경되면 좋을 것 같아요

Suggested change
{data.content.map((data) => (
const { data: templates } = useGetTemplates({
category: selectedFilterHeader,
sort: selectedFilterButton,
});
{templates.content.map((template) => ()}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

해당 부분 반영해보았습니다 감사합니다 ㅎㅎ

<참고하는TemplateCard
key={data.templateId}
data={data}
memoFolders={memoFoldersData}
/>
))}
</Masonry>
</ResponsiveMasonry>
</div>
);
};
Expand Down
11 changes: 8 additions & 3 deletions src/domain/참고하는/components/참고하는TemplateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import Icon from '@components/Icon';
import { CATEGORY_COLOR } from '@constants/config';
import * as styles from '@domain/참고하는/components/참고하는TemplateCard.css';
import { CATEGORY } from '@domain/참고하는/models';
import { type Refer } from '@domain/참고하는/types';
import { type ReferContent } from '@domain/참고하는/types';
import { getNumToK } from '@domain/참고하는/utils';
import { useToastStore } from '@stores/toast';
import { COLORS } from '@styles/tokens';

import FolderDialog from './FolderDialog';

interface 참고하는TemplateCardProps {
data: Refer;
data: ReferContent;
memoFolders: Folder[];
}

Expand All @@ -29,6 +29,7 @@ const 참고하는TemplateCard = ({
content,
copiedCount,
savedCount,
isArchived,
} = data;

const { showToast } = useToastStore();
Expand All @@ -52,7 +53,11 @@ const 참고하는TemplateCard = ({
color={COLORS['Grey/300']}
/>
</Button>
<FolderDialog templateId={templateId} memoFolders={memoFolders} />
<FolderDialog
templateId={templateId}
isArchived={isArchived}
memoFolders={memoFolders}
/>
</Card.Menu>
<Card.Header>
<Badge color={CATEGORY_COLOR[categoryNameKr]}>{categoryNameKr}</Badge>
Expand Down
10 changes: 10 additions & 0 deletions src/domain/참고하는/queries/useDeleteTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useMutation } from '@tanstack/react-query';

import { deleteTemplate } from '../api';

const useDeleteTemplate = () =>
useMutation({
mutationFn: deleteTemplate,
});

export default useDeleteTemplate;
14 changes: 3 additions & 11 deletions src/domain/참고하는/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@ import { type CATEGORY, type FILTER_BUTTONS } from '@domain/참고하는/models'

export type Category = keyof typeof CATEGORY;

export interface Refer {
export interface ReferContent {
templateId: number;
category: Category;
subCategory: string;
content: string;
savedCount: number;
copiedCount: number;
isArchived: boolean;
}

export type FilterButton = keyof typeof FILTER_BUTTONS;

export interface Content {
templateId: number;
category: Category;
subCategory: string;
content: string;
savedCount: number;
copiedCount: number;
}

export interface Templates {
content: Content[];
content: ReferContent[];
}
2 changes: 1 addition & 1 deletion src/styles/sprinkles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const width = {
const responsiveProperties = defineProperties({
conditions: {
small: { '@media': 'screen and (min-width: 768px)' },
middle: { '@media': 'screen and (min-width: 1024px)' },
middle: { '@media': 'screen and (min-width: 1080px)' },
large: { '@media': 'screen and (min-width: 1440px)' },
},
defaultCondition: 'large',
Expand Down
Loading