Browse Source

feat(repo): add clone btn

which links to downloads and shows nostr clone url
master
DanConwayDev 2 years ago
parent
commit
ad4f4dbccc
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 15
      src/lib/components/InstallNgit.svelte
  2. 110
      src/lib/components/repo/RepoDetails.svelte

15
src/lib/components/InstallNgit.svelte

@ -1,4 +1,8 @@
<div class="prose"> <script lang="ts">
export let size: 'sm' | 'md' = 'md'
</script>
<div class="prose" class:text-sm={size === 'sm'}>
<p> <p>
download binaries and add them to a directory from which they can be run download binaries and add them to a directory from which they can be run
globally: globally:
@ -6,15 +10,18 @@
<p> <p>
<a <a
href="https://github.com/DanConwayDev/ngit-cli/releases/download/v1.3.1/ngit-x86_64-unknown-linux-gnu.tar.gz" href="https://github.com/DanConwayDev/ngit-cli/releases/download/v1.3.1/ngit-x86_64-unknown-linux-gnu.tar.gz"
class="btn btn-neutral">Linux</a class="btn btn-neutral"
class:btn-sm={size === 'sm'}>Linux</a
> >
<a <a
href="https://github.com/DanConwayDev/ngit-cli/releases/download/v1.3.1/ngit-x86_64-apple-darwin.tar.gz" href="https://github.com/DanConwayDev/ngit-cli/releases/download/v1.3.1/ngit-x86_64-apple-darwin.tar.gz"
class="btn btn-neutral">Mac</a class="btn btn-neutral"
class:btn-sm={size === 'sm'}>Mac</a
> >
<a <a
href="https://github.com/DanConwayDev/ngit-cli/releases/download/v1.3.1/ngit-x86_64-pc-windows-msvc.zip" href="https://github.com/DanConwayDev/ngit-cli/releases/download/v1.3.1/ngit-x86_64-pc-windows-msvc.zip"
class="btn btn-neutral">Windows</a class="btn btn-neutral"
class:btn-sm={size === 'sm'}>Windows</a
> >
v1.3.1 v1.3.1
</p> </p>

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

