|
|
@@ -0,0 +1,77 @@
|
|
|
+<script lang="ts">
|
|
|
+ import { GitCommitVertical, GitPullRequestIcon } from '@lucide/svelte';
|
|
|
+ import { formatDistanceToNow } from 'date-fns';
|
|
|
+
|
|
|
+ import { GlassPane } from '$lib/components/common/glass-pane';
|
|
|
+ import type { GitCommit, GitPullRequest } from '$lib/types/workspace';
|
|
|
+ import type { Changes } from '$lib/types/workspace';
|
|
|
+
|
|
|
+ let { onloadchanges }: { onloadchanges?: () => Promise<Changes> } = $props();
|
|
|
+
|
|
|
+ const PAGE_SIZE = 5;
|
|
|
+ let loading = $state(true);
|
|
|
+ let expanded = $state(false);
|
|
|
+ let prs = $state<GitPullRequest[]>([]);
|
|
|
+ let commits = $state<GitCommit[]>([]);
|
|
|
+
|
|
|
+ $effect(() => {
|
|
|
+ fetchData();
|
|
|
+ });
|
|
|
+
|
|
|
+ const fetchData = async () => {
|
|
|
+ loading = true;
|
|
|
+ try {
|
|
|
+ const changes = await onloadchanges?.();
|
|
|
+ if (changes) {
|
|
|
+ prs = changes.gitPullRequests;
|
|
|
+ commits = changes.gitCommits;
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.error('Failed to fetch changes:', err);
|
|
|
+ }
|
|
|
+ loading = false;
|
|
|
+ };
|
|
|
+
|
|
|
+ const openPrs = $derived(prs.filter((p) => !p.merged && p.state === 'open'));
|
|
|
+ const total = $derived(openPrs.length + commits.length);
|
|
|
+ const visibleCommits = $derived(
|
|
|
+ expanded ? commits : commits.slice(0, Math.max(0, PAGE_SIZE - openPrs.length)),
|
|
|
+ );
|
|
|
+
|
|
|
+ const formatDate = (date?: Date) => (date ? formatDistanceToNow(date, { addSuffix: true }) : '');
|
|
|
+</script>
|
|
|
+
|
|
|
+<div>
|
|
|
+ <h2 class="mb-2 text-lg font-thin text-white/75">History</h2>
|
|
|
+ <div class="space-y-2">
|
|
|
+ {#each openPrs as pr (pr.id)}
|
|
|
+ <GlassPane class="flex items-center gap-2 px-3 py-2">
|
|
|
+ <GitPullRequestIcon class="shrink-0 text-blue-400/70" size={14} strokeWidth={2} />
|
|
|
+ <span class="flex-1 text-sm text-white/80">{pr.title}</span>
|
|
|
+ <span class="shrink-0 text-xs text-white/30">{formatDate(pr.createdAt)}</span>
|
|
|
+ </GlassPane>
|
|
|
+ {/each}
|
|
|
+ {#each visibleCommits as commit (commit.sha)}
|
|
|
+ <GlassPane class="flex items-center gap-2 px-3 py-2">
|
|
|
+ <GitCommitVertical class="shrink-0 text-white/30" size={14} strokeWidth={2} />
|
|
|
+ <code class="w-14 shrink-0 font-mono text-xs text-white/30">
|
|
|
+ {commit.sha.substring(0, 7)}
|
|
|
+ </code>
|
|
|
+ <span class="flex-1 text-sm text-white/80">{commit.message}</span>
|
|
|
+ <span class="shrink-0 text-xs text-white/30">{formatDate(commit.createdAt)}</span>
|
|
|
+ </GlassPane>
|
|
|
+ {/each}
|
|
|
+ {#if openPrs.length === 0 && commits.length === 0 && !loading}
|
|
|
+ <p class="text-sm text-white/25">No changes found</p>
|
|
|
+ {/if}
|
|
|
+ </div>
|
|
|
+ {#if total > PAGE_SIZE}
|
|
|
+ <button
|
|
|
+ class="mt-2 w-full py-1.5 text-center text-xs text-white/30 hover:text-white/60"
|
|
|
+ type="button"
|
|
|
+ onclick={() => (expanded = !expanded)}
|
|
|
+ >
|
|
|
+ {expanded ? 'Show Less' : 'Show More…'}
|
|
|
+ </button>
|
|
|
+ {/if}
|
|
|
+</div>
|