From 4755873fe9ed44eeb442773b897388eb4311aa8c Mon Sep 17 00:00:00 2001 From: 0xExp-po Date: Mon, 9 Sep 2024 17:38:49 +0900 Subject: [PATCH] feat: display real commit history --- dapp/src/components/CommitHistory.astro | 34 ------- dapp/src/components/CommitHistory.jsx | 50 ++++++++++ dapp/src/components/CommitRecord.astro | 121 ------------------------ dapp/src/components/CommitRecord.jsx | 74 +++++++++++++++ dapp/src/components/ProjectInfo.astro | 21 +++- dapp/src/service/StateService.ts | 27 ++++++ 6 files changed, 168 insertions(+), 159 deletions(-) delete mode 100644 dapp/src/components/CommitHistory.astro create mode 100644 dapp/src/components/CommitHistory.jsx delete mode 100644 dapp/src/components/CommitRecord.astro create mode 100644 dapp/src/components/CommitRecord.jsx diff --git a/dapp/src/components/CommitHistory.astro b/dapp/src/components/CommitHistory.astro deleted file mode 100644 index 688b2e4..0000000 --- a/dapp/src/components/CommitHistory.astro +++ /dev/null @@ -1,34 +0,0 @@ ---- -import { getCommitHistory } from '../service/GithubService'; -import CommitRecord from './CommitRecord.astro'; -import { formatDate } from '../service/utils'; -import type { FormattedCommit } from '../types/github'; - -const commitHistory = await getCommitHistory('tupui', 'soroban-versioning'); ---- - -
- {commitHistory && commitHistory.length > 0 && commitHistory.map((day: { date: string; commits: FormattedCommit[] }) => ( -
-

-
- {formatDate(day.date)} -

-
- {day.commits.map((commit: FormattedCommit) => ( -
-
- -
- ))} -
-
- ))} -
diff --git a/dapp/src/components/CommitHistory.jsx b/dapp/src/components/CommitHistory.jsx new file mode 100644 index 0000000..b9eabdd --- /dev/null +++ b/dapp/src/components/CommitHistory.jsx @@ -0,0 +1,50 @@ +import React from 'react'; +import { getCommitHistory } from '../service/GithubService'; +import CommitRecord from './CommitRecord.jsx'; +import { formatDate } from '../service/utils'; +import { loadProjectRepoInfo } from '../service/StateService'; + +const CommitHistory = () => { + const [commitHistory, setCommitHistory] = React.useState([]); + + React.useEffect(() => { + const fetchCommitHistory = async () => { + const projectRepoInfo = loadProjectRepoInfo(); + if (projectRepoInfo?.author && projectRepoInfo?.repository) { + const history = await getCommitHistory(projectRepoInfo.author, projectRepoInfo.repository); + console.log("history:", history); + setCommitHistory(history); + } + }; + fetchCommitHistory(); + }, []); + + return ( +
+ {commitHistory.map((day) => ( +
+

+
+ {formatDate(day.date)} +

+
+ {day.commits.map((commit) => ( +
+ +
+ ))} +
+
+ ))} +
+ ); +}; + +export default CommitHistory; diff --git a/dapp/src/components/CommitRecord.astro b/dapp/src/components/CommitRecord.astro deleted file mode 100644 index 579b6af..0000000 --- a/dapp/src/components/CommitRecord.astro +++ /dev/null @@ -1,121 +0,0 @@ ---- -interface Props { - message: string; - date: string; - authorName: string; - authorGithubLink: string; - sha: string; - commitLink: string; -} - -const { message, date, authorName, authorGithubLink, sha, commitLink } = Astro.props; - -import { formatTime } from '../service/utils'; - -const formattedMessage = message.split(/\r?\n/).map((line: string) => line.trim()).filter(Boolean); -const firstLine = formattedMessage[0]; -const hasMoreLines = formattedMessage.length > 1; ---- - -
-
-
- {firstLine} - {hasMoreLines && ( - - )} -
- {hasMoreLines && ( - - )} -
- {authorName} - committed on - {formatTime(date)} -
-
-
- {sha.substring(0, 7)} - -
-
- - - diff --git a/dapp/src/components/CommitRecord.jsx b/dapp/src/components/CommitRecord.jsx new file mode 100644 index 0000000..cd37fc3 --- /dev/null +++ b/dapp/src/components/CommitRecord.jsx @@ -0,0 +1,74 @@ +import React, { useState, useEffect } from 'react'; +import { formatTime } from '../service/utils'; +import { loadProjectLatestSha } from '../service/StateService'; + +const CommitRecord = ({ message, date, authorName, authorGithubLink, sha, commitLink }) => { + const [isCopied, setIsCopied] = useState(false); + const [isLatestCommit, setIsLatestCommit] = useState(false); + const formattedMessage = message.split(/\r?\n/).map(line => line.trim()).filter(Boolean); + const firstLine = formattedMessage[0]; + const hasMoreLines = formattedMessage.length > 1; + const [isExpanded, setIsExpanded] = useState(false); + + useEffect(() => { + const highlightLatestCommit = () => { + const latestSha = 'cb2e487eb72e836d5ef9f00b52997416a56173dd'; + setIsLatestCommit(sha === latestSha); + }; + highlightLatestCommit(); + }, [sha]); + + const handleCopy = async () => { + try { + await navigator.clipboard.writeText(sha); + setIsCopied(true); + setTimeout(() => setIsCopied(false), 2000); + } catch (err) { + console.error('Failed to copy: ', err); + } + }; + + return ( +
+ {isLatestCommit && ( +
+ latest commit +
+ )} +
+
+ {firstLine} + {hasMoreLines && ( + + )} +
+ {hasMoreLines && isExpanded && ( +
{formattedMessage.slice(1).join('\n')}
+ )} +
+ {authorName} + committed on + {formatTime(date)} +
+
+
+ {sha.substring(0, 7)} + +
+
+ ); +}; + +export default CommitRecord; \ No newline at end of file diff --git a/dapp/src/components/ProjectInfo.astro b/dapp/src/components/ProjectInfo.astro index 20bb5dd..97781ad 100644 --- a/dapp/src/components/ProjectInfo.astro +++ b/dapp/src/components/ProjectInfo.astro @@ -2,7 +2,7 @@ import Topic from "./utils/Topic.astro"; import Modal from "./utils/Modal.astro"; import Loading from "./utils/Loading.astro"; -import CommitHistory from "./CommitHistory.astro"; +import CommitHistory from "./CommitHistory.jsx"; ---
@@ -50,7 +50,7 @@ import CommitHistory from "./CommitHistory.astro";
- +
@@ -111,8 +111,8 @@ import CommitHistory from "./CommitHistory.astro";