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

[Refactor] 컴포넌트, 변수명 리펙토링 #204

Merged
merged 15 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
8 changes: 4 additions & 4 deletions src/page/archiving/index/ArchivingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { theme } from '@/common/style/theme/theme';
import { useTeamId } from '@/shared/store/team';

const ArchivingPage = () => {
const [selectedId, setSelectedId] = useState('total');
const [selectedTabId, setSelectedTabId] = useState('total');

const teamId = useTeamId();

Expand All @@ -32,7 +32,7 @@ const ArchivingPage = () => {
};

const handleSelectedId = (id: string) => {
setSelectedId(id);
setSelectedTabId(id);
};

const handleBlockClick = (e: React.MouseEvent<HTMLDivElement>, block: Block) => {
Expand All @@ -45,7 +45,7 @@ const ArchivingPage = () => {
});

setSelectedBlock(block);
setSelectedId('selected');
setSelectedTabId('selected');
};

const sideBarRef = useOutsideClick(handleClose, 'TimeBlock');
Expand Down Expand Up @@ -151,7 +151,7 @@ const ArchivingPage = () => {
<DocumentBar
selectedBlock={selectedBlock}
ref={sideBarRef}
selectedId={selectedId}
selectedTabId={selectedTabId}
onSelectId={handleSelectedId}
onClickClose={handleClose}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css } from '@emotion/react';

import { theme } from '@/common/style/theme/theme';

