Skip to content

Commit

Permalink
Merge pull request #158 from Team-INSERT/refactor/history
Browse files Browse the repository at this point in the history
refactor : history 페이지
  • Loading branch information
Ubinquitous authored Apr 16, 2024
2 parents 8933406 + 7ac78a0 commit c5b19af
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
8 changes: 4 additions & 4 deletions app/history/[title]/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const History = ({ title }: { title: string }) => {
className={styles.historyBox}
key={String(history.thisVersionCreatedAt)}
>
<div className={styles.hgroup}>
<hgroup className={styles.hgroup}>
<h1 className={styles.historyId}>#{history.index}</h1>
<span className={styles.createdAt}>
<time className={styles.createdAt}>
편집일 ·&nbsp;
{formatDate(history.thisVersionCreatedAt)}
</span>
</div>
</time>
</hgroup>
<span className={styles.author}>작성자 ·&nbsp;{history.nickName}</span>
</Link>
))}
Expand Down
25 changes: 13 additions & 12 deletions app/history/[title]/detail/[id]/HistoryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { FC } from "react";
import Link from "next/link";
import Container from "@/components/Container";
import { VersionDifferent } from "@/enum";
import { useSuspenseQuery } from "@tanstack/react-query";
import { historyQuery } from "@/services/history/history.query";
import * as styles from "./style.css";
Expand All @@ -21,33 +22,33 @@ const HistoryDetail: FC<{ id: number; title: string }> = ({ id, title }) => {
docsType={history.docsType}
lastModifiedAt={history.versionDocs.thisVersionCreatedAt}
>
<div className={styles.container}>
<main className={styles.container}>
<Link href={`/user/${history.versionDocs.userId}`} className={styles.author}>
작성자 · {history.versionDocs.nickName}
</Link>
<div className={styles.historyBox}>
<ul className={styles.historyBox}>
{history.diff.map((dif: HistoryType, historyId: number) => {
const operationIcon = (() => {
switch (dif.operation) {
case "INSERT":
case VersionDifferent.INSERT:
return "+";
case "DELETE":
case VersionDifferent.DELETE:
return "-";
case "EQUAL":
return "";
case VersionDifferent.EQUAL:
return;
default:
return dif.operation;
}
})();
return (
<div key={historyId} className={styles.historyContent}>
<div className={styles.historyOperation[dif.operation]}>{operationIcon}</div>
<div className={styles.history[dif.operation]}>{dif.text}</div>
</div>
<li key={historyId} className={styles.historyContent}>
<i className={styles.historyOperation[dif.operation]}>{operationIcon}</i>
<p className={styles.history[dif.operation]}>{dif.text}</p>
</li>
);
})}
</div>
</div>
</ul>
</main>
</Container>
);
};
Expand Down
5 changes: 3 additions & 2 deletions app/history/[title]/detail/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ interface PageProps {
}

export const generateMetadata = async ({ params: { title, id } }: PageProps): Promise<Metadata> => {
const decodedTitle = decodeURI(title);
return generateOpenGraph({
title: `역사#${decodeURI(title)}_${id}`,
description: `${decodeURI(title)} 문서의 ${id}번째 역사입니다.`,
title: `역사#${decodedTitle}_${id}`,
description: `${decodedTitle} 문서의 ${id}번째 역사입니다.`,
});
};

Expand Down
5 changes: 3 additions & 2 deletions app/history/[title]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ interface PageProps {
}

export const generateMetadata = async ({ params: { title } }: PageProps): Promise<Metadata> => {
const decodedTitle = decodeURI(title);
return generateOpenGraph({
title: `역사#${decodeURI(title)}`,
description: `${decodeURI(title)} 문서의 역사입니다.`,
title: `역사#${decodedTitle}`,
description: `${decodedTitle} 문서의 역사입니다.`,
});
};

Expand Down
1 change: 1 addition & 0 deletions enum/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as EditorType } from "./editorType.enum";
export { default as VersionDifferent } from "./versionDifferent.enum";
7 changes: 7 additions & 0 deletions enum/versionDifferent.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum VersionDifferent {
INSERT = "INSERT",
DELETE = "DELETE",
EQUAL = "EQUAL",
}

export default VersionDifferent;

0 comments on commit c5b19af

Please sign in to comment.