-
Notifications
You must be signed in to change notification settings - Fork 53
[이준기] week8, 11 #336
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
Open
eonpain
wants to merge
16
commits into
codeit-bootcamp-frontend:part2-이준기
Choose a base branch
from
eonpain:part2-이준기-week8
base: part2-이준기
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "part2-\uC774\uC900\uAE30-week8"
Open
[이준기] week8, 11 #336
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
93a0e93
chore: 머지 후 브랜치 삭제 github action 추가
withyj-codeit 38ef208
Merge branch 'codeit-bootcamp-frontend:part2-이준기' into part2-이준기
eonpain ca43c8d
weeklyMission-week6
eonpain 4834117
weekly mission week6 다시제출
eonpain 08630e7
6주차 코드 수정완료
eonpain 782f404
Merge branch 'codeit-bootcamp-frontend:part2-이준기' into part2-이준기
eonpain c291413
Merge branch 'part2-이준기' of https://github.com/eonpain/2-Weekly-Missi…
eonpain 6c374c4
chore:App컴포넌트이름을 Shared로 변경
eonpain b00f4dd
docs:홈페이지를 만들고 folder페이지와 shared페이지로 라우팅하도록 전반적인 문서수정
eonpain a2628bd
Fix: 7주차 미션 코드리뷰 확인 후 수정
eonpain be01839
Feat: sns공유, url복사, 폴더 및 링크 삭제, 폴더추가, 폴더에 링크추가 기능이 있는 모달 생성
eonpain fc69e3b
Fix: tsx로 확장자 수정 중 캐시 삭제 전 코드 저장 목적으로 커밋
eonpain 845d468
Build: 타입스크립트 모듈 추가 및 설치, 마이그레이션
eonpain 0a92260
Feat: 검색 기능 추가
eonpain 4285268
Style: hooks 폴더 구조 변경
eonpain 25269cb
Fix: 검색창 관련 컴포넌트 내용수정
eonpain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import React, { useState, useEffect } from "react"; | ||
| import logoIcon from "../Image/logo.svg"; | ||
| import nullImg from "../Image/bulldog.png"; | ||
| import StarImg from "../Image/star.svg"; | ||
| import KebabImg from "../Image/kebab.svg"; | ||
| import { formatDateString, calculateElapsedTime } from "./Time"; | ||
| import * as S from "./Styled"; | ||
| import { DeleteLink, AddToFolderModal } from "./modal"; | ||
| import { LinkData } from "@utils/type"; | ||
|
|
||
| function Card({ data }: { data: LinkData }) { | ||
| const formattedDate = formatDateString(data.created_at); | ||
| const [imgNull, setImgNull] = useState(""); | ||
| const createdTime = calculateElapsedTime(data.created_at); | ||
| const [kebabBool, setKebabBool] = useState(false); | ||
| const [ago, setAgo] = useState(""); | ||
| const [modalContent, setModalContent] = useState<string | null>(null); | ||
| const [modalOpen, setModalOpen] = useState(false); | ||
|
|
||
| const handleKebabClick = () => { | ||
| setKebabBool((prevBool) => !prevBool); | ||
| }; | ||
|
|
||
| const setImageNull = () => { | ||
| if (data.image_source == undefined) { | ||
| setImgNull(nullImg); | ||
| } else { | ||
| setImgNull(data.image_source); | ||
| } | ||
| }; | ||
|
|
||
| const calculateAgo = (createdTime: number) => { | ||
| if (createdTime < 2) { | ||
| return "1 minute ago"; | ||
| } else if (createdTime <= 59) { | ||
| return `${createdTime} minutes ago`; | ||
| } else if (createdTime / 60 <= 23) { | ||
| return `${Math.ceil(createdTime / 60)} hour ago`; | ||
| } else if (createdTime / 60 >= 24 && createdTime / 60 / 24 < 2) { | ||
| return `1 day ago`; | ||
| } else if (createdTime / 60 / 24 >= 2 && createdTime / 60 / 24 <= 30) { | ||
| return `${Math.ceil(createdTime / 60 / 24)} days ago`; | ||
| } else if (createdTime / 60 / 24 > 30 && createdTime / 60 / 24 <= 60) { | ||
| return `1 month ago`; | ||
| } else if (createdTime / 60 / 24 > 60 && createdTime / 60 / 24 <= 365) { | ||
| return `${Math.ceil(createdTime / 60 / 24 / 30)} months ago`; | ||
| } else if (createdTime / 60 / 24 > 365 && createdTime / 60 / 24 <= 730) { | ||
| return `1 year ago`; | ||
| } else { | ||
| return `${Math.ceil(createdTime / 60 / 24 / 365)} years ago`; | ||
| } | ||
| }; | ||
|
|
||
| useEffect(setImageNull, [data.image_source]); | ||
| useEffect(() => { | ||
| const ago = calculateAgo(createdTime); | ||
| setAgo(ago); | ||
| }, [createdTime]); | ||
|
Comment on lines
+54
to
+58
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useEffect에 넘기는 콜백을 따로 선언하는 경우도 있고 화살표함수로 바로 선언하는 경우도 있네요. |
||
|
|
||
| const handleDeleteClick = () => { | ||
| setModalContent("DeleteLinkModal"); | ||
| setModalOpen(true); | ||
| }; | ||
|
|
||
| const handleAddToFolderClick = () => { | ||
| setModalContent("AddToFolderModal"); | ||
| setModalOpen(true); | ||
| }; | ||
|
|
||
| const handleCloseModal = () => { | ||
| setModalContent(null); | ||
| setModalOpen(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <S.Card> | ||
| <a href={`${data.url}`} target="_blank" rel="noopener noreferrer"> | ||
| <S.CardImgWrap> | ||
| {data.image_source === undefined ? ( | ||
| <> | ||
| <S.NullImg src={`${imgNull}`} alt={`${data.title}`}></S.NullImg> | ||
| <S.NullImg src={logoIcon} alt="logo"></S.NullImg> | ||
| </> | ||
| ) : ( | ||
| <S.CardImg src={`${imgNull}`} alt={`${data.title}`}></S.CardImg> | ||
| )} | ||
| </S.CardImgWrap> | ||
| </a> | ||
| <S.Star src={StarImg} alt="별 이미지" /> | ||
| <S.CardText className="cardText"> | ||
| <S.KebabAgoBox> | ||
| <S.Ago>{`${ago}`}</S.Ago> | ||
| <S.Kebab onClick={handleKebabClick}> | ||
| <img src={KebabImg} alt="케밥 이미지" /> | ||
| </S.Kebab> | ||
| {kebabBool && ( | ||
| <S.KebabSelect> | ||
| <S.kebabOption onClick={handleDeleteClick}> | ||
| 삭제하기 | ||
| </S.kebabOption> | ||
| <S.kebabOption onClick={handleAddToFolderClick}> | ||
| 폴더에 추가 | ||
| </S.kebabOption> | ||
| </S.KebabSelect> | ||
| )} | ||
| </S.KebabAgoBox> | ||
| <S.Des>{`${data.description}`}</S.Des> | ||
| <S.CardDate>{`${formattedDate}`}</S.CardDate> | ||
| </S.CardText> | ||
| </S.Card> | ||
| {modalOpen && modalContent === "DeleteLinkModal" && ( | ||
| <DeleteLink onClose={handleCloseModal} /> | ||
| )} | ||
| {modalOpen && modalContent === "AddToFolderModal" && ( | ||
| <AddToFolderModal onClose={handleCloseModal} /> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default Card; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
더 좋은 변수명이 있을 것 같습니다.
변수명이 타입(bool)을 포함하도록 하는 건 좋은 습관이 아니에요.
정확히 어떤 역할을 하는 변수인지 잘 표현해주세요.
약간의 팁을 드리자면 boolean 타입의 변수들에 경우 is~, has~ 같은 prefix를 붙이면 의미를 나타내기 좋습니다.
kebabBool같은 경우 삭제, 폴더의 추가 등 여러 동작들을 노출할지를 결정하므로
isShowMoreActions이런 느낌으로 네이밍 해볼 수 있겠네요.