From ff23415818acddb8a60dea2447e827e6fcce973e Mon Sep 17 00:00:00 2001 From: chyoo Date: Tue, 7 Jul 2026 09:29:44 +0900 Subject: [PATCH] paginate launcher source and build history --- src/pages/launcher/LauncherSourcePage.tsx | 67 ++++++++++++++++++----- src/pages/launcher/launcher-api.ts | 17 ++++++ 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/pages/launcher/LauncherSourcePage.tsx b/src/pages/launcher/LauncherSourcePage.tsx index c378732..d085b30 100644 --- a/src/pages/launcher/LauncherSourcePage.tsx +++ b/src/pages/launcher/LauncherSourcePage.tsx @@ -9,7 +9,7 @@ import { LoadingModal, useMinimumLoading } from '../operations/operation-utils'; import { getLauncherSource, getGiteaCommitDiff, - listGiteaCommits, + listGiteaCommitsPage, listLauncherVersions, listPlatformRepos, updateLauncherSource, @@ -130,6 +130,42 @@ function commitRangeSince(range: CommitRange) { return date.toISOString(); } +function diffLineClass(line: string) { + if (line.startsWith('+++') || line.startsWith('---')) { + return 'bg-sky-500/10 text-sky-200'; + } + if (line.startsWith('@@')) { + return 'bg-violet-500/15 text-violet-200'; + } + if (line.startsWith('+')) { + return 'bg-emerald-500/15 text-emerald-100'; + } + if (line.startsWith('-')) { + return 'bg-rose-500/15 text-rose-100'; + } + if (line.startsWith('diff --git') || line.startsWith('index ')) { + return 'bg-muted/40 text-foreground'; + } + return 'text-muted-foreground'; +} + +function DiffViewer({ diff }: { diff: string }) { + const lines = diff ? diff.split(/\r?\n/) : ['표시할 변경 내역이 없습니다.']; + + return ( +
+ {lines.map((line, index) => ( +
+ + {index + 1} + +
{line || ' '}
+
+ ))} +
+ ); +} + export function LauncherSourcePage() { const { toast } = useToast(); const [activeTarget, setActiveTarget] = useState('launcher-client'); @@ -144,6 +180,7 @@ export function LauncherSourcePage() { const [commitRange, setCommitRange] = useState('week'); const [commitPage, setCommitPage] = useState(1); const [hasNextCommitPage, setHasNextCommitPage] = useState(false); + const [totalCommits, setTotalCommits] = useState(null); const [commitsLoading, setCommitsLoading] = useState(false); const [commitsError, setCommitsError] = useState(''); const [diffTarget, setDiffTarget] = useState(null); @@ -158,6 +195,7 @@ export function LauncherSourcePage() { const activeVersion = useMemo(() => versions.find((version) => version.isActive) ?? versions[0], [versions]); const activeForm = forms[activeTarget]; const activeTargetMeta = targetLabels[activeTarget]; + const totalCommitPages = totalCommits === null ? null : Math.max(1, Math.ceil(totalCommits / commitPageSize)); const updateForm = (patch: Partial) => { setForms((prev) => ({ @@ -215,27 +253,30 @@ export function LauncherSourcePage() { setCommits([]); setCommitsError(''); setHasNextCommitPage(false); + setTotalCommits(null); return; } let canceled = false; setCommitsLoading(true); setCommitsError(''); - listGiteaCommits(repository.owner, repository.repo, sourceBranch, { + listGiteaCommitsPage(repository.owner, repository.repo, sourceBranch, { page: commitPage, - limit: commitPageSize + 1, + limit: commitPageSize, since: commitRangeSince(commitRange) }) - .then((nextCommits) => { + .then((result) => { if (!canceled) { - setCommits(nextCommits.slice(0, commitPageSize)); - setHasNextCommitPage(nextCommits.length > commitPageSize); + setCommits(result.commits); + setTotalCommits(result.total); + setHasNextCommitPage(result.total === null ? result.commits.length === commitPageSize : commitPage < Math.max(1, Math.ceil(result.total / commitPageSize))); } }) .catch((error: Error) => { if (!canceled) { setCommits([]); setHasNextCommitPage(false); + setTotalCommits(null); setCommitsError(error.message); } }) @@ -460,7 +501,9 @@ export function LauncherSourcePage() {
- 페이지 {commitPage} + + {totalCommits === null ? `페이지 ${commitPage}` : `총 ${totalCommits}건 · ${commitPage} / ${totalCommitPages}`} +
@@ -486,7 +529,7 @@ export function LauncherSourcePage() { open={Boolean(diffTarget)} title="커밋 내역 상세" onClose={() => setDiffTarget(null)} - className="max-w-5xl" + className="max-w-[min(96vw,1400px)]" footer={} > {diffTarget ? ( @@ -505,9 +548,7 @@ export function LauncherSourcePage() { ) : diffError ? (
Diff 조회 실패: {diffError}
) : ( -
-                {diffContent || '표시할 변경 내역이 없습니다.'}
-              
+ )}
) : null} diff --git a/src/pages/launcher/launcher-api.ts b/src/pages/launcher/launcher-api.ts index f689ce2..ecc02a0 100644 --- a/src/pages/launcher/launcher-api.ts +++ b/src/pages/launcher/launcher-api.ts @@ -221,6 +221,23 @@ export function listGiteaCommits( ).then((result) => result.commits); } +export function listGiteaCommitsPage( + owner: string, + repo: string, + branch = 'develop', + options: { page: number; limit: number; since?: string } +) { + const params = new URLSearchParams({ + sha: branch, + page: String(options.page), + limit: String(options.limit) + }); + if (options.since) params.set('since', options.since); + return apiRequest<{ commits: GiteaCommit[]; total: number | null; page: number; limit: number }>( + `/gitea/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/commits?${params.toString()}` + ); +} + export function getGiteaCommitDiff(owner: string, repo: string, sha: string) { return apiRequest<{ diff: string }>( `/gitea/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/commits/${encodeURIComponent(sha)}/diff`