diff --git a/src/lib/components/prs/Status.svelte b/src/lib/components/prs/Status.svelte
index 500ba84..2ab0084 100644
--- a/src/lib/components/prs/Status.svelte
+++ b/src/lib/components/prs/Status.svelte
@@ -1,7 +1,13 @@
@@ -11,13 +17,15 @@
- {#if status === 'Open'}
+ {#if status === proposal_status_open}
Open
- {:else if status === 'Merged'}
+ {:else if status === proposal_status_applied}
Merged
- {:else if status === 'Closed'}
+ {:else if status === proposal_status_closed}
Closed
- {:else if status === 'Draft'}
+ {:else if status === proposal_status_draft}
import { ndk } from '$lib/stores/ndk'
import { NDKEvent, NDKRelaySet } from '@nostr-dev-kit/ndk'
- import type { PRStatus } from './type'
import { selected_pr_full } from '$lib/stores/PR'
- import { pr_status_kind } from '$lib/kinds'
+ import {
+ proposal_status_applied,
+ proposal_status_closed,
+ proposal_status_draft,
+ proposal_status_open,
+ statusKindtoText,
+ } from '$lib/kinds'
import { getUserRelays, logged_in_user } from '$lib/stores/users'
import { selected_repo } from '$lib/stores/repo'
import Status from '$lib/components/prs/Status.svelte'
- export let status: PRStatus | undefined = undefined
+ export let status: number | undefined = undefined
export let repo_id: string = ''
export let pr_id: string = ''
@@ -20,13 +25,12 @@
$logged_in_user !== undefined && repo_id === $selected_repo.repo_id
}
- async function changeStatus(new_status: PRStatus) {
+ async function changeStatus(new_status_kind: number) {
if (!$logged_in_user) return
let event = new NDKEvent(ndk)
- event.kind = pr_status_kind
- event.tags.push(['l', new_status])
+ event.kind = new_status_kind
event.tags.push(['e', pr_id, 'root'])
- event.tags.push(['r', `r-${repo_id}`])
+ event.tags.push(['r', `${repo_id}`])
loading = true
let relays = [...$selected_repo.relays]
try {
@@ -54,7 +58,7 @@
...pr_full,
summary: {
...pr_full.summary,
- status: new_status,
+ status: new_status_kind,
status_date: event.created_at || 0,
},
}
@@ -74,43 +78,47 @@
tabIndex={0}
class="menu dropdown-content z-[1] ml-0 w-52 rounded-box bg-base-300 p-2 shadow"
>
- {#if status !== 'Draft'}
+ {#if status !== proposal_status_draft}
{
- changeStatus('Draft')
+ changeStatus(proposal_status_draft)
}}
- class="btn btn-neutral btn-sm mx-2 align-middle">Draft {statusKindtoText(proposal_status_draft)}
{/if}
- {#if status !== 'Open'}
+ {#if status !== proposal_status_open}
{
- changeStatus('Open')
+ changeStatus(proposal_status_open)
}}
- class="btn btn-success btn-sm mx-2 align-middle">Open {statusKindtoText(proposal_status_open)}
{/if}
- {#if status !== 'Merged'}
+ {#if status !== proposal_status_applied}
{
- changeStatus('Merged')
+ changeStatus(proposal_status_applied)
}}
- class="btn btn-primary btn-sm mx-2 align-middle">Merged {statusKindtoText(proposal_status_applied)}
{/if}
- {#if status !== 'Closed'}
+ {#if status !== proposal_status_closed}
{
- changeStatus('Closed')
+ changeStatus(proposal_status_closed)
}}
- class="btn btn-neutral btn-sm mx-2 align-middle">Closed {statusKindtoText(proposal_status_closed)}
{/if}
diff --git a/src/lib/components/prs/type.ts b/src/lib/components/prs/type.ts
index f55b85c..8477384 100644
--- a/src/lib/components/prs/type.ts
+++ b/src/lib/components/prs/type.ts
@@ -9,7 +9,7 @@ export interface PRSummary {
repo_id: string
id: string
comments: number
- status: undefined | PRStatus
+ status: undefined | number
status_date: number
author: User
created_at: number | undefined
@@ -41,19 +41,6 @@ export const summaries_defaults: PRSummaries = {
loading: true,
}
-export type PRStatus = 'Draft' | 'Open' | 'Merged' | 'Closed'
-
-export function isPRStatus(
- potential_status: string | undefined
-): potential_status is PRStatus {
- return (
- !!potential_status &&
- (potential_status == 'Draft' ||
- potential_status == 'Open' ||
- potential_status == 'Merged' ||
- potential_status == 'Closed')
- )
-}
export interface PRFull {
summary: PRSummary
pr_event: NDKEvent | undefined
diff --git a/src/lib/kinds.ts b/src/lib/kinds.ts
index 309d092..e482c7c 100644
--- a/src/lib/kinds.ts
+++ b/src/lib/kinds.ts
@@ -1,6 +1,22 @@
export const reply_kind: number = 1622
-export const pr_status_kind: number = 19851985
+export const proposal_status_open: number = 1630
+export const proposal_status_applied: number = 1631
+export const proposal_status_closed: number = 1632
+export const proposal_status_draft: number = 1633
+export const pr_status_kinds: number[] = [
+ proposal_status_open,
+ proposal_status_applied,
+ proposal_status_closed,
+ proposal_status_draft,
+]
+
+export function statusKindtoText(kind: number): string {
+ if (kind === proposal_status_open) return 'Open'
+ if (kind === proposal_status_applied) return 'Applied'
+ if (kind === proposal_status_closed) return 'Closed'
+ return 'Draft'
+}
export const repo_kind: number = 30617
diff --git a/src/lib/stores/PR.ts b/src/lib/stores/PR.ts
index cf2ed80..77f2fbb 100644
--- a/src/lib/stores/PR.ts
+++ b/src/lib/stores/PR.ts
@@ -3,13 +3,8 @@ import { writable, type Unsubscriber, type Writable } from 'svelte/store'
import { ndk } from './ndk'
import type { User } from '$lib/components/users/type'
import { ensureUser } from './users'
-import {
- type PRFull,
- full_defaults,
- isPRStatus,
- type PRStatus,
-} from '$lib/components/prs/type'
-import { pr_status_kind } from '$lib/kinds'
+import { type PRFull, full_defaults } from '$lib/components/prs/type'
+import { pr_status_kinds, proposal_status_open } from '$lib/kinds'
import { ensureSelectedRepo } from './repo'
import { extractPatchMessage } from '$lib/components/events/content/utils'
import { goto } from '$app/navigation'
@@ -154,28 +149,23 @@ export const ensurePRFull = (repo_id: string, pr_id: string) => {
sub_replies.on('event', (event: NDKEvent) => {
if (
- event.kind == pr_status_kind &&
+ event.kind &&
+ pr_status_kinds.includes(event.kind) &&
event.created_at &&
- selected_pr_status_date < event.created_at &&
- event.getMatchingTags('l').length === 1 &&
- event.getMatchingTags('l')[0].length > 1
+ selected_pr_status_date < event.created_at
) {
- const potential_status = event.getMatchingTags('l')[0][1]
-
- if (isPRStatus(potential_status)) {
- selected_pr_status_date = event.created_at
- selected_pr_full.update((full) => {
- return {
- ...full,
- 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,
- },
- }
- })
- }
+ selected_pr_status_date = event.created_at
+ selected_pr_full.update((full) => {
+ return {
+ ...full,
+ summary: {
+ ...full.summary,
+ status: event.kind,
+ // this wont be 0 as we are ensuring it is not undefined above
+ status_date: event.created_at || 0,
+ },
+ }
+ })
}
selected_pr_replies.update((replies) => {
return [...replies, event].sort(
@@ -190,7 +180,7 @@ export const ensurePRFull = (repo_id: string, pr_id: string) => {
...full,
summary: {
...full.summary,
- status: full.summary.status || 'Open',
+ status: full.summary.status || proposal_status_open,
},
loading: false,
}
diff --git a/src/lib/stores/PRs.ts b/src/lib/stores/PRs.ts
index 15b55ac..6c34bd9 100644
--- a/src/lib/stores/PRs.ts
+++ b/src/lib/stores/PRs.ts
@@ -6,12 +6,17 @@ import {
} from '@nostr-dev-kit/ndk'
import { writable, type Unsubscriber, type Writable } from 'svelte/store'
import { ndk } from './ndk'
-import { isPRStatus, summary_defaults } from '$lib/components/prs/type'
+import { summary_defaults } from '$lib/components/prs/type'
import type { User } from '$lib/components/users/type'
import { ensureUser } from './users'
-import type { PRStatus, PRSummaries } from '$lib/components/prs/type'
+import type { PRSummaries } from '$lib/components/prs/type'
import { ensureSelectedRepo } from './repo'
-import { patch_kind, pr_status_kind, repo_kind } from '$lib/kinds'
+import {
+ patch_kind,
+ pr_status_kinds,
+ proposal_status_open,
+ repo_kind,
+} from '$lib/kinds'
import type { Repo } from '$lib/components/repo/type'
import { extractPatchMessage } from '$lib/components/events/content/utils'
@@ -138,7 +143,7 @@ function getAndUpdatePRStatus(prs: PRSummaries, repo: Repo): void {
if (sub_statuses) sub_statuses.stop()
sub_statuses = ndk.subscribe(
{
- kinds: [pr_status_kind],
+ kinds: pr_status_kinds,
'#e': prs.summaries.map((pr) => pr.id),
'#r': [`r-${prs.id}`],
},
@@ -150,36 +155,31 @@ function getAndUpdatePRStatus(prs: PRSummaries, repo: Repo): void {
sub_statuses.on('event', (event: NDKEvent) => {
const tagged_pr_event = event.tagValue('e')
if (
- event.kind == pr_status_kind &&
+ event.kind &&
+ pr_status_kinds.includes(event.kind) &&
tagged_pr_event &&
- event.created_at &&
- event.getMatchingTags('l').length === 1 &&
- event.getMatchingTags('l')[0].length > 1
+ event.created_at
) {
- const potential_status = event.getMatchingTags('l')[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,
- }
+ 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: event.kind as number,
+ status_date: event.created_at,
}
+ }
- return o
- }),
- }
- })
- }
+ return o
+ }),
+ }
+ })
}
})
@@ -189,12 +189,9 @@ function getAndUpdatePRStatus(prs: PRSummaries, repo: Repo): void {
...prs,
summaries: prs.summaries.map((o) => ({
...o,
- status: o.status || 'Open',
+ status: o.status || proposal_status_open,
})),
}
})
})
}
-function extractTagContent(arg0: string): string {
- throw new Error('Function not implemented.')
-}