-
Notifications
You must be signed in to change notification settings - Fork 6
Feat: CardItem 컴포넌트 구현, timeAgo 유틸함수 구현, star.svg kebab.svg 다운로드 #23
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
The head ref may contain hidden characters: "feature/Card-ui\uCEF4\uD3EC\uB10C\uD2B8-\uAD6C\uD604"
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { useState } from "react"; | ||
| import timeAgo from "@/util/timAgo"; | ||
| import Image from "next/image"; | ||
|
|
||
| interface linkDataType { | ||
| id: number; | ||
| title: string; | ||
| description: string; | ||
| favorite: boolean; | ||
| imageSource: string; | ||
| url: string; | ||
| createdAt: string; | ||
| } | ||
|
|
||
| const CardItem = (info: linkDataType) => { | ||
| const [isSubscribed, seIsSubscribed] = useState(false); | ||
| const [isOpen, setIsOpen] = useState(false); | ||
|
|
||
| const formattedDate = info.createdAt?.slice(0, 10).replace(/-/g, "."); | ||
| const createdTime = timeAgo(info.createdAt); | ||
|
|
||
| return ( | ||
| <div className="w-[340px] h-[344px] rounded-[12px] shadow-lg mt-20 ml-20 overflow-hidden cursor-pointer hover:scale-105 hover:duration-300"> | ||
| <section className="relative w-full h-[60%]"> | ||
| <Image | ||
| src={info.imageSource || `/images/no-content.svg`} | ||
| objectFit="cover" | ||
| alt="링크 미리보기" | ||
| fill | ||
| /> | ||
| {isSubscribed ? ( | ||
| <div | ||
| onClick={() => seIsSubscribed(!isSubscribed)} | ||
| className="absolute top-[15px] right-[15px] z-1" | ||
| > | ||
| <Image | ||
| src="/icons/star-fill.svg" | ||
| width={32} | ||
| height={32} | ||
| alt="subscripe button" | ||
| /> | ||
| </div> | ||
| ) : ( | ||
| <div | ||
| onClick={() => seIsSubscribed(!isSubscribed)} | ||
| className="absolute top-[15px] right-[15px] z-1" | ||
| > | ||
| <Image | ||
| src="/icons/star-empty.svg" | ||
| width={32} | ||
| height={32} | ||
| alt="subscripe button" | ||
| /> | ||
| </div> | ||
| )} | ||
| </section> | ||
|
|
||
| <section className="w-full h-[40%] flex flex-col justify-between gap-[10px] pt-[15px] px-[20px] pb-[10px]"> | ||
| <div className="flex justify-between"> | ||
| <span className="text-sm text-gray-400"> | ||
| {createdTime || "1일 전"} | ||
|
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. 작성시간 계산하는거는 나중에 따로 구현하실건가욤?
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. util/timeAgo를 제가 못봤었네요 ㅎ |
||
| </span> | ||
| <div | ||
| className="relative w-[21px] h-[17px]" | ||
| onClick={(state) => setIsOpen(!state)} | ||
| > | ||
| <Image src="/icons/kebab.svg" alt="kebab button" fill /> | ||
| </div> | ||
| </div> | ||
| <div className="text-[black100] text-lg "> | ||
|
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. 저는 text-black100 으로 작성해도 정상적으로 적용되더라구요! |
||
| {info.description || "설명"} | ||
| </div> | ||
| <div className="text-sm text-[black200]"> | ||
| {formattedDate || "2024.11.06"} | ||
| </div> | ||
| </section> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default CardItem; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| export default function Home() { | ||
| return <div>인덱스 페이지</div>; | ||
| } | ||
| export default function Home() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| function timeAgo(createdAt: string) { | ||
| const createdDate = new Date(createdAt); | ||
| const currentDate = new Date(); | ||
|
|
||
| const secondsDiff = Math.floor((currentDate - createdDate) / 1000); // 초 단위 차이 | ||
| const minutesDiff = Math.floor(secondsDiff / 60); // 분 단위 차이 | ||
| const hoursDiff = Math.floor(minutesDiff / 60); // 시간 단위 차이 | ||
| const daysDiff = Math.floor(hoursDiff / 24); // 일 단위 차이 | ||
|
|
||
| if (hoursDiff < 1) { | ||
| return `${secondsDiff}초 전`; // 1시간 미만 | ||
| } else if (hoursDiff < 24) { | ||
| return `${hoursDiff}시간 전`; // 1일 미만 | ||
| } else { | ||
| return `${daysDiff}일 전`; // 1일 이상 | ||
| } | ||
| } | ||
|
|
||
| export default timeAgo; |
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.
objectFit="cover" 이거 현재 버전에서 경고 뜰거에요
style={{ objectFit: 'cover' }} 이렇게 바꾸면 👍
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.
옹 어떤 경고죠?