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

[권주현] Week11 #363

Merged
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
Binary file added public/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://developers.kakao.com/sdk/js/kakao.js"></script>
<title>Linkbrary</title>
</head>
<body>
Expand Down
Binary file added src/assets/facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/kakaotalk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ body {
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

button {
cursor: pointer;
}

:root {
--primary: #6d5afe;
--red: #ff5b56;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from "classnames";
import styles from "./styles/Avatar.module.css";
import styles from "./Avatar.module.css";

function Avatar({ src, size }) {
const avatarClass = classNames(styles.avatar, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FaFacebook, FaInstagram, FaTwitter, FaYoutube } from "react-icons/fa";
import styles from "./styles/Footer.module.css";
import styles from "./Footer.module.css";

function Footer() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mainLogo from "../assets/Linkbrary.png";
import Avatar from "./Avatar";
import styles from "./styles/Header.module.css";
import mainLogo from "../../assets/Linkbrary.png";
import styles from "./Header.module.css";
import Avatar from "../Avatar";

function Header({ userAvatarImage, userProfileEmail, userLogInSuccess }) {
return (
Expand Down
36 changes: 36 additions & 0 deletions src/globalComponents/Modal/Modal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.background {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
z-index: 1000;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
position: fixed;
}

.container {
padding: 28px;
background-color: var(--white);
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
border-radius: 15px;
position: relative;
}

.exitButton {
width: 24px;
height: 24px;
position: absolute;
right: 16px;
top: 16px;
border: none;
border-radius: 9999px;
background-color: var(--gray-400);
color: var(--gray-600);
cursor: pointer;
}
92 changes: 92 additions & 0 deletions src/globalComponents/Modal/ModalChildren.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.formContainer {
width: 280px;
display: flex;
flex-direction: column;
gap: 10px;
margin-top: 10px;
}

.formInput {
width: 100%;
padding: 15px 18px;
border: 1px solid var(--primary);
border-radius: 10px;
color: var(--black);
font-size: 16px;
font-weight: 400;
}

.formButton {
width: 100%;
padding: 16px 20px;
border-radius: 10px;
border: none;
background: var(--primary-gradient);
font-size: 16px;
font-weight: 600;
color: var(--white);
}

.redBackground {
background: none;
background-color: var(--red);
}

.shareBox {
width: 280px;
display: flex;
align-items: center;
justify-content: center;
gap: 32px;
margin-top: 10px;
}

.shareButtonWrapper {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
font-size: 13px;
font-weight: 400;
color: var(--black);
}

.shareButton {
background: none;
border: none;
border-radius: 100%;
}

.title {
font-size: 20px;
font-weight: 700;
color: var(--black);
}

.subTitle {
font-size: 14px;
font-weight: 400;
color: var(--gray-600);
}

.inputList {
display: flex;
flex-direction: column;
gap: 8px;
}

.inputList button {
width: 100%;
text-align: left;
font-size: 16px;
font-weight: 400;
background-color: transparent;
border: none;
border-radius: 8px;
padding: 6px 15px;
}

.inputList button:active {
background-color: var(--gray-400);
color: var(--primary);
}
16 changes: 16 additions & 0 deletions src/globalComponents/Modal/index.jsx
Copy link
Collaborator

Choose a reason for hiding this comment

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

DeleteModal, xxModal 등 여러 Modal이 있는데, 이 Modal 컴포넌트는 전혀 사용되지 않고 있네요.

Modal 컴포넌트 자체가 좀 더 확장성이 있어서 다른 구체화된 Modal 들의 수고를 덜어 줄 수 있지 않을까요?
확장을 위한 prop을 몇개 더 추가해줄 수도 있고, children에 구체화된 컴포넌트를 넣을 수도 있을 것 같네요.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import styles from "./Modal.module.css";

function Modal({ children, onClick }) {
return (
<div className={styles.background}>
<div className={styles.container}>
{children}
<button className={styles.exitButton} onClick={onClick}>
X
</button>
</div>
</div>
);
}

export default Modal;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FaSearch } from "react-icons/fa";
import styles from "./styles/SearchBar.module.css";
import styles from "./SearchBar.module.css";

function SearchBar() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import FolderLinkCards from "./FolderLinkCards";
import SearchBar from "../../../globalComponents/SearchBar";
import { useEffect, useState } from "react";
import { useSearchParams } from "react-router-dom";
import { getLinksByUserIdAndFolderId } from "../../../services/api";
import useAsync from "../../../services/useAsync";
import FoldersList from "./FoldersList";
import styles from "../styles/FoldersController.module.css";
import useAsync from "../../../../services/useAsync";
import { getLinksByUserIdAndFolderId } from "../../../../services/api";
import styles from "./FoldersController.module.css";
import SearchBar from "../../../../globalComponents/SearchBar";
import FoldersList from "../FoldersList";
import FolderLinkCards from "../FolderLinkCards";

function FoldersController({ folders, userId }) {
const [loading, setLoading] = useState(true);
Expand Down
53 changes: 0 additions & 53 deletions src/pages/FolderPage/components/FolderLinkCard.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styles from "../../../../../../globalComponents/Modal/ModalChildren.module.css";
Copy link
Collaborator

Choose a reason for hiding this comment

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

폴더구조가 맥락별로 깔끔하게 바뀌었지만, 그 깊이가 어마어마해졌습니다 ㅋㅋㅋㅋㅋ

자주 있는 일인데요, TypeScript의 alias로 해결할 수 있습니다.
찾아보면 stackOverflow에 많이 있으니 한번 알아보시면 좋을 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

사실 저도 PR올리면서 이게 맞나 싶었는데 다음 과제가 프로젝트를 ts로 변경하는거여서 아래의 내용도 다 포함해서 리팩토링하고 다음 PR엔 깔끔하게 보이도록 하겠습니다.🥲


function LinkAddToFolderForm() {
return (
<>
<h1 className={styles.title}>폴더에 추가</h1>
<h2 className={styles.subTitle}>링크 주소</h2>
<form className={styles.formContainer}>
<ul className={styles.inputList}>
<li>
<button>코딩 팁</button>
</li>
<li>
<button>채용 사이트</button>
</li>
<li>
<button>유용한 글</button>
</li>
<li>
<button>나만의 장소</button>
</li>
</ul>
<button className={styles.formButton}>추가하기</button>
</form>
</>
);
}

export default LinkAddToFolderForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import styles from "../../../../../../globalComponents/Modal/ModalChildren.module.css";

function LinkDeleteForm() {
return (
<>
<h1 className={styles.title}>링크 삭제</h1>
<h2 className={styles.subTitle}>url</h2>
<form className={styles.formContainer}>
<button className={`${styles.formButton} ${styles.redBackground}`}>
삭제하기
</button>
</form>
</>
);
}

export default LinkDeleteForm;
78 changes: 78 additions & 0 deletions src/pages/FolderPage/components/FolderLinkCard/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { useState } from "react";
import {
displayCreatedTime,
formatDateString,
} from "../../../../utils/dateUtils";
import defaultImage from "../../../../assets/card-default.png";
import kebab from "../../../../assets/kebab.svg";
import styles from "../../../LinkCard.module.css";
import { FaRegStar } from "react-icons/fa";
import Modal from "../../../../globalComponents/Modal";
import LinkAddToFolderForm from "./components/LinkAddToFolderForm";
import LinkDeleteForm from "./components/LinkDeleteForm";

function FolderLinkCard({ link }) {
const [onModal, setOnModal] = useState(false);
const [modalContent, setModalContent] = useState(null);

const handleClickModal = (actionType) => {
const actionTypes = {
deleteLink: <LinkDeleteForm />,
addLink: <LinkAddToFolderForm />,
};

setModalContent(actionTypes[actionType]);
setOnModal(true);
};
Comment on lines +15 to +26
Copy link
Collaborator

Choose a reason for hiding this comment

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

Modal을 띄워주는 state와 Modal의 내용을 정해주는 state가 따로있네요.

하나만 있어도 될 것 같은데 줄여볼 수 있지 않을까요?


const { url, description, title, created_at, image_source } = link;

const createdTime = displayCreatedTime(created_at);
const createdAtFormat = formatDateString(created_at);

const src = image_source || defaultImage;

const handleToggleDropDown = (e) => {
e.preventDefault();
e.stopPropagation();

const button = e.currentTarget;
const linkInfo = button.closest(`.${styles.linkInfo}`);
const dropdown = linkInfo.querySelector(`.${styles.dropdown}`);
dropdown.classList.toggle(styles.hidden);
};

return (
<div className={styles.linkContainer}>
<a href={url} target="_blank" rel="noreferrer">
<div className={styles.imageWrapper}>
<img className={styles.linkImage} src={src} alt={title} />
<FaRegStar className={styles.starIcon} />
</div>
</a>
<div className={styles.linkInfo}>
<div className={styles.linkInfoContent}>
<div>{createdTime}</div>
<button onClick={handleToggleDropDown} className={styles.kebabButton}>
<img src={kebab} alt="menu" />
</button>
</div>
<div className={styles.linkInfoContent}>{description}</div>
<div className={styles.linkInfoContent}>{createdAtFormat}</div>
<div className={`${styles.dropdown} ${styles.hidden}`}>
<button onClick={() => handleClickModal("deleteLink")}>
삭제하기
</button>
<button onClick={() => handleClickModal("addLink")}>
폴더에 추가
</button>
</div>
</div>
{onModal && (
<Modal onClick={() => setOnModal(false)}>{modalContent}</Modal>
)}
</div>
);
}

export default FolderLinkCard;
Loading
Loading