Browse Source

feat(ListPRs): add wrapper

- add repo page
- add wrapper for for listPR component
master
DanConwayDev 2 years ago
parent
commit
c142375fd6
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 24
      __snapshots__/repo-summary-card.test.js.snap
  2. 42
      __snapshots__/repo-summary-list.test.js.snap
  3. 9
      src/lib/components/RepoSummaryCard.svelte
  4. 4
      src/lib/components/ReposSummaryList.svelte
  5. 2
      src/lib/stores/ndk.ts
  6. 38
      src/lib/wrappers/OpenPRs.svelte
  7. 5
      src/lib/wrappers/ReposRecent.svelte
  8. 8
      src/routes/repo/[repo_id]/+page.svelte
  9. 5
      src/routes/repo/[repo_id]/+page.ts

24
__snapshots__/repo-summary-card.test.js.snap

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Repo/Summary/Card Long Details test 1`] = `
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Long Name that goes on and on and on and on a...
@ -10,11 +12,13 @@ exports[`Repo/Summary/Card Long Details test 1`] = ` @@ -10,11 +12,13 @@ exports[`Repo/Summary/Card Long Details test 1`] = `
Lorem ipsum dolor sit amet, consectetur adipi...
</p>
</div>
</div>
</a>
`;
exports[`Repo/Summary/Card Long and No Spaces test 1`] = `
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
LongNameLongNameLongNameLongNameLongNameLongN...
@ -23,11 +27,13 @@ exports[`Repo/Summary/Card Long and No Spaces test 1`] = ` @@ -23,11 +27,13 @@ exports[`Repo/Summary/Card Long and No Spaces test 1`] = `
LoremipsumLoremipsumLoremipsumLoremipsumLorem...
</p>
</div>
</div>
</a>
`;
exports[`Repo/Summary/Card No Details test 1`] = `
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Untitled
@ -35,11 +41,13 @@ exports[`Repo/Summary/Card No Details test 1`] = ` @@ -35,11 +41,13 @@ exports[`Repo/Summary/Card No Details test 1`] = `
<p class="s-LKxYhcdFgLTA">
</p>
</div>
</div>
</a>
`;
exports[`Repo/Summary/Card Short Details test 1`] = `
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Short Name
@ -48,7 +56,7 @@ exports[`Repo/Summary/Card Short Details test 1`] = ` @@ -48,7 +56,7 @@ exports[`Repo/Summary/Card Short Details test 1`] = `
short description
</p>
</div>
</div>
</a>
`;
exports[`Repo/Summary/Card loading test 1`] = `

42
__snapshots__/repo-summary-list.test.js.snap