@ -1,7 +1,9 @@
<script lang="ts"> <script lang="ts">
import UserHeader from '$lib/components/users/UserHeader.svelte' import UserHeader from '$lib/components/users/UserHeader.svelte'
import { nip19 } from 'nostr-tools'
import AlertWarning from '../AlertWarning.svelte' import AlertWarning from '../AlertWarning.svelte'
import { icons_misc } from '../icons' import { icons_misc } from '../icons'
import InstallNgit from '../InstallNgit.svelte'
import { event_defaults } from './type' import { event_defaults } from './type'
export let { export let {
@ -27,14 +29,105 @@
? description.slice(0, 450) + '...' ? description.slice(0, 450) + '...'
: description : description
let naddr_copied = false let naddr_copied = false
const create_nostr_url = (
maintainers: string[],
identifier: string,
relays: string[]
) => {
if (identifier.length > 0 && maintainers.length > 0) {
let npub = nip19.npubEncode(maintainers[0])
if (relays.length > 0) {
let relay = relays[0]
if (/^[a-zA-Z0-9.]+$/.test(relay.replace('wss://', ''))) {
return `nostr://${npub}/${identifier}?relayhint=${relay.replace('wss://', '')}`
}
return `nostr://${npub}/${identifier}?relayhint=${encodeURIComponent(relay)}`
}
return `nostr://${npub}/${identifier}`
}
return ''
}
$: nostr_url = create_nostr_url(maintainers, identifier, relays)
let nostr_url_copied = false
let git_url_copied: false | string = false let git_url_copied: false | string = false
let maintainer_copied: false | string = false let maintainer_copied: false | string = false
$: event_not_found = !loading && created_at == 0 $: event_not_found = !loading && created_at == 0
</script> </script>
<div class="prose w-full max-w-md"> <div class="prose w-full max-w-md">
{#if !loading}
<div class="clearfix">
<div class="dropdown dropdown-end float-right">
<div tabIndex={0} class="btn btn-success btn-sm text-base-400">
clone
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
class="h-5 w-5 flex-none fill-success-content"
><path
fill="currentColor"
d="M11.646 15.146L5.854 9.354a.5.5 0 0 1 .353-.854h11.586a.5.5 0 0 1 .353.854l-5.793 5.792a.5.5 0 0 1-.707 0"
/></svg
>
</div>
<ul
tabIndex={0}
class="w-md menu dropdown-content z-[1] ml-0 rounded-box bg-base-300 p-2 shadow"
>
<li class="prose">
<div>
<div>
<h4 class="mt-0">1. install ngit and git-remote-nostr</h4>
<InstallNgit size="sm" />
</div>
</div>
</li>
<li class="m-0 p-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(nostr_url)
nostr_url_copied = true
setTimeout(() => {
nostr_url_copied = false
}, 2000)
} catch {}
}}
class="group cursor-pointer rounded-md"
>
<div>
<h4 class="mt-0 pt-0">
2. copy gitclone url
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
class="ml-1 inline h-4 w-4 flex-none fill-base-content opacity-50 group-hover:opacity-100"
class:fill-base-content={!nostr_url_copied}
class:fill-success={nostr_url_copied}
>
{#each icons_misc.copy as d}
<path {d} />
{/each}
</svg>
{#if nostr_url_copied}<span
class="text-sm text-success opacity-50"
>
(copied to clipboard)</span
>{/if}
</h4>
<p class="my-2 break-words border p-2 text-xs">{nostr_url}</p>
</div>
</div>
</li>
</ul>
</div>
</div>
{/if}
{#if event_not_found} {#if event_not_found}
<h4>identifier</h4> <h4 class="mt-0 pt-1">identifier</h4>
<p class="my-2 break-words text-sm">{identifier}</p> <p class="my-2 break-words text-sm">{identifier}</p>
{:else} {:else}
{#if name == identifier} {#if name == identifier}
@ -43,10 +136,10 @@
<div class="skeleton my-2 h-4"></div> <div class="skeleton my-2 h-4"></div>
<div class="skeleton my-2 mb-3 h-4 w-2/3"></div> <div class="skeleton my-2 mb-3 h-4 w-2/3"></div>
{:else if !name || name.length == 0} {:else if !name || name.length == 0}
<h4>name / identifier</h4> <h4 class="mt-0 pt-1">name / identifier</h4>
<div>none</div> <div>none</div>
{:else} {:else}
<h4>name / identifier</h4> <h4 class="mt-0 pt-1">name / identifier</h4>
<p class="my-2 break-words text-sm">{name}</p> <p class="my-2 break-words text-sm">{name}</p>
{/if} {/if}
{:else} {:else}
@ -102,7 +195,9 @@
<div /> <div />
{:else} {:else}
<h4> <h4>
clone {#if git_url_copied}<span class="text-sm text-success opacity-50"> git servers {#if git_url_copied}<span
class="text-sm text-success opacity-50"
>
(copied to clipboard)</span (copied to clipboard)</span
>{/if} >{/if}
</h4> </h4>
@ -173,9 +268,8 @@
<div /> <div />
{:else} {:else}
<h4> <h4>
{#if event_not_found}author{:else}maintainers{/if} {#if maintainer_copied}<span {#if event_not_found}author{:else}maintainers{/if}
class="text-sm text-success opacity-50" {#if maintainer_copied}<span class="text-sm text-success opacity-50">
>
(copied to clipboard)</span (copied to clipboard)</span
>{/if} >{/if}
</h4> </h4>
@ -260,7 +354,7 @@
{#if event_not_found} {#if event_not_found}
<div class="text-xs"> <div class="text-xs">
<AlertWarning> <AlertWarning>
<div class="font-semibold pb-1">missing repository details</div> <div class="pb-1 font-semibold">missing repository details</div>
<div>cannot find referenced repository event</div> <div>cannot find referenced repository event</div>
</AlertWarning> </AlertWarning>
</div> </div>

Loading…
Cancel
Save