diff --git a/src/component/OpenStrcat.tsx b/src/component/OpenStrcat.tsx
index c66b5ff2..60c4c103 100644
--- a/src/component/OpenStrcat.tsx
+++ b/src/component/OpenStrcat.tsx
@@ -4,9 +4,11 @@ interface Props {
id: string;
bgAndBorderColor: string;
timeTextColor: string;
+ theme: string;
+ contentCount: string;
+ contentTextCount: string;
title: string;
- description: string;
- time: string;
+ lastContentCreatedAt: string;
}
export default function OpenStrcat({
@@ -14,23 +16,30 @@ export default function OpenStrcat({
bgAndBorderColor,
timeTextColor,
title,
- description,
- time,
+ contentCount,
+ contentTextCount,
+ lastContentCreatedAt,
}: Props) {
+ const truncatedTitle = truncateText(title, 19);
+ const contentText = `${contentCount}개의 마음이 ${contentTextCount}자 이어졌어요!`;
+ const truncatedContentText = truncateText(contentText, 37);
+
return (
-
+
-
-
{title}
-
- {description}
+
+
+ {truncatedTitle}
+
+
+ {truncatedContentText}
- {time}
+ {timeString(lastContentCreatedAt)}
@@ -38,4 +47,38 @@ export default function OpenStrcat({
);
}
-const timeString = () => {};
+function truncateText(text: string, maxLength: number) {
+ if (text.length > maxLength) {
+ return text.substring(0, maxLength - 1) + '...';
+ }
+ return text;
+}
+
+const timeString = (date: string) => {
+ const now = new Date();
+ const lastContentCreatedAt = new Date(date);
+ const diff = now.getTime() - lastContentCreatedAt.getTime();
+ const diffSeconds = Math.floor(diff / 1000);
+ const diffMinutes = Math.floor(diffSeconds / 60);
+ const diffHours = Math.floor(diffMinutes / 60);
+ const diffDays = Math.floor(diffHours / 24);
+ const diffWeeks = Math.floor(diffDays / 7);
+ const diffMonths = Math.floor(diffDays / 30);
+ const diffYears = Math.floor(diffMonths / 12);
+
+ if (diffSeconds < 11 * 60) {
+ return '방금';
+ } else if (diffMinutes < 60) {
+ return `${diffMinutes}분 전`;
+ } else if (diffHours < 24) {
+ return `${diffHours}시간 전`;
+ } else if (diffDays < 7) {
+ return `${diffDays}일 전`;
+ } else if (diffWeeks < 4) {
+ return `${diffWeeks}주 전`;
+ } else if (diffMonths < 12) {
+ return `${diffMonths}개월 전`;
+ } else {
+ return `${diffYears}년 전`;
+ }
+};
diff --git a/src/component/OpenStrcatBoard.tsx b/src/component/OpenStrcatBoard.tsx
index 240eec1a..27cd698c 100644
--- a/src/component/OpenStrcatBoard.tsx
+++ b/src/component/OpenStrcatBoard.tsx
@@ -9,56 +9,43 @@ interface Props {
export default function OpenStrcatBoard({ openBoard }: Props) {
const bgAndBorderColor: Record
= {
- 'strcat-night': 'bg-strcat-night/50 border-strcat-night',
- 'strcat-peach': 'bg-strcat-peach/50 border-strcat-peach',
- 'strcat-lilac': 'bg-strcat-lilac/50 border-strcat-lilac',
- 'strcat-chris': 'bg-strcat-chris/50 border-strcat-chris',
- 'strcat-mas': 'bg-strcat-mas/50 border-strcat-mas',
- 'strcat-sul': 'bg-strcat-sul/50 border-strcat-sul',
- 'strcat-spring': 'bg-strcat-spring/50 border-strcat-spring',
+ night: 'bg-strcat-night/50 border-strcat-night',
+ peach: 'bg-strcat-peach/50 border-strcat-peach',
+ lilac: 'bg-strcat-lilac/50 border-strcat-lilac',
+ chris: 'bg-strcat-chris/50 border-strcat-chris',
+ mas: 'bg-strcat-mas/50 border-strcat-mas',
+ sul: 'bg-strcat-sul/50 border-strcat-sul',
+ spring: 'bg-strcat-spring/50 border-strcat-spring',
};
const textColor: Record = {
- 'strcat-night': 'text-strcat-night',
- 'strcat-peach': 'text-strcat-peach',
- 'strcat-lilac': 'text-strcat-lilac',
- 'strcat-chris': 'text-white',
- 'strcat-mas': 'text-white',
- 'strcat-sul': 'text-strcat-sul',
- 'strcat-spring': 'text-strcat-spring',
+ night: 'text-strcat-night',
+ peach: 'text-strcat-peach',
+ lilac: 'text-strcat-lilac',
+ chris: 'text-white',
+ mas: 'text-white',
+ sul: 'text-strcat-sul',
+ spring: 'text-strcat-spring',
};
- const colorList = Array.from(
- { length: 10 },
- (_, index) =>
- bgAndBorderColor[
- Object.keys(bgAndBorderColor)[
- index % Object.keys(bgAndBorderColor).length
- ]
- ],
- );
-
- const textColorList = Array.from(
- { length: 10 },
- (_, index) =>
- textColor[Object.keys(textColor)[index % Object.keys(textColor).length]],
- );
-
return (
{openBoard.map((item, i) => {
return (
-
-
-
+
+
+
+
+
);
})}
diff --git a/src/types/openBoard.ts b/src/types/openBoard.ts
index 50080c2c..301608fa 100644
--- a/src/types/openBoard.ts
+++ b/src/types/openBoard.ts
@@ -1,6 +1,8 @@
export interface openBoard {
+ contentCount: string;
+ contentTextCount: string;
id: string;
+ lastContentCreatedAt: string;
+ theme: string;
title: string;
- description: string;
- time: string;
}
diff --git a/src/utils/apiInterface.tsx b/src/utils/apiInterface.tsx
index f86426b8..0dc3caa9 100644
--- a/src/utils/apiInterface.tsx
+++ b/src/utils/apiInterface.tsx
@@ -7,7 +7,7 @@ export const axiosGetBoard = (id: string) => {
};
export const axiosGetPublicBoard = () => {
- return axios.get(`/api/public`);
+ return axiosInstance.get(`/boards/public`);
};
export const axiosGetBoardSummaries = (id: string) => {