Browse Source

feat(RepoPage): display nip34 patches as prs

with nip34 in its current state there is no way to identify the root
patch without first requesting all patches and client side filtering
out the ones with `[ PATCH n/n ]` in
the content

this commit doesn't do that filtering
master
DanConwayDev 2 years ago
parent
commit
c0754728ce
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 5
      src/lib/components/RepoSummaryCard.svelte
  2. 88
      src/lib/stores/PRs.ts
  3. 2
      src/routes/repo/[repo_id]/+page.ts

5
src/lib/components/RepoSummaryCard.svelte

@ -22,8 +22,9 @@ @@ -22,8 +22,9 @@
<div class="skeleton mb-2 h-5 w-40"></div>
<div class="w-100 skeleton h-4"></div>
{:else}
<a class="link-primary break-words" href="/repo/{encodeURI(repo_id)}"
>{short_name}</a
<a
class="link-primary break-words"
href="/repo/{encodeURIComponent(repo_id)}">{short_name}</a
>
{#if short_descrption.length > 0}
<p class="text-muted break-words pb-1 text-sm">

88
src/lib/stores/PRs.ts

@ -6,8 +6,9 @@ import type { User } from '$lib/components/users/type' @@ -6,8 +6,9 @@ import type { User } from '$lib/components/users/type'
import { ensureUser } from './users'
import type { PRStatus, PRSummaries } from '$lib/components/prs/type'
import { ensureSelectedRepo } from './repo'
import { pr_status_kind } from '$lib/kinds'
import { patch_kind, pr_kind, pr_status_kind, repo_kind } from '$lib/kinds'
import type { Repo } from '$lib/components/repo/type'
import { extractPatchMessage } from '$lib/components/events/content/utils'
export const pr_summaries: Writable<PRSummaries> = writable({
id: '',
@ -15,8 +16,6 @@ export const pr_summaries: Writable<PRSummaries> = writable({ @@ -15,8 +16,6 @@ export const pr_summaries: Writable<PRSummaries> = writable({
loading: false,
})
const pr_kind: number = 318
let selected_repo_id: string = ''
let authors_unsubscribers: Unsubscriber[] = []
@ -41,23 +40,58 @@ export const ensurePRSummaries = async (repo_id: string) => { @@ -41,23 +40,58 @@ export const ensurePRSummaries = async (repo_id: string) => {
const repo = await ensureSelectedRepo(repo_id)
sub = ndk.subscribe(
[
{
kinds: [pr_kind],
'#a': repo.maintainers.map(
(m) => `${repo_kind}:${m.hexpubkey}:${repo.repo_id}`
),
limit: 50,
},
{
kinds: [patch_kind],
'#a': repo.maintainers.map(
(m) => `${repo_kind}:${m.hexpubkey}:${repo.repo_id}`
),
limit: 50,
},
],
{
kinds: [pr_kind],
'#r': [`r-${repo_id}`],
limit: 50,
closeOnEose: true,
},
{
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(repo.relays, ndk)
repo.relays.length > 0
? NDKRelaySet.fromRelayUrls(repo.relays, ndk)
: undefined
)
sub.on('event', (event: NDKEvent) => {
try {
if (
event.kind == pr_kind &&
event.getMatchingTags('r').find((t) => t[1] === `r-${repo_id}`)
) {
if (event.kind == patch_kind && event.content.length > 0) {
pr_summaries.update((prs) => {
return {
...prs,
summaries: [
...prs.summaries,
{
...summary_defaults,
id: event.id,
repo_id: repo_id,
title: extractPatchMessage(event.content) || '',
descritpion: event.tagValue('description') || '',
created_at: event.created_at,
comments: 0,
author: {
hexpubkey: event.pubkey,
loading: true,
npub: '',
},
loading: false,
},
],
}
})
}
if (event.kind == pr_kind) {
pr_summaries.update((prs) => {
return {
...prs,
@ -81,21 +115,21 @@ export const ensurePRSummaries = async (repo_id: string) => { @@ -81,21 +115,21 @@ export const ensurePRSummaries = async (repo_id: string) => {
],
}
})
}
authors_unsubscribers.push(
ensureUser(event.pubkey).subscribe((u: User) => {
pr_summaries.update((prs) => {
return {
...prs,
summaries: prs.summaries.map((o) => ({
...o,
author: u,
})),
}
})
authors_unsubscribers.push(
ensureUser(event.pubkey).subscribe((u: User) => {
pr_summaries.update((prs) => {
return {
...prs,
summaries: prs.summaries.map((o) => ({
...o,
author: event.pubkey === o.author.hexpubkey ? u : o.author,
})),
}
})
)
}
})
)
} catch {}
})
sub.on('eose', () => {

2
src/routes/repo/[repo_id]/+page.ts

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
export const load = ({ params }) => {
return {
repo_id: params.repo_id,
repo_id: decodeURIComponent(params.repo_id),
}
}

Loading…
Cancel
Save