Browse Source

feat(repo-details): add unique commit and naddr

and copy naddr on click
master
DanConwayDev 2 years ago
parent
commit
99bda4b57a
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 39
      src/lib/components/repo/RepoDetails.svelte
  2. 2
      src/lib/components/repo/type.ts
  3. 1
      src/lib/components/repo/vectors.ts
  4. 1
      src/lib/stores/repos.ts

39
src/lib/components/repo/RepoDetails.svelte

@ -4,6 +4,7 @@
export let { export let {
event_id, event_id,
naddr,
identifier, identifier,
unique_commit, unique_commit,
name, name,
@ -21,6 +22,7 @@
!description && description.length > 500 !description && description.length > 500
? description.slice(0, 450) + '...' ? description.slice(0, 450) + '...'
: description : description
let naddr_copied = false
</script> </script>
<div class="prose w-full max-w-md"> <div class="prose w-full max-w-md">
@ -149,4 +151,41 @@
{/each} {/each}
{/if} {/if}
</div> </div>
{#if loading}
<div class="skeleton my-3 h-5 w-20"></div>
<div class="skeleton my-2 h-4"></div>
<div class="skeleton my-2 mb-3 h-4 w-2/3"></div>
{:else if unique_commit && unique_commit.length > 0}
<h4>earliest unique commit</h4>
<p class="my-2 break-words text-xs">{unique_commit}</p>
{/if}
{#if loading}
<div class="skeleton my-3 h-5 w-20"></div>
<div class="skeleton my-2 h-4"></div>
<div class="skeleton my-2 mb-3 h-4 w-2/3"></div>
{:else if naddr && naddr.length > 0}
<!-- eslint-disable-next-line svelte/valid-compile -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
on:click={async () => {
try {
await navigator.clipboard.writeText(naddr)
naddr_copied = true
setTimeout(() => {
naddr_copied = false
}, 2000)
} catch {}
}}
>
<h4>
naddr
{#if naddr_copied}<span class="text-success opacity-50">
(copied)</span
>{/if}
</h4>
<p class="my-2 break-words text-xs">{naddr}</p>
</div>
{/if}
</div> </div>

2
src/lib/components/repo/type.ts

@ -2,6 +2,7 @@ import { defaults as user_defaults, type User } from '../users/type'
export interface RepoEvent { export interface RepoEvent {
event_id: string event_id: string
naddr: string
identifier: string identifier: string
unique_commit: string | undefined unique_commit: string | undefined
name: string name: string
@ -17,6 +18,7 @@ export interface RepoEvent {
} }
export const event_defaults: RepoEvent = { export const event_defaults: RepoEvent = {
event_id: '', event_id: '',
naddr: '',
identifier: '', identifier: '',
unique_commit: '', unique_commit: '',
name: '', name: '',

1
src/lib/components/repo/vectors.ts

@ -48,6 +48,7 @@ const base: RepoEvent = {
], ],
loading: false, loading: false,
event_id: '', event_id: '',
naddr: '',
web: ['https://gitworkshop.dev/repo/example', 'https://example.com'], web: ['https://gitworkshop.dev/repo/example', 'https://example.com'],
referenced_by: [], referenced_by: [],
created_at: 0, created_at: 0,

1
src/lib/stores/repos.ts

@ -253,6 +253,7 @@ export const eventToRepoEvent = (event: NDKEvent): RepoEvent | undefined => {
}) })
return { return {
event_id: event.id, event_id: event.id,
naddr: event.encode(),
identifier: event.replaceableDTag(), identifier: event.replaceableDTag(),
unique_commit: event.tagValue('r') || undefined, unique_commit: event.tagValue('r') || undefined,
name: event.tagValue('name') || '', name: event.tagValue('name') || '',

Loading…
Cancel
Save