export const containerStyle = (blockSelected: string) =>
export const documentBarContainerStyle = (blockSelected: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

저는 이전 네이밍이 더 좋은 것 같아요 !

어차피 DocumentBar.style.ts 이므로 도큐먼트바에 대한 스타일링이 명시되어있으므로, 그냥 container 스타일이라 해도 좋을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

흠 containerStyle로만 하니 온갖 군데에서 선언한 containerStyle이 자동완성에 다떠서 요렇게 바꾸어 봤는데 저도 너무 길다는 느낌이 들긴해서 다시 돌려놓는게 맞는거 같네요!!

css({
position: 'sticky',

Expand Down
20 changes: 10 additions & 10 deletions src/page/archiving/index/component/DocumentBar/DocumentBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { containerStyle } from '@/page/archiving/index/component/DocumentBar/DocumentBar.style';
import { documentBarContainerStyle } from '@/page/archiving/index/component/DocumentBar/DocumentBar.style';
import DocumentBarTab from '@/page/archiving/index/component/DocumentBarTab/DocumentBarTab';
import SelectedBlock from '@/page/archiving/index/component/SelectedBlock/SelectedBlock';
import TotalDocument from '@/page/archiving/index/component/TotalDocument/TotalDocument';
Expand All @@ -8,35 +8,35 @@ import { ForwardedRef, forwardRef } from 'react';

interface DocumentBarProps {
selectedBlock?: Block;
selectedId: string;
selectedTabId: string;
onSelectId: (Id: string) => void;
onClickClose: () => void;
}

const DocumentBar = (
{ selectedBlock, selectedId, onSelectId, onClickClose }: DocumentBarProps,
{ selectedBlock, selectedTabId, onSelectId, onClickClose }: DocumentBarProps,
ref: ForwardedRef<HTMLDivElement>
) => {
const handleTabClick = (selectedId: string, tabId: string) => {
if (tabId !== selectedId) {
const handleTabClick = (selectedTabId: string, tabId: string) => {
if (tabId !== selectedTabId) {
onSelectId(tabId);
}
};

return (
<aside css={containerStyle(selectedBlock ? selectedBlock.name : '')} ref={ref}>
<DocumentBarTab selectedId={selectedId} onTabClick={handleTabClick} />
{selectedId === 'selected' ? (
<aside css={documentBarContainerStyle(selectedBlock ? selectedBlock.name : '')} ref={ref}>
<DocumentBarTab selectedTabId={selectedTabId} onTabClick={handleTabClick} />
{selectedTabId === 'selected' ? (
selectedBlock && (
<SelectedBlock
selectedId={selectedId}
selectedTabId={selectedTabId}
blockName={selectedBlock.name}
selectedBlock={selectedBlock}
onClickClose={onClickClose}
/>
)
) : (
<TotalDocument selectedId={selectedId} />
<TotalDocument selectedTabId={selectedTabId} />
)}
</aside>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const tabStyle = (tabId: string) =>
font: `${theme.text.body04}`,
});

export const selectedStyle = (selected: string, tabId: string) =>
selected === tabId
export const selectedStyle = (selectedTabId: string, tabId: string) =>
selectedTabId === tabId
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

👍👍👍

? css({
backgroundColor: theme.colors.white,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import Button from '@/common/component/Button/Button';
import Flex from '@/common/component/Flex/Flex';

interface DocumentBarTabProps {
selectedId: string;
onTabClick: (selectedId: string, tabId: string) => void;
selectedTabId: string;
onTabClick: (selectedTabId: string, tabId: string) => void;
}

const DocumentBarTab = ({ selectedId, onTabClick }: DocumentBarTabProps) => {
const DocumentBarTab = ({ selectedTabId, onTabClick }: DocumentBarTabProps) => {
return (
<Flex tag={'nav'}>
<Button
onClick={() => onTabClick(selectedId, 'selected')}
css={[tabStyle('selected'), selectedStyle(selectedId, 'selected')]}>
onClick={() => onTabClick(selectedTabId, 'selected')}
css={[tabStyle('selected'), selectedStyle(selectedTabId, 'selected')]}>
선택한 블록
</Button>
<Button
onClick={() => onTabClick(selectedId, 'total')}
css={[tabStyle('total'), selectedStyle(selectedId, 'total')]}>
onClick={() => onTabClick(selectedTabId, 'total')}
css={[tabStyle('total'), selectedStyle(selectedTabId, 'total')]}>
Comment on lines +15 to +21
Copy link
Contributor

Choose a reason for hiding this comment

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

제가 규홍님께 TabsTab을 컴포넌트로 따로 분리해보면 좋을 것 같다고 말씀드렸는데, 일단은 여기서 고칠 수 있다고 생각되는게 html tag 에요 !

제가 HTML문서를 찾아봤는데, "nav는 문서의 부분 중 다른 페이지 혹은 컨텐츠로의 링크를 보여주는 "구획"이다" 라고 하더라고요 !

즉, nav 안에 ul 안에 li가 있는 구조가 정석적인 구조인 것 같아요, 특히나 탭과 같은 컴포넌트를 구현할 때 !

이 때 또 고려해볼 수 있는건 ulli는 시맨틱 태그가 아니기 때문에 적절히 role을 부여할 수 있을 것 같아요.

실제로 WAI-ARIA 가 제공해주는 role중에는 tablisttab이 있기 때문에 이를 각각 ul, li에 부여해준다면 너무너무 좋을 것 같습니다 !

거기다가 더해서 li 태그를 tab을 통해 사용자가 접근할 수 있도록 해준다면 더더욱 완벽! 할거 같아요. 드롭다운 구현 중에 제가 사용했던 것 같은데 참고해보시면 좋을 것 같아요 !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오호!! 이거 브렌치 머지하고 다른 브렌치파서 주용님이 알려주신 방향으로 공컴 구현 도전해보겠습니다!!

전체 문서
</Button>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { css } from '@emotion/react';

import { theme } from '@/common/style/theme/theme';

export const containerStyle = (selectedId: string) =>
export const documentItemContainerStyle = (selectedTabId: string) =>
css({
display: 'flex',
flexDirection: 'column',

gap: '0.4rem',
padding: selectedId === 'total' ? '1rem 1.2rem' : '1.2rem',
padding: selectedTabId === 'total' ? '1rem 1.2rem' : '1.2rem',

border: `1px solid ${theme.colors.gray_300}`,
borderRadius: '8px',
Expand All @@ -20,7 +20,7 @@ export const containerStyle = (selectedId: string) =>
},
});

export const blockNameTextStyle = (color: string) =>
export const blockNameStyle = (color: string) =>
css({
display: 'inline-block',

Expand All @@ -36,7 +36,7 @@ export const blockNameTextStyle = (color: string) =>
textOverflow: 'ellipsis',
});

export const fileNameStyle = css({
export const documentNameStyle = css({
width: '18rem',
maxHeight: '2.8rem',

Expand Down
45 changes: 26 additions & 19 deletions src/page/archiving/index/component/DocumentItem/DocumentItem.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable jsx-a11y/click-events-have-key-events */
import {
blockNameTextStyle,
containerStyle,
fileNameStyle,
blockNameStyle,
documentItemContainerStyle,
documentNameStyle,
} from '@/page/archiving/index/component/DocumentItem/DocumentItem.style';
import { handleDownload } from '@/page/archiving/index/util/document';
import { downloadDocument } from '@/page/archiving/index/util/document';

import { ReactNode } from 'react';

Expand All @@ -21,51 +21,58 @@ import { useTeamId } from '@/shared/store/team';
interface DocumentItemProps {
documentId: number;
children: ReactNode;
selectedId: string;
selectedTabId: string;
blockName?: string;
fileUrl: string;
color?: string;
documentUrl: string;
blockColor?: string;
}

const DocumentItem = ({ documentId, children, selectedId, blockName, fileUrl, color }: DocumentItemProps) => {
const DocumentItem = ({
documentId,
children,
selectedTabId,
blockName,
documentUrl,
blockColor,
}: DocumentItemProps) => {
const { isOpen, openModal, closeModal, currentContent } = useModal();

const fileName = children?.toString();
const documentName = children?.toString();
Copy link
Member

Choose a reason for hiding this comment

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

file ->document로 변경해주니 코드 전체적으로 통일감이 느껴져서 좋네요👍


const teamId = useTeamId();

//문서 클릭시 띄워주는 함수
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.

동의합니다!

const onClickDocumentItem = () => {
window.open(fileUrl);
const handleDocumentItemClick = () => {
window.open(documentUrl);
};

const handleDownloadClick = (e: React.MouseEvent<SVGSVGElement, MouseEvent>) => {
handleDownload(fileUrl, fileName);
downloadDocument(documentUrl, documentName);
e.stopPropagation();
};

const handleTrashClick = (e: React.MouseEvent<SVGSVGElement, MouseEvent>) => {
const handleTrashBoxClick = (e: React.MouseEvent<SVGSVGElement, MouseEvent>) => {
e.stopPropagation();
openModal(<DeleteModal title="docs" detail="docs" onClose={closeModal} teamId={+teamId} id={documentId} />);
};

return (
<>
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}
<li css={containerStyle(selectedId)} onClick={onClickDocumentItem}>
{color && (
<li css={documentItemContainerStyle(selectedTabId)} onClick={handleDocumentItemClick}>
{blockColor && (
<div>
<Text tag="body8" css={blockNameTextStyle(color)}>
<Text tag="body8" css={blockNameStyle(blockColor)}>
{blockName}
</Text>
</div>
)}
<Flex>
<Text tag="body6" css={fileNameStyle}>
{fileName}
<Text tag="body6" css={documentNameStyle}>
{documentName}
</Text>
<Download width={20} height={20} css={{ cursor: 'pointer' }} onClick={handleDownloadClick} />
<TrashBox width={20} height={20} onClick={(e) => handleTrashClick(e)} css={{ cursor: 'pointer' }} />
<TrashBox width={20} height={20} onClick={(e) => handleTrashBoxClick(e)} css={{ cursor: 'pointer' }} />
</Flex>
</li>
<Modal isOpen={isOpen} children={currentContent} onClose={closeModal} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DocumentItem from '@/page/archiving/index/component/DocumentItem/DocumentItem';
import { ICON_TYPE } from '@/page/archiving/index/constant/icon';
import { useBlockQuery } from '@/page/archiving/index/hook/api/useBlockQuery';
import { useBlockInfoQuery } from '@/page/archiving/index/hook/api/useBlockInfoQuery';
import { Block } from '@/page/archiving/index/type/blockType';
import { DocumentType } from '@/page/archiving/index/type/documentType';
import { formattingDate } from '@/page/archiving/index/util/date';
Expand All @@ -19,23 +19,23 @@ import { useTeamId } from '@/shared/store/team';
import { blockNameStyle, deleteBtnStyle } from './SelectedBlock.style';

interface DocumentBarInfoProps {
selectedId: string;
selectedTabId: string;
blockName: string;
selectedBlock: Block;
onClickClose: () => void;
Copy link
Member

Choose a reason for hiding this comment

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

onClose는 어떤가요 ?

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 SelectedBlock = ({ selectedId, blockName, selectedBlock, onClickClose }: DocumentBarInfoProps) => {
const SelectedBlock = ({ selectedTabId, blockName, selectedBlock, onClickClose }: DocumentBarInfoProps) => {
const { isOpen, openModal, closeModal, currentContent } = useModal();

const teamId = useTeamId();

const { data: blockData } = useBlockQuery(+teamId, selectedBlock?.timeBlockId ?? 0);
const { data: blockData } = useBlockInfoQuery(+teamId, selectedBlock?.timeBlockId ?? 0);

const startDate = formattingDate(selectedBlock.startDate);
const endDate = formattingDate(selectedBlock.endDate);

const handleCloseClick = () => {
const handleModalClose = () => {
onClickClose();
closeModal;
};
Expand All @@ -56,7 +56,7 @@ const SelectedBlock = ({ selectedId, blockName, selectedBlock, onClickClose }: D
<DeleteModal
title="block"
detail="block"
onClose={handleCloseClick}
onClose={handleModalClose}
teamId={+teamId}
id={selectedBlock.timeBlockId}
/>
Expand All @@ -74,9 +74,9 @@ const SelectedBlock = ({ selectedId, blockName, selectedBlock, onClickClose }: D
<DocumentItem
key={data.documentId}
documentId={data.documentId}
selectedId={selectedId}
selectedTabId={selectedTabId}
blockName={data.blockName}
fileUrl={data.fileUrl}>
documentUrl={data.fileUrl}>
{data.fileName}
</DocumentItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import useDebounce from '@/common/hook/useDebounce';

import { useTeamId } from '@/shared/store/team';

interface DocumentBarToolProps {
selectedId: string;
interface TotalDocumentProps {
selectedTabId: string;
}

const TotalDocument = ({ selectedId }: DocumentBarToolProps) => {
const TotalDocument = ({ selectedTabId }: TotalDocumentProps) => {
const [selected, setSelected] = useState('최근 업로드 순');

const teamId = useTeamId();
Expand Down Expand Up @@ -61,10 +61,10 @@ const TotalDocument = ({ selectedId }: DocumentBarToolProps) => {
<DocumentItem
key={data.documentId}
documentId={data.documentId}
selectedId={selectedId}
selectedTabId={selectedTabId}
blockName={data.blockName}
fileUrl={data.fileUrl}
color={data.color}>
documentUrl={data.fileUrl}
blockColor={data.color}>
{data.fileName}
</DocumentItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query';

import { getDocuments } from '@/shared/api/time-blocks/team/time-block';

export const useBlockQuery = (teamId: number, blockId: number) => {
export const useBlockInfoQuery = (teamId: number, blockId: number) => {
return useQuery({
queryKey: ['document', blockId],
Copy link
Contributor

Choose a reason for hiding this comment

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

블럭 내용 관련 이라면 쿼리키를 'blockInfo' 와 같은 블록 내용관련으로 바꿔도 좋을 거 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

요거는 문서 삭제되면 전체문서, 블록 문서 두개 모두 재실행 시키기 위해서 두 쿼리의 첫 쿼리키를 document로 지정해 보았습니다!

queryFn: () => getDocuments(teamId, blockId),
Expand Down
2 changes: 1 addition & 1 deletion src/page/archiving/index/util/document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const handleDownload = (fileUrl: string, name?: string) => {
export const downloadDocument = (fileUrl: string, name?: string) => {
const url = URL.createObjectURL(new Blob([fileUrl]));
const a = document.createElement('a');
a.href = url;
Expand Down
7 changes: 3 additions & 4 deletions src/shared/component/LeftSidebar/LeftSidebar.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const containerStyle = () =>
transitionDuration: '0.5s',
});

export const LogoSymbolStyle = css({
export const tikiLogoStyle = css({
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
Expand All @@ -42,14 +42,14 @@ export const LogoSymbolStyle = css({
cursor: 'pointer',
});

export const leftSidebarListStyle = css({
export const leftSidebarMenuStyle = css({
display: 'flex',
flexDirection: 'column',

gap: '2.4rem',
});

export const arrowStyle = css({
export const arrowBtnStyle = css({
position: 'absolute',

top: '3.8rem',
Expand All @@ -66,4 +66,3 @@ export const settingStyle = css({

bottom: '2.4rem',
});

Loading
Loading