Browse Source

feat!: changed to nip34 status

using different kind numbers for each status type
master
DanConwayDev 2 years ago
parent
commit
a9ae256ec0
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 24
      src/lib/components/prs/Status.svelte
  2. 48
      src/lib/components/prs/StatusSelector.svelte
  3. 15
      src/lib/components/prs/type.ts
  4. 18
      src/lib/kinds.ts
  5. 46
      src/lib/stores/PR.ts
  6. 65
      src/lib/stores/PRs.ts

24
src/lib/components/prs/Status.svelte

@ -1,7 +1,13 @@ @@ -1,7 +1,13 @@
<script lang="ts">
import {
proposal_status_applied,
proposal_status_closed,
proposal_status_draft,
proposal_status_open,
} from '$lib/kinds'
import { pr_icon_path } from './icons'
export let status: string | undefined = undefined
export let status: number | undefined = undefined
export let edit_mode = false
</script>
@ -11,13 +17,15 @@ @@ -11,13 +17,15 @@
<div
tabIndex={0}
role="button"
class:btn-success={status && status === 'Open'}
class:btn-primary={status && status === 'Merged'}
class:btn-neutral={!status || status === 'Draft' || status === 'Closed'}
class:btn-success={status && status === proposal_status_open}
class:btn-primary={status && status === proposal_status_applied}
class:btn-neutral={!status ||
status === proposal_status_draft ||
status === proposal_status_closed}
class:cursor-default={!edit_mode}
class="btn btn-success btn-sm align-middle"
>
{#if status === 'Open'}
{#if status === proposal_status_open}
<!-- http://icon-sets.iconify.design/octicon/git-pull-request-16/ -->
<svg
xmlns="http://www.w3.org/2000/svg"
@ -26,7 +34,7 @@ @@ -26,7 +34,7 @@
><path d={pr_icon_path.open} />
</svg>
Open
{:else if status === 'Merged'}
{:else if status === proposal_status_applied}
<!-- https://icon-sets.iconify.design/octicon/git-merge-16/ -->
<svg
xmlns="http://www.w3.org/2000/svg"
@ -35,7 +43,7 @@ @@ -35,7 +43,7 @@
><path d={pr_icon_path.merge} /></svg
>
Merged
{:else if status === 'Closed'}
{:else if status === proposal_status_closed}
<!-- https://icon-sets.iconify.design/octicon/git-pull-request-closed-16/ -->
<svg
xmlns="http://www.w3.org/2000/svg"
@ -44,7 +52,7 @@ @@ -44,7 +52,7 @@
><path d={pr_icon_path.close} /></svg
>
Closed
{:else if status === 'Draft'}
{:else if status === proposal_status_draft}
<!-- https://icon-sets.iconify.design/octicon/git-pull-request-draft-16// -->
<svg
xmlns="http://www.w3.org/2000/svg"

48
src/lib/components/prs/StatusSelector.svelte

@ -1,14 +1,19 @@ @@ -1,14 +1,19 @@
<script lang="ts">
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 @@ @@ -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 @@ @@ -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 @@ @@ -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}
<li class="pl-0">
<button
on:click={() => {
changeStatus('Draft')
changeStatus(proposal_status_draft)
}}
class="btn btn-neutral btn-sm mx-2 align-middle">Draft</button
class="btn btn-neutral btn-sm mx-2 align-middle"
>{statusKindtoText(proposal_status_draft)}</button
>
</li>
{/if}
{#if status !== 'Open'}
{#if status !== proposal_status_open}
<li class="pl-0">
<button
on:click={() => {
changeStatus('Open')
changeStatus(proposal_status_open)
}}
class="btn btn-success btn-sm mx-2 align-middle">Open</button
class="btn btn-success btn-sm mx-2 align-middle"
>{statusKindtoText(proposal_status_open)}</button
>
</li>
{/if}
{#if status !== 'Merged'}
{#if status !== proposal_status_applied}
<li class="pl-0">
<button
on:click={() => {
changeStatus('Merged')
changeStatus(proposal_status_applied)
}}
class="btn btn-primary btn-sm mx-2 align-middle">Merged</button
class="btn btn-primary btn-sm mx-2 align-middle"
>{statusKindtoText(proposal_status_applied)}</button
>
</li>
{/if}
{#if status !== 'Closed'}
{#if status !== proposal_status_closed}
<li class="pl-0">
<button
on:click={() => {
changeStatus('Closed')
changeStatus(proposal_status_closed)
}}
class="btn btn-neutral btn-sm mx-2 align-middle">Closed</button
class="btn btn-neutral btn-sm mx-2 align-middle"
>{statusKindtoText(proposal_status_closed)}</button
>
</li>
{/if}

15
src/lib/components/prs/type.ts

@ -9,7 +9,7 @@ export interface PRSummary { @@ -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 = { @@ -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

18
src/lib/kinds.ts

@ -1,6 +1,22 @@ @@ -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

46
src/lib/stores/PR.ts

@ -3,13 +3,8 @@ import { writable, type Unsubscriber, type Writable } from 'svelte/store' @@ -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) => { @@ -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) => { @@ -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,
}

65
src/lib/stores/PRs.ts

@ -6,12 +6,17 @@ import { @@ -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 { @@ -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 { @@ -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 { @@ -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.')
}

Loading…
Cancel
Save