Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
81 changes: 81 additions & 0 deletions components/CardItem.tsx
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"
Copy link
Collaborator

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' }} 이렇게 바꾸면 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

옹 어떤 경고죠?

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일 전"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

작성시간 계산하는거는 나중에 따로 구현하실건가욤?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 ">
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
4 changes: 1 addition & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export default function Home() {
return <div>인덱스 페이지</div>;
}
export default function Home() {}
5 changes: 5 additions & 0 deletions public/icons/kebab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/icons/star-empty.svg
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 public/icons/star-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions public/images/no-content.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions util/timAgo.ts
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;
Loading