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

[김한샘] Week12 #390

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
771e7a1
Add: 타입스크립트 추가
hansaemkim38 May 5, 2024
e6af1ee
Feat: app, index.tsx로 변경
hansaemkim38 May 5, 2024
c83ed0d
Add: tsconfig compilerOptions 추가
hansaemkim38 May 5, 2024
516989f
Update: GetDate, ModalContext tsx로 변경
hansaemkim38 May 5, 2024
9b34bec
Update: KebabList tsx로 변경
hansaemkim38 May 5, 2024
a745f55
Update: fetchUtils/index ts로 변경
hansaemkim38 May 5, 2024
8504573
Update: Shared 페이지 ts로 변경
hansaemkim38 May 5, 2024
d0384e6
Add: tsconfig baseurl추가
hansaemkim38 May 5, 2024
2ea5507
Update: Search components tsx로 변경
hansaemkim38 May 5, 2024
19fc358
Update: folder, shared페이지 타입추가, modalcontext, cardlist 타입 추가
hansaemkim38 May 5, 2024
25f4ccf
Update: tsconfig 수정
hansaemkim38 May 5, 2024
1168a01
Update: header.tsx 추가
hansaemkim38 May 5, 2024
6a2e5ce
Update: card관련 컴포넌트 타입 추가
hansaemkim38 May 6, 2024
e8b8cda
Update: FolderTabList 관련 컴포넌트 타입 추가
hansaemkim38 May 6, 2024
6477d00
Update: ts파일로 변경
hansaemkim38 May 6, 2024
01de7d7
Fix: 타입 에러 수정
hansaemkim38 May 6, 2024
88434e3
Update: ts파일로 변경
hansaemkim38 May 6, 2024
71f499e
Fix: 타입 수정
hansaemkim38 May 6, 2024
2cc4953
Update: modal 관련 타입 정리
hansaemkim38 May 6, 2024
09acc16
Add: tsconfig, custom.d.ts 추가
hansaemkim38 May 6, 2024
d001534
Fix: shared 페이지 타입에러 수정
hansaemkim38 May 6, 2024
4f2dbf1
Fix: 타입에러 수정
hansaemkim38 May 6, 2024
f85510c
Fix: 타입에러 수정
hansaemkim38 May 6, 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
4 changes: 3 additions & 1 deletion package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"typescript": "^4.9.5"
}
}
15 changes: 8 additions & 7 deletions src/App.jsx → src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import "./styles/form.css";
import "./styles/pages/main/main.css";

import React from "react";
import Footer from "./components/Footer/Footer";
import Header from "./components/Header/Header";
import { BrowserRouter } from "react-router-dom";
import AppRouter from "./routes";

function App() {
return (
<BrowserRouter>
<Header />
<AppRouter />
<Footer />
</BrowserRouter>
);
return (
<BrowserRouter>
<Header />
<AppRouter />
<Footer />
</BrowserRouter>
);
}

export default App;
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import "./AddLinkForm.css";
import React from "react";
import LinkIcon from "../../assets/icon/link.png";
import { useContext } from "react";
import ModalContext from "../Modal/ModalContext";

