diff --git a/__snapshots__/navbar--default.png b/__snapshots__/navbar--default.png index 640fa06..bbd86c5 100644 Binary files a/__snapshots__/navbar--default.png and b/__snapshots__/navbar--default.png differ diff --git a/__snapshots__/prs-list-item--author-loading.png b/__snapshots__/prs-list-item--author-loading.png new file mode 100644 index 0000000..467eedd Binary files /dev/null and b/__snapshots__/prs-list-item--author-loading.png differ diff --git a/__snapshots__/prs-list-item--long-and-no-spaces.png b/__snapshots__/prs-list-item--long-and-no-spaces.png index ac2ce81..b70b00c 100644 Binary files a/__snapshots__/prs-list-item--long-and-no-spaces.png and b/__snapshots__/prs-list-item--long-and-no-spaces.png differ diff --git a/__snapshots__/prs-list-item--long-details.png b/__snapshots__/prs-list-item--long-details.png index d704a66..f538eeb 100644 Binary files a/__snapshots__/prs-list-item--long-details.png and b/__snapshots__/prs-list-item--long-details.png differ diff --git a/__snapshots__/prs-list-item--short-details.png b/__snapshots__/prs-list-item--short-details.png index 54a389d..d9f3928 100644 Binary files a/__snapshots__/prs-list-item--short-details.png and b/__snapshots__/prs-list-item--short-details.png differ diff --git a/__snapshots__/prs-list-item.test.js.snap b/__snapshots__/prs-list-item.test.js.snap index 0ae0477..31ed730 100644 --- a/__snapshots__/prs-list-item.test.js.snap +++ b/__snapshots__/prs-list-item.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PRs/List/Item Long Details smoke-test 1`] = ` +exports[`PRs/List/Item Author Loading smoke-test 1`] = `
  • - rather long title that goes on and on and on and on and on and on... + short title
  • `; -exports[`PRs/List/Item Long and No Spaces smoke-test 1`] = ` +exports[`PRs/List/Item Long Details smoke-test 1`] = `
  • - LongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameL... + rather long title that goes on and on and on and on and on and on...
  • `; -exports[`PRs/List/Item No Details smoke-test 1`] = ` +exports[`PRs/List/Item Long and No Spaces smoke-test 1`] = `
  • - Untitled + LongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameL...
    @@ -112,7 +124,7 @@ exports[`PRs/List/Item Short Details smoke-test 1`] = ` opened 7 days ago
  • - fred + DanConwayDev
  • diff --git a/__snapshots__/prs-list-list--default.png b/__snapshots__/prs-list-list--default.png index 5a95a2b..c61bbef 100644 Binary files a/__snapshots__/prs-list-list--default.png and b/__snapshots__/prs-list-list--default.png differ diff --git a/__snapshots__/prs-list-list--no-title.png b/__snapshots__/prs-list-list--no-title.png index ee1c272..321fff7 100644 Binary files a/__snapshots__/prs-list-list--no-title.png and b/__snapshots__/prs-list-list--no-title.png differ diff --git a/__snapshots__/prs-list-list--partially-loaded.png b/__snapshots__/prs-list-list--partially-loaded.png index 3c3273b..88b9ef8 100644 Binary files a/__snapshots__/prs-list-list--partially-loaded.png and b/__snapshots__/prs-list-list--partially-loaded.png differ diff --git a/__snapshots__/prs-list-list.test.js.snap b/__snapshots__/prs-list-list.test.js.snap index 6239f42..b2f2ab3 100644 --- a/__snapshots__/prs-list-list.test.js.snap +++ b/__snapshots__/prs-list-list.test.js.snap @@ -35,7 +35,7 @@ exports[`PRs/List/List Default smoke-test 1`] = ` opened 7 days ago
  • - fred + DanConwayDev
  • @@ -57,7 +57,7 @@ exports[`PRs/List/List Default smoke-test 1`] = ` opened a minute ago
  • - carole + DanConwayDev
  • @@ -89,7 +89,7 @@ exports[`PRs/List/List Default smoke-test 1`] = ` opened 3 months ago
  • - steve + DanConwayDev
  • @@ -185,7 +185,7 @@ exports[`PRs/List/List No Title smoke-test 1`] = ` opened 7 days ago
  • - fred + DanConwayDev
  • @@ -207,7 +207,7 @@ exports[`PRs/List/List No Title smoke-test 1`] = ` opened a minute ago
  • - carole + DanConwayDev
  • @@ -251,7 +251,7 @@ exports[`PRs/List/List Partially Loaded smoke-test 1`] = ` opened 7 days ago
  • - fred + DanConwayDev
  • @@ -273,7 +273,7 @@ exports[`PRs/List/List Partially Loaded smoke-test 1`] = ` opened a minute ago
  • - carole + DanConwayDev
  • diff --git a/__snapshots__/repo-summary-list--default.png b/__snapshots__/repo-summary-list--default.png index 6f67520..cb26bc0 100644 Binary files a/__snapshots__/repo-summary-list--default.png and b/__snapshots__/repo-summary-list--default.png differ diff --git a/src/lib/components/PRsList.stories.svelte b/src/lib/components/prs/PRsList.stories.svelte similarity index 93% rename from src/lib/components/PRsList.stories.svelte rename to src/lib/components/prs/PRsList.stories.svelte index 0d2c2a2..6c4a300 100644 --- a/src/lib/components/PRsList.stories.svelte +++ b/src/lib/components/prs/PRsList.stories.svelte @@ -2,7 +2,7 @@ import type { Meta } from "@storybook/svelte"; import PRsList from "./PRsList.svelte"; import { Story, Template } from "@storybook/addon-svelte-csf"; - import { PRsListItemArgsVectors as vectors } from "./PR.vectors"; + import { PRsListItemArgsVectors as vectors } from "./vectors"; export const meta: Meta = { title: "PRs/List/List", diff --git a/src/lib/components/PRsList.svelte b/src/lib/components/prs/PRsList.svelte similarity index 70% rename from src/lib/components/PRsList.svelte rename to src/lib/components/prs/PRsList.svelte index b73829e..75f82d4 100644 --- a/src/lib/components/PRsList.svelte +++ b/src/lib/components/prs/PRsList.svelte @@ -2,12 +2,11 @@ import { fade } from "svelte/transition"; import { onMount } from "svelte"; - import PRsListItem, { - type Args as PRsListItemArgs, - } from "$lib/components/PRsListItem.svelte"; + import PRsListItem from "$lib/components/prs/PRsListItem.svelte"; + import type { PRSummary } from "./type"; export let title: string = ""; - export let prs: PRsListItemArgs[] = []; + export let prs: PRSummary[] = []; export let loading: boolean = false; @@ -21,8 +20,8 @@

    None

    {/if} {/if} diff --git a/src/lib/components/prs/type.ts b/src/lib/components/prs/type.ts new file mode 100644 index 0000000..71a890e --- /dev/null +++ b/src/lib/components/prs/type.ts @@ -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, +}; diff --git a/src/lib/components/PR.vectors.ts b/src/lib/components/prs/vectors.ts similarity index 56% rename from src/lib/components/PR.vectors.ts rename to src/lib/components/prs/vectors.ts index 9550e35..5927efb 100644 --- a/src/lib/components/PR.vectors.ts +++ b/src/lib/components/prs/vectors.ts @@ -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, -}; \ No newline at end of file + 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, +}; diff --git a/src/lib/components/users/type.ts b/src/lib/components/users/type.ts index ec27087..d9d9286 100644 --- a/src/lib/components/users/type.ts +++ b/src/lib/components/users/type.ts @@ -7,6 +7,12 @@ export interface User { profile?: NDKUserProfile; } +export let defaults: User = { + loading: true, + hexpubkey: "", + npub: "", +} + export function getName(user: User, fallback_to_pubkey: boolean = false): string { return user.profile ? ( user.profile.name diff --git a/src/lib/stores/PRs.ts b/src/lib/stores/PRs.ts new file mode 100644 index 0000000..a3be9c8 --- /dev/null +++ b/src/lib/stores/PRs.ts @@ -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 = 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, + }; + }); + }); +} diff --git a/src/lib/wrappers/OpenPRs.svelte b/src/lib/wrappers/OpenPRs.svelte index 2c013d3..ed6101d 100644 --- a/src/lib/wrappers/OpenPRs.svelte +++ b/src/lib/wrappers/OpenPRs.svelte @@ -1,38 +1,14 @@ - + diff --git a/src/routes/repo/[repo_id]/+page.svelte b/src/routes/repo/[repo_id]/+page.svelte index 3c0d9bc..d8621c2 100644 --- a/src/routes/repo/[repo_id]/+page.svelte +++ b/src/routes/repo/[repo_id]/+page.svelte @@ -9,12 +9,12 @@ ensureSelectedRepo(repo_id); -

    {$selected_repo.name}

    +

    {$selected_repo.name}

    -
    +
    -
    +