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

[김동현] week16 #1066

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
10 changes: 5 additions & 5 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions src/api/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export async function getFolders() {
}
}

export async function getUserFolders(folderId: string | undefined) {
let url = "/users/1/links";
export async function getUserFolders(userId: string = '1', folderId?: string ) {
let url = "/users/${userId}/links";
Comment on lines +21 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

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

지난번 리뷰를 반영해주셨군요! 굳 👍


if (folderId) {
url += `?folderId=${folderId}`;
Expand All @@ -33,9 +33,9 @@ export async function getUserFolders(folderId: string | undefined) {
}
}

export async function getButtonList() {
export async function getButtonList(userId: string = '1') {
try {
const response = await http.get("/users/1/folders");
const response = await http.get("/users/${userId}/folders");
return response.data;
} catch (error) {
throw new Error("버튼 리스트를 불러오는데 실패했습니다.");
Expand Down
9 changes: 7 additions & 2 deletions src/components/ButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import "./ButtonGroup.css";
import add_icon from "../assets/svg/add.svg";
import { ButtonGroupProps } from "../types/type";

function ButtonGroup({ buttonList }: ButtonGroupProps) {
if (!Array.isArray(buttonList)) {
return null;
}
Comment on lines +3 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

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

이렇게 early return 을 추가하는 부분 좋습니다. 이 곳 말고도 프로젝트 내 다양한 곳에 early return 추가할 부분이 있을거에요. early return 을 습관화해서 비효율적인 랜더링을 막으면 최적화에 도움이 됩니다.


function ButtonGroup({ buttonList }: any) {
return (
<div className="button_area">
<div className="button_list">
<button className="button_folder">전체</button>
{buttonList.map((button: any) => (
{buttonList.map((button) => (
<button key={button.id} type="button" className="button_folder">
{button.name}
</button>
Expand Down
5 changes: 3 additions & 2 deletions src/components/CardList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { FolderData, FolderProps } from "types/type";
import Card from "./Card";
import "./CardList.css";

function CardList({ items }: any) {
function CardList({ folderList }: FolderProps) {
return (
<ul className="card_list">
{items ? items.map((item: any) => <Card item={item} key={item.id} />) : null}
{folderList ? folderList.map((item: FolderData) => <Card cardList={item} key={item.id} />) : null}
</ul>
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/CardsArea.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import "./CardsArea.css";
import CardList from "./CardList";
import { FolderProps } from "types/type";

// 에러처리, 로딩처리 추후 추가 예정
function CardsArea({ foldersData }: any) {
function CardsArea({ folderList }: FolderProps) {
return (
<div className="card_area">
<div className="card_wrapper">
{/* {buttonData ? <ButtonList buttonData={buttonData} /> : " "} */}
<CardList items={foldersData} />
<CardList folderList={folderList} />
</div>
</div>
);
Expand Down
14 changes: 6 additions & 8 deletions src/pages/folder/FolderPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import pen_icon from "../../assets/svg/pen.svg";
import share_icon from "../../assets/svg/share.svg";
import delete_icon from "../../assets/svg/delete.svg";
import ButtonGroup from "../../components/ButtonGroup";
import { UserData, FolderData, ButtonData } from "@/src/types/type";
import { UserData, FolderData, ButtonData } from "types/type";

function FolderPage() {
const [users, setUsers] = useState<UserData | undefined>();
const [folders, setFolders] = useState<FolderData | undefined>();
const [buttons, setButtons] = useState<ButtonData | undefined>();
const [users, setUsers] = useState<UserData>();
const [folders, setFolders] = useState<FolderData[]>();
const [buttons, setButtons] = useState<ButtonData[]>();
// const [folderTitle, setFolderTitle] = useState("전체");
const [folderTitle] = useState("전체");
// const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -74,9 +74,7 @@ function FolderPage() {

loadUserFoldersData();
}, [id]);

console.log(folders);


return (
<div className="folderPage">
<Gnb userEmail={users?.email} />
Expand Down Expand Up @@ -105,7 +103,7 @@ function FolderPage() {
</div>
{folders ? (
<div>
<CardsArea foldersData={folders} />
<CardsArea folderList={folders} />
</div>
) : (
<div className="folder_no_link">저장된 링크가 없습니다.</div>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/share/SharePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import Banner from "../../components/Banner";
import SearchBar from "../../components/SearchBar";
import CardsArea from "../../components/CardsArea";
import Footer from "../../components/Footer";
import { FolderData, UserData } from "@/src/types/type";
import { FolderData, UserData } from "../../types/type";

function SharePage() {
const [users, setUsers] = useState<UserData | undefined>();
const [folders, setFolders] = useState<FolderData | undefined>();
const [folders, setFolders] = useState<FolderData[]>();
// const [isLoading, setIsLoading] = useState(false);
// const [error, setError] = useState(null);

Expand Down Expand Up @@ -53,7 +53,7 @@ function SharePage() {
<Banner userName={users?.name} />
<div className="sharePage_contents">
<SearchBar />
<CardsArea foldersData={folders} />
<CardsArea folderList={folders} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

명시적으로 array 관련된 값들은 ***List / ***Item 이렇게 구분해서 네이밍을 해요. 기존 Data -> List 로 변경해주셔서 더 좋네요.
혹은 복수 / 단수로 구분도 한답니다.

</div>
<Footer />
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/types/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface FolderData {
imageSource?: string;
}

export interface FolderProps{
folderList: FolderData[] | undefined;
}

export interface ButtonData {
id: number;
created_at: string;
Expand All @@ -23,6 +27,11 @@ export interface ButtonData {
link?: any;
}


export interface ButtonGroupProps {
buttonList: ButtonData[] | undefined;
};

Comment on lines +31 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

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

타입 추가 좋습니다. 뒤에 undefined 값은 불필요해보입니다~
아래처럼 변경되면 좋겠어요.

export interface ButtonGroupProps {
  buttonList: ButtonData[];
};

export interface Icon {
id: number;
name: string;
Expand Down
23 changes: 22 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,29 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
"api/*": [
"src/api/*"
],
"assets/*": [
"src/assets/*"
],
"components/*": [
"src/components/*"
],
"constants/*": [
"src/constants/*"
],
"pages/*": [
"src/pages/*"
],
"types/*":[
"src/types/*"
],
"util/*": [
"src/util/*"
],
Comment on lines +18 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

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

"@util/* 이거처럼 @ 없이 이렇게 설정을 하기도 합니다! 설정 굳!

},
"typeRoots": ["./node_modules/@types", "@types"]
},
Expand Down
Loading