|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
import type { User } from "../users/type"; |
||||
import { defaults as user_defaults } from "../users/type"; |
||||
|
||||
export interface PRSummary { |
||||
title: string; |
||||
id: string; |
||||
comments: number; |
||||
author: User; |
||||
created_at: number | undefined; |
||||
loading: boolean; |
||||
} |
||||
|
||||
export const defaults: PRSummary = { |
||||
title: "", |
||||
id: "", |
||||
comments: 0, |
||||
author: { ...user_defaults }, |
||||
created_at: 0, |
||||
loading: true, |
||||
}; |
||||
|
||||
export interface PRSummaries { |
||||
id: string; |
||||
summaries: PRSummary[]; |
||||
loading: boolean; |
||||
} |
||||
|
||||
export const summaries_defaults: PRSummaries = { |
||||
id: "", |
||||
summaries: [], |
||||
loading: true, |
||||
}; |
||||
@ -1,26 +1,37 @@
@@ -1,26 +1,37 @@
|
||||
import type { Args as PRListItemArgs } from "./PRsListItem.svelte"; |
||||
import dayjs from "dayjs"; |
||||
import relativeTime from "dayjs/plugin/relativeTime"; |
||||
import type { PRSummary } from "./type"; |
||||
import { UserVectors } from "../users/vectors"; |
||||
|
||||
dayjs.extend(relativeTime); |
||||
|
||||
export let PRsListItemArgsVectors = { |
||||
Short: { |
||||
title: "short title", |
||||
author: "fred", |
||||
author: { ...UserVectors.default }, |
||||
created_at: dayjs().subtract(7, 'days').unix(), |
||||
comments: 2, |
||||
} as PRListItemArgs, |
||||
loading: false, |
||||
} as PRSummary, |
||||
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: "carole", |
||||
author: { ...UserVectors.default }, |
||||
created_at: dayjs().subtract(1, 'minute').unix(), |
||||
comments: 0, |
||||
} as PRListItemArgs, |
||||
loading: false, |
||||
} as PRSummary, |
||||
LongNoSpaces: { |
||||
title: "LongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongName", |
||||
author: "steve", |
||||
author: { ...UserVectors.default }, |
||||
created_at: dayjs().subtract(3, 'month').subtract(3, 'days').unix(), |
||||
comments: 1, |
||||
} as PRListItemArgs, |
||||
}; |
||||
loading: false, |
||||
} as PRSummary, |
||||
AuthorLoading: { |
||||
title: "short title", |
||||
author: { ...UserVectors.loading }, |
||||
created_at: dayjs().subtract(3, 'month').subtract(3, 'days').unix(), |
||||
comments: 1, |
||||
loading: false, |
||||
} as PRSummary, |
||||
}; |
||||
@ -0,0 +1,100 @@
@@ -0,0 +1,100 @@
|
||||
import type { NDKEvent } from "@nostr-dev-kit/ndk"; |
||||
import { writable, type Unsubscriber, type Writable } from "svelte/store" |
||||
import { ndk } from "./ndk"; |
||||
import type { Repo } from "$lib/components/repo/type"; |
||||
import { defaults } from "$lib/components/prs/type"; |
||||
import type { User } from "$lib/components/users/type"; |
||||
import { ensureUser, users } from "./users"; |
||||
import type { PRSummaries, PRSummary } from "$lib/components/prs/type"; |
||||
|
||||
export let pr_summaries: Writable<PRSummaries> = writable({ |
||||
id: "", |
||||
summaries: [], |
||||
loading: false, |
||||
}); |
||||
|
||||
let pr_kind: number = 318; |
||||
|
||||
let selected_repo_id: string = ""; |
||||
|
||||
let authors_unsubscribers: Unsubscriber[] = []; |
||||
|
||||
export let ensurePRSummaries = (repo_id: string) => { |
||||
if (selected_repo_id == repo_id) return; |
||||
if (repo_id == "") return pr_summaries.set({ |
||||
id: "", |
||||
summaries: [], |
||||
loading: false, |
||||
}); |
||||
|
||||
selected_repo_id = repo_id; |
||||
pr_summaries.update(prs => { |
||||
return { |
||||
...prs, |
||||
id: repo_id, |
||||
loading: true, |
||||
}; |
||||
}); |
||||
authors_unsubscribers.forEach(u => u()); |
||||
authors_unsubscribers = []; |
||||
|
||||
let sub = ndk.subscribe({ |
||||
kinds: [pr_kind], |
||||
'#r': [`r-${repo_id}`], |
||||
limit: 50, |
||||
}); |
||||
|
||||
sub.on("event", (event: NDKEvent) => { |
||||
try { |
||||
if (event.kind == pr_kind |
||||
&& event.getMatchingTags("r").find(t => t[1] === `r-${repo_id}`) |
||||
) { |
||||
console.log(event); |
||||
pr_summaries.update(prs => { |
||||
return { |
||||
...prs, |
||||
summaries: [ |
||||
...prs.summaries, |
||||
{ |
||||
...defaults, |
||||
id: event.id, |
||||
title: event.tagValue("name") || "", |
||||
created_at: event.created_at, |
||||
comments: 0, |
||||
author: { |
||||
hexpubkey: event.pubkey, |
||||
loading: true, |
||||
npub: "", |
||||
}, |
||||
loading: false, |
||||
} |
||||
], |
||||
} |
||||
}); |
||||
|
||||
authors_unsubscribers.push( |
||||
ensureUser(event.pubkey).subscribe((u: User) => { |
||||
pr_summaries.update(prs => { |
||||
console.log('test'); |
||||
return { |
||||
...prs, |
||||
summaries: prs.summaries.map(o => ({ |
||||
...o, |
||||
author: u, |
||||
})), |
||||
} |
||||
}); |
||||
}) |
||||
); |
||||
} |
||||
} catch { } |
||||
}); |
||||
sub.on("eose", () => { |
||||
pr_summaries.update(prs => { |
||||
return { |
||||
...prs, |
||||
loading: false, |
||||
}; |
||||
}); |
||||
}); |
||||
} |
||||
@ -1,38 +1,14 @@
@@ -1,38 +1,14 @@
|
||||
<script lang="ts"> |
||||
import PRsList from "$lib/components/PRsList.svelte"; |
||||
import type { Args } from "$lib/components/PRsListItem.svelte"; |
||||
import { ndk } from "$lib/stores/ndk"; |
||||
import PRsList from "$lib/components/prs/PRsList.svelte"; |
||||
import { ensurePRSummaries, pr_summaries } from "$lib/stores/PRs"; |
||||
|
||||
export let limit: number = 100; |
||||
|
||||
let prs: Args[] = []; |
||||
export let loading: boolean = true; |
||||
let repo_kind: number = 30317; |
||||
let pr_kind: number = 318; |
||||
export let repo_id: string = ""; |
||||
|
||||
let sub = ndk.subscribe({ |
||||
kinds: [pr_kind], |
||||
"#d": [repo_id], |
||||
limit, |
||||
}); |
||||
sub.on("event", (event) => { |
||||
if (prs.length < limit) { |
||||
if (event.kind == pr_kind) |
||||
prs = [ |
||||
...prs, |
||||
{ |
||||
title: event.tagValue("name") || "", |
||||
author: event.pubkey, |
||||
created_at: event.created_at, |
||||
comments: 1, |
||||
}, |
||||
]; |
||||
} else if (loading == true) loading = false; |
||||
}); |
||||
sub.on("eose", () => { |
||||
if (loading == true) loading = false; |
||||
}); |
||||
ensurePRSummaries(repo_id); |
||||
</script> |
||||
|
||||
<PRsList title="Open PRs" {prs} {loading} /> |
||||
<PRsList |
||||
title="Open PRs" |
||||
prs={$pr_summaries.summaries} |
||||
loading={$pr_summaries.loading} |
||||
/> |
||||
|
||||