diff --git a/src/lib/components/prs/icons.ts b/src/lib/components/prs/icons.ts
new file mode 100644
index 0000000..597a4b6
--- /dev/null
+++ b/src/lib/components/prs/icons.ts
@@ -0,0 +1,6 @@
+export let pr_icon_path = {
+ open: "M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25m5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354M3.75 2.5a.75.75 0 1 0 0 1.5a.75.75 0 0 0 0-1.5m0 9.5a.75.75 0 1 0 0 1.5a.75.75 0 0 0 0-1.5m8.25.75a.75.75 0 1 0 1.5 0a.75.75 0 0 0-1.5 0",
+ close: "M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1m9.5 5.5a.75.75 0 0 1 .75.75v3.378a2.251 2.251 0 1 1-1.5 0V7.25a.75.75 0 0 1 .75-.75m-2.03-5.273a.75.75 0 0 1 1.06 0l.97.97l.97-.97a.748.748 0 0 1 1.265.332a.75.75 0 0 1-.205.729l-.97.97l.97.97a.751.751 0 0 1-.018 1.042a.751.751 0 0 1-1.042.018l-.97-.97l-.97.97a.749.749 0 0 1-1.275-.326a.749.749 0 0 1 .215-.734l.97-.97l-.97-.97a.75.75 0 0 1 0-1.06ZM2.5 3.25a.75.75 0 1 0 1.5 0a.75.75 0 0 0-1.5 0M3.25 12a.75.75 0 1 0 0 1.5a.75.75 0 0 0 0-1.5m9.5 0a.75.75 0 1 0 0 1.5a.75.75 0 0 0 0-1.5",
+ draft: "M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1m9.5 14a2.25 2.25 0 1 1 0-4.5a2.25 2.25 0 0 1 0 4.5M2.5 3.25a.75.75 0 1 0 1.5 0a.75.75 0 0 0-1.5 0M3.25 12a.75.75 0 1 0 0 1.5a.75.75 0 0 0 0-1.5m9.5 0a.75.75 0 1 0 0 1.5a.75.75 0 0 0 0-1.5M14 7.5a1.25 1.25 0 1 1-2.5 0a1.25 1.25 0 0 1 2.5 0m0-4.25a1.25 1.25 0 1 1-2.5 0a1.25 1.25 0 0 1 2.5 0",
+ merge: "M5.45 5.154A4.25 4.25 0 0 0 9.25 7.5h1.378a2.251 2.251 0 1 1 0 1.5H9.25A5.734 5.734 0 0 1 5 7.123v3.505a2.25 2.25 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.95-.218M4.25 13.5a.75.75 0 1 0 0-1.5a.75.75 0 0 0 0 1.5m8.5-4.5a.75.75 0 1 0 0-1.5a.75.75 0 0 0 0 1.5M5 3.25a.75.75 0 1 0 0 .005z",
+};
\ No newline at end of file
diff --git a/src/lib/components/prs/type.ts b/src/lib/components/prs/type.ts
index 1ae76ef..960e39a 100644
--- a/src/lib/components/prs/type.ts
+++ b/src/lib/components/prs/type.ts
@@ -9,6 +9,8 @@ export interface PRSummary {
repo_id: string;
id: string;
comments: number;
+ status: undefined | PRStatus,
+ status_date: number,
author: User;
created_at: number | undefined;
loading: boolean;
@@ -20,6 +22,8 @@ export const summary_defaults: PRSummary = {
repo_id: "",
id: "",
comments: 0,
+ status: undefined,
+ status_date: 0,
author: { ...user_defaults },
created_at: 0,
loading: true,
@@ -51,7 +55,6 @@ export function isPRStatus(potential_status: string | undefined): potential_stat
export interface PRFull {
summary: PRSummary;
pr_event: NDKEvent | undefined;
- status: PRStatus;
labels: string[];
events: Event[];
loading: boolean;
@@ -60,7 +63,6 @@ export interface PRFull {
export const full_defaults: PRFull = {
summary: { ...summary_defaults },
pr_event: undefined,
- status: "Open",
labels: [],
events: [],
loading: true,
diff --git a/src/lib/components/prs/vectors.ts b/src/lib/components/prs/vectors.ts
index 5927efb..8a6bb58 100644
--- a/src/lib/components/prs/vectors.ts
+++ b/src/lib/components/prs/vectors.ts
@@ -5,19 +5,23 @@ import { UserVectors } from "../users/vectors";
dayjs.extend(relativeTime);
+let Short = {
+ title: "short title",
+ author: { ...UserVectors.default },
+ created_at: dayjs().subtract(7, 'days').unix(),
+ comments: 2,
+ status: "Open",
+ loading: false,
+} as PRSummary;
+
export let PRsListItemArgsVectors = {
- Short: {
- title: "short title",
- author: { ...UserVectors.default },
- created_at: dayjs().subtract(7, 'days').unix(),
- comments: 2,
- loading: false,
- } as PRSummary,
+ Short,
Long: {
title: "rather long title that goes on and on and on and on and on and on and on and on and on and on and on and on and on and on and on",
author: { ...UserVectors.default },
created_at: dayjs().subtract(1, 'minute').unix(),
comments: 0,
+ status: "Open",
loading: false,
} as PRSummary,
LongNoSpaces: {
@@ -25,6 +29,7 @@ export let PRsListItemArgsVectors = {
author: { ...UserVectors.default },
created_at: dayjs().subtract(3, 'month').subtract(3, 'days').unix(),
comments: 1,
+ status: "Open",
loading: false,
} as PRSummary,
AuthorLoading: {
@@ -32,6 +37,23 @@ export let PRsListItemArgsVectors = {
author: { ...UserVectors.loading },
created_at: dayjs().subtract(3, 'month').subtract(3, 'days').unix(),
comments: 1,
+ status: "Open",
loading: false,
} as PRSummary,
+ StatusLoading: {
+ ...Short,
+ status: undefined,
+ } as PRSummary,
+ StatusDraft: {
+ ...Short,
+ status: "Draft",
+ } as PRSummary,
+ StatusClosed: {
+ ...Short,
+ status: "Closed",
+ } as PRSummary,
+ StatusMerged: {
+ ...Short,
+ status: "Merged",
+ } as PRSummary,
};
diff --git a/src/lib/stores/PR.ts b/src/lib/stores/PR.ts
index 9ca89b9..34396f5 100644
--- a/src/lib/stores/PR.ts
+++ b/src/lib/stores/PR.ts
@@ -145,7 +145,12 @@ export let ensurePRFull = (repo_id: string, pr_id: string) => {
selected_pr_full.update(full => {
return {
...full,
- status: potential_status as PRStatus,
+ summary: {
+ ...full.summary,
+ status: potential_status as PRStatus,
+ // this wont be 0 as we are ensuring it is not undefined above
+ status_date: event.created_at || 0,
+ },
};
});
}
@@ -158,10 +163,14 @@ export let ensurePRFull = (repo_id: string, pr_id: string) => {
});
});
- sub.on("eose", () => {
+ sub_replies.on("eose", () => {
selected_pr_full.update(full => {
let updated = {
...full,
+ summary: {
+ ...full.summary,
+ status: full.summary.status || "Open",
+ },
loading: false,
};
if (full.summary.loading === false) {
diff --git a/src/lib/stores/PRs.ts b/src/lib/stores/PRs.ts
index d8a9ea9..e09bdd9 100644
--- a/src/lib/stores/PRs.ts
+++ b/src/lib/stores/PRs.ts
@@ -1,11 +1,13 @@
import { NDKRelaySet, type NDKEvent, NDKSubscription } from "@nostr-dev-kit/ndk";
import { writable, type Unsubscriber, type Writable } from "svelte/store"
import { ndk } from "./ndk";
-import { summary_defaults } from "$lib/components/prs/type";
+import { isPRStatus, summary_defaults } from "$lib/components/prs/type";
import type { User } from "$lib/components/users/type";
import { ensureUser } from "./users";
-import type { PRSummaries } from "$lib/components/prs/type";
+import type { PRStatus, PRSummaries } from "$lib/components/prs/type";
import { ensureSelectedRepo } from "./repo";
+import { pr_status_kind } from "$lib/kinds";
+import type { Repo } from "$lib/components/repo/type";
export let pr_summaries: Writable
= writable({
id: "",
@@ -104,6 +106,7 @@ export let ensurePRSummaries = async (repo_id: string) => {
});
sub.on("eose", () => {
pr_summaries.update(prs => {
+ getAndUpdatePRStatus(prs, repo);
return {
...prs,
loading: false,
@@ -111,3 +114,67 @@ export let ensurePRSummaries = async (repo_id: string) => {
});
});
}
+
+let sub_statuses: NDKSubscription;
+
+function getAndUpdatePRStatus(prs: PRSummaries, repo: Repo): void {
+ if (sub_statuses) sub_statuses.stop();
+ sub_statuses = ndk.subscribe(
+ {
+ kinds: [pr_status_kind],
+ "#e": prs.summaries.map(pr => pr.id),
+ '#r': [`r-${prs.id}`],
+ },
+ {
+ closeOnEose: false,
+ },
+ NDKRelaySet.fromRelayUrls(repo.relays, ndk),
+ );
+ sub_statuses.on("event", (event: NDKEvent) => {
+ let tagged_pr_event = event.tagValue('e');
+ if (event.kind == pr_status_kind
+ && tagged_pr_event
+ && event.created_at
+ && event.getMatchingTags("t").length === 1
+ && event.getMatchingTags("t")[0].length > 1
+ ) {
+ let potential_status = event.getMatchingTags("t")[0][1];
+
+ if (isPRStatus(potential_status)) {
+ pr_summaries.update(prs => {
+ return {
+ ...prs,
+ summaries: prs.summaries.map(o => {
+ if (
+ o.id === tagged_pr_event
+ && event.created_at
+ && o.status_date < event.created_at
+ ) {
+ return {
+ ...o,
+ status: potential_status as PRStatus,
+ status_date: event.created_at,
+ }
+ }
+
+ return o;
+ }),
+ }
+ });
+ }
+ }
+ });
+
+ sub_statuses.on("eose", () => {
+ pr_summaries.update(prs => {
+ return {
+ ...prs,
+ summaries: prs.summaries.map(o => ({
+ ...o,
+ status: o.status || "Open",
+ })),
+ }
+ });
+ });
+
+}
\ No newline at end of file
diff --git a/src/routes/repo/[repo_id]/pr/[pr_id]/+page.svelte b/src/routes/repo/[repo_id]/pr/[pr_id]/+page.svelte
index bbeaca4..c7cfce4 100644
--- a/src/routes/repo/[repo_id]/pr/[pr_id]/+page.svelte
+++ b/src/routes/repo/[repo_id]/pr/[pr_id]/+page.svelte
@@ -75,7 +75,6 @@