function AddLinkForm() {
const { openModal, setModalType } = useContext(ModalContext);
const onClickModalOpen = (e) => {
const { openModal, setModalType } = useContext(ModalContext)!;
const onClickModalOpen = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
openModal();
setModalType("folderAdd");
Expand Down
20 changes: 17 additions & 3 deletions src/components/Card/Card.jsx → src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "./Card.css";
import React from "react";
import catImg from "../../assets/images/cat.jpg";
import GetDate from "../../utils/GetDate";
import GetDaysAgo from "../../utils/GetDaysAgo";
Expand All @@ -9,14 +10,27 @@ import EditableStarButton from "./EditableStarButton";
import KebabButton from "./KebabButton";
import { useLocation } from "react-router-dom";

function Card({ card }) {
interface FolderCardData {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Card 컴포넌트의 Prop에 대한 type인데 CardPropType 정도로 표현하면 더 직관적이지 않을까요?

card: {
id: number;
createdAt: string;
description?: string;
folderId?: number;
title?: string;
updatedAt?: string;
url: string;
imageSource?: string;
};
}

function Card({ card }: FolderCardData) {
const { description, id, title, url, imageSource, createdAt } = card;
const [display, setDisplay] = useToggle();
const location = useLocation();

const onClickKebabButton = (e) => {
const onClickKebabButton = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setDisplay();
if (typeof setDisplay === "function") setDisplay();
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from "react";
import starIcon from "../../assets/svg/star.svg";
import "./EditableStarButton.css";

function EditableStarButton() {
return (
<button className="editable-star">
<img src={starIcon} alt="즐겨찾기" />
</button>
);
return (
<button className="editable-star">
<img src={starIcon} alt="즐겨찾기" />
</button>
);
}

export default EditableStarButton;
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from "react";
import KebabIcon from "../../assets/svg/kebab.svg";

function KebebButton({ onClickKebabButton }) {
interface OnClickKebabButton {
onClickKebabButton: (e: React.MouseEvent<HTMLButtonElement>) => void;
}

function KebebButton({ onClickKebabButton }: OnClickKebabButton) {
return (
<button className="Kebab" onClick={onClickKebabButton}>
<img src={KebabIcon} alt="메뉴 더보기" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import "./KebabList.css";
import { useContext } from "react";
import ModalContext from "../Modal/ModalContext";
import React from "react";

function KebabList({ url, setDisplay }) {
const { openModal, setModalType, setCardUrl } = useContext(ModalContext);
interface KebabListInterface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

변수명에 변수 타입이 들어가는 것이 안좋듯이, type과 interface도 마찬가지입니다.

url: string;
setDisplay: boolean | (() => void);
}

function KebabList({ url, setDisplay }: KebabListInterface) {
const { openModal, setModalType, setCardUrl } = useContext(ModalContext)!;

const onClickDeleteLinkModalOpen = (e) => {
const onClickDeleteLinkModalOpen = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setModalType("linkDelete");
setCardUrl(url);
openModal();
setDisplay();
if (typeof setDisplay === "function") setDisplay();
};

const onClickAddFolderModalOpen = (e) => {
const onClickAddFolderModalOpen = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setModalType("folderAdd");
setCardUrl(url);
openModal();
setDisplay();
if (typeof setDisplay === "function") setDisplay();
};
return (
<ul className="Kebab-list">
Expand Down
30 changes: 0 additions & 30 deletions src/components/CardList/CardList.jsx

This file was deleted.

59 changes: 59 additions & 0 deletions src/components/CardList/CardList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from "react";
import "./CardList.css";
import Card from "../Card/Card";

interface CardListData {
id: number;
createdAt: string;
url: string;
title: string;
description: string;
imageSource?: string;
}

interface UserFolderCardDataList {
data: {
id: number;
createdAt: string;
description?: string;
folderId?: number;
title?: string;
updatedAt?: string;
url: string;
imageSource?: string;
};
}
Comment on lines +14 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

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

바로 위에 선언한 CardListData를 재활용하는 것이 좋습니다.

TS의 & 를 잘 이용해보세요.


function renderCardList(cardData: CardListData[] | UserFolderCardDataList["data"][]) {
return (
<ul className="card-list">
{Array.isArray(cardData) &&
cardData.map((card) => {
return <Card card={card} key={card.id} />;
})}
</ul>
);
}

function CardList({
cardListData,
userFolderDataList,
}: {
cardListData?: CardListData[];
userFolderDataList?: UserFolderCardDataList;
}) {
return (
<>
{cardListData && cardListData.length > 0 && renderCardList(cardListData)}
{userFolderDataList &&
Array.isArray(userFolderDataList.data) &&
userFolderDataList.data.length > 0 &&
renderCardList(userFolderDataList.data)}
{!cardListData && !userFolderDataList && (
<div className="empty-link">저장된 링크가 없습니다.</div>
)}
</>
);
}

export default CardList;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import "./CardTitleIcon.css";
import shareIcon from "../../assets/svg/share.svg";
import penIcon from "../../assets/svg/pen.svg";
Expand All @@ -7,7 +8,7 @@ import ModalContext from "../Modal/ModalContext";
import { useContext } from "react";

function CardTitleIcon() {
const { setModalType, openModal } = useContext(ModalContext);
const { setModalType, openModal } = useContext(ModalContext)!;

const cardTitleIcon = [
{
Expand Down
17 changes: 0 additions & 17 deletions src/components/ConHeader/ConHeader.jsx

This file was deleted.

37 changes: 37 additions & 0 deletions src/components/ConHeader/ConHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";
import "./ConHeader.css";

interface FolderData {
id: number;
name: string;
owner: {
id: number;
name: string;
profileImageSource: string;
};
links: {
id: number;
createdAt: string;
url: string;
title: string;
description: string;
imageSource?: string;
}[];
count: number;
}

function ConHeader({ folderData }: { folderData: FolderData | null }) {
const owner = folderData?.owner;

return (
<div className="con-header-wrap">
<div className="con-header">
<img src={owner?.profileImageSource} alt="" />
<h3>{owner?.name}</h3>
</div>
<h2>{folderData?.name}</h2>
</div>
);
}

export default ConHeader;
16 changes: 0 additions & 16 deletions src/components/FolderTabList/Button.jsx

This file was deleted.

23 changes: 23 additions & 0 deletions src/components/FolderTabList/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import "./Button.css";

interface buttonData {
Copy link
Collaborator

Choose a reason for hiding this comment

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

타입의 이름들은 파스칼케이스로 작성해주시는 편이 좋습니다.

data: {
id: number;
name: string;
};
onClickButton: (id: number, name: string) => void;
buttonClass: number | null;
}

function Button({ data, onClickButton, buttonClass }: buttonData) {
const { id, name } = data;

return (
<button className={buttonClass === id ? "select" : ""} onClick={() => onClickButton(id, name)}>
{name}
</button>
);
}

export default Button;
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import "./FolderAddButton.css";
import addBtnImg from "../../assets/icon/svg/add-button-img.svg";
import ModalContext from "../Modal/ModalContext";
import { useContext } from "react";

function FolderAddButton() {
const { openModal, setModalType } = useContext(ModalContext);
const { openModal, setModalType } = useContext(ModalContext)!;

const onClickButton = () => {
setModalType("add");
Expand Down
Loading
Loading