@ -7,7 +7,9 @@ exports[`Repo/Summary/List Default test 1`] = ` @@ -7,7 +7,9 @@ exports[`Repo/Summary/List Default test 1`] = `
Featured Repositories
</h3>
</div>
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Short Name
@ -16,8 +18,10 @@ exports[`Repo/Summary/List Default test 1`] = ` @@ -16,8 +18,10 @@ exports[`Repo/Summary/List Default test 1`] = `
short description
</p>
</div>
</div>
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
</a>
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Long Name that goes on and on and on and on a...
@ -26,8 +30,10 @@ exports[`Repo/Summary/List Default test 1`] = ` @@ -26,8 +30,10 @@ exports[`Repo/Summary/List Default test 1`] = `
Lorem ipsum dolor sit amet, consectetur adipi...
</p>
</div>
</div>
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
</a>
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
LongNameLongNameLongNameLongNameLongNameLongN...
@ -36,7 +42,7 @@ exports[`Repo/Summary/List Default test 1`] = ` @@ -36,7 +42,7 @@ exports[`Repo/Summary/List Default test 1`] = `
LoremipsumLoremipsumLoremipsumLoremipsumLorem...
</p>
</div>
</div>
</a>
</div>
`;
@ -89,7 +95,9 @@ exports[`Repo/Summary/List Loading test 1`] = ` @@ -89,7 +95,9 @@ exports[`Repo/Summary/List Loading test 1`] = `
exports[`Repo/Summary/List No Title test 1`] = `
<div class="space-y-5">
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Short Name
@ -98,8 +106,10 @@ exports[`Repo/Summary/List No Title test 1`] = ` @@ -98,8 +106,10 @@ exports[`Repo/Summary/List No Title test 1`] = `
short description
</p>
</div>
</div>
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
</a>
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Long Name that goes on and on and on and on a...
@ -108,7 +118,7 @@ exports[`Repo/Summary/List No Title test 1`] = ` @@ -108,7 +118,7 @@ exports[`Repo/Summary/List No Title test 1`] = `
Lorem ipsum dolor sit amet, consectetur adipi...
</p>
</div>
</div>
</a>
</div>
`;
@ -119,7 +129,9 @@ exports[`Repo/Summary/List Partially Loaded test 1`] = ` @@ -119,7 +129,9 @@ exports[`Repo/Summary/List Partially Loaded test 1`] = `
Latest
</h3>
</div>
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Short Name
@ -128,8 +140,10 @@ exports[`Repo/Summary/List Partially Loaded test 1`] = ` @@ -128,8 +140,10 @@ exports[`Repo/Summary/List Partially Loaded test 1`] = `
short description
</p>
</div>
</div>
<div class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA">
</a>
<a class="card w-96 bg-primary text-primary-content s-LKxYhcdFgLTA"
href="/repo/"
>
<div class="card-body s-LKxYhcdFgLTA">
<h2 class="card-title s-LKxYhcdFgLTA">
Long Name that goes on and on and on and on a...
@ -138,7 +152,7 @@ exports[`Repo/Summary/List Partially Loaded test 1`] = ` @@ -138,7 +152,7 @@ exports[`Repo/Summary/List Partially Loaded test 1`] = `
Lorem ipsum dolor sit amet, consectetur adipi...
</p>
</div>
</div>
</a>
<div class="card w-96 bg-neutral text-neutral-focus s-LKxYhcdFgLTA">
<div class="card-body s-LKxYhcdFgLTA">
<div class="text-center s-LKxYhcdFgLTA">

9
src/lib/components/RepoSummaryCard.svelte

@ -2,10 +2,12 @@ @@ -2,10 +2,12 @@
export interface Args {
name: string;
description: string;
repo_id: string;
loading?: boolean;
}
export const defaults: Args = {
name: "",
repo_id: "",
description: "",
loading: false,
};
@ -14,7 +16,7 @@ @@ -14,7 +16,7 @@
<script lang="ts">
import { slide } from "svelte/transition";
export let { name, description, loading } = defaults;
export let { name, description, repo_id: repo_id, loading } = defaults;
let short_name: string;
$: {
if (name.length > 45) short_name = name.slice(0, 45) + "...";
@ -37,15 +39,16 @@ @@ -37,15 +39,16 @@
</div>
</div>
{:else}
<div
<a
transition:slide={{ duration: 50 }}
class="card w-96 bg-primary text-primary-content"
href="/repo/{repo_id}"
>
<div class="card-body">
<h2 class="card-title">{short_name}</h2>
<p>{short_descrption}</p>
</div>
</div>
</a>
{/if}
<style>

4
src/lib/components/ReposSummaryList.svelte

@ -20,8 +20,8 @@ @@ -20,8 +20,8 @@
{#if repos.length == 0 && !loading}
<p class="prose">None</p>
{/if}
{#each repos as { name, description }}
<RepoSummaryCard {name} {description} />
{#each repos as { name, description, repo_id }}
<RepoSummaryCard {name} {description} {repo_id} />
{/each}
{#if loading}
<RepoSummaryCard loading={true} />

2
src/lib/stores/ndk.ts

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
import NDKSvelte from '@nostr-dev-kit/ndk-svelte';
export const ndk = new NDKSvelte({
explicitRelayUrls: ['ws://localhost:8080'],
explicitRelayUrls: ['ws://localhost:8055'],
});
ndk.connect();

38
src/lib/wrappers/OpenPRs.svelte

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
<script lang="ts">
import PRsList from "$lib/components/PRsList.svelte";
import type { Args } from "$lib/components/PRsListItem.svelte";
import { ndk } from "$lib/stores/ndk";
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;
});
</script>
<PRsList title="Open PRs" {prs} {loading} />

5
src/lib/wrappers/ReposRecent.svelte

@ -7,21 +7,24 @@ @@ -7,21 +7,24 @@
let repos: Args[] = [];
let loading: boolean = true;
let kind: number = 30017;
let kind: number = 30317;
let sub = ndk.subscribe({
kinds: [kind],
limit,
});
sub.on("event", (event) => {
if (repos.length < limit) {
try {
if (event.kind == kind)
repos = [
...repos,
{
name: event.tagValue("name") || "",
description: event.tagValue("description") || "",
repo_id: event.replaceableDTag(),
},
];
} catch {}
} else if (loading == true) loading = false;
});
sub.on("eose", () => {

8
src/routes/repo/[repo_id]/+page.svelte

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
<script lang="ts">
import OpenPRs from "$lib/wrappers/OpenPRs.svelte";
export let data: { repo_id: string };
let repo_id = data.repo_id;
</script>
<OpenPRs {repo_id} />

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

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
export const load = ({ params }) => {
return {
repo_id: params.repo_id,
}
}
Loading…
Cancel
Save