Add Download radio button to Clone popover

This commit is contained in:
Sebastian Martinez
2025-04-25 13:06:35 +02:00
parent 775cbd1c37
commit 8d1624e0da
6 changed files with 91 additions and 13 deletions
+36 -8
View File
@@ -14,8 +14,10 @@
export let baseUrl: BaseUrl;
export let id: string;
export let name: string;
export let currentRefname: string;
export let enabledArchiveDownload: boolean;
let radicle: boolean = true;
let activeTab: "radicle" | "git" | "archive" = "radicle";
$: radCloneUrl = `rad clone ${id}`;
$: portFragment =
@@ -23,6 +25,7 @@
baseUrl.port === config.nodes.defaultHttpdPort
? ""
: `:${baseUrl.port}`;
$: archiveUrl = `curl -OJ ${baseUrl.scheme}://${baseUrl.hostname}${portFragment}/raw/${id}/archive/${currentRefname}`;
$: gitCloneUrl = `git clone ${baseUrl.scheme}://${
baseUrl.hostname
}${portFragment}/${parseRepositoryId(id)?.pubkey ?? id}.git ${name}`;
@@ -47,13 +50,13 @@
<div slot="popover" style:width="24rem" class="popover">
<div style:margin-bottom="1.5rem">
<Radio ariaLabel="Toggle render method">
<Radio ariaLabel="Toggle render method" styleGap="2px">
<Button
styleWidth="100%"
styleBorderRadius="0"
variant={radicle ? "selected" : "not-selected"}
variant={activeTab === "radicle" ? "selected" : "not-selected"}
on:click={() => {
radicle = true;
activeTab = "radicle";
}}>
<Icon name="logo" />
Radicle
@@ -62,24 +65,37 @@
<Button
styleWidth="100%"
styleBorderRadius="0"
variant={!radicle ? "selected" : "not-selected"}
variant={activeTab === "git" ? "selected" : "not-selected"}
on:click={() => {
radicle = false;
activeTab = "git";
}}>
<Icon name="git" />
Git
</Button>
{#if enabledArchiveDownload}
<div class="global-spacer"></div>
<Button
styleWidth="100%"
styleBorderRadius="0"
variant={activeTab === "archive" ? "selected" : "not-selected"}
on:click={() => {
activeTab = "archive";
}}>
<Icon name="archive" />
Download
</Button>
{/if}
</Radio>
</div>
{#if radicle}
{#if activeTab === "radicle"}
<label for="rad-clone-url">
Use the <ExternalLink href="https://radicle.xyz">
Radicle CLI
</ExternalLink> to clone this repository.
</label>
<Command command={radCloneUrl} />
{:else}
{:else if activeTab === "git"}
<div>
<label for="git-clone-url">
If you don't have Radicle installed, you can still clone the
@@ -91,6 +107,18 @@
such as issues or patches.
</div>
</div>
{:else if activeTab === "archive"}
<div>
<label for="git-clone-url">
If you don't have Radicle installed, you can still download an archive
of the repository.
</label>
<Command command={archiveUrl} />
<div style:margin-top="1.5rem">
Note that a compressed archive of the source code does not include any
of the social artifacts such as issues or patches nor the git history.
</div>
</div>
{/if}
</div>
</Popover>
+9 -2
View File
@@ -11,7 +11,7 @@
import config from "@app/lib/config";
import { HttpdClient } from "@http-client";
import { baseUrlToString } from "@app/lib/utils";
import { baseUrlToString, formatQualifiedRefname } from "@app/lib/utils";
import { groupCommits } from "@app/lib/commit";
import Button from "@app/components/Button.svelte";
@@ -104,7 +104,14 @@
Commits
</Link>
</svelte:fragment>
<RepoNameHeader {repo} {baseUrl} slot="header" />
<RepoNameHeader
{repo}
currentRefname={formatQualifiedRefname(
revision || repo.payloads["xyz.radicle.project"].data.defaultBranch,
peer,
)}
{baseUrl}
slot="header" />
<div style:margin="1rem" slot="subheader">
<Header
+9 -1
View File
@@ -20,6 +20,7 @@
import RepoNameHeader from "./Source/RepoNameHeader.svelte";
import Separator from "./Separator.svelte";
import TreeComponent from "./Source/Tree.svelte";
import { formatQualifiedRefname } from "@app/lib/utils";
export let baseUrl: BaseUrl;
export let blobResult: BlobResult;
@@ -130,7 +131,14 @@
<FilePath filenameWithPath={path} />
{/if}
</svelte:fragment>
<RepoNameHeader {repo} {baseUrl} slot="header" />
<RepoNameHeader
{repo}
currentRefname={formatQualifiedRefname(
revision || repo.payloads["xyz.radicle.project"].data.defaultBranch,
peer,
)}
{baseUrl}
slot="header" />
<div style:margin="1rem" slot="subheader">
<Header
+19 -2
View File
@@ -3,7 +3,7 @@
import dompurify from "dompurify";
import { markdown } from "@app/lib/markdown";
import { twemoji } from "@app/lib/utils";
import { baseUrlToString, twemoji } from "@app/lib/utils";
import Badge from "@app/components/Badge.svelte";
import CloneButton from "@app/views/repos/Header/CloneButton.svelte";
@@ -15,6 +15,18 @@
export let repo: Repo;
export let baseUrl: BaseUrl;
export let currentRefname: string;
let enabledArchiveDownload = false;
void fetch(
`${baseUrlToString(baseUrl)}/raw/${repo.rid}/archive/${currentRefname}`,
{
method: "HEAD",
},
).then(response => {
enabledArchiveDownload = response.ok;
});
function render(content: string): string {
return dompurify.sanitize(
@@ -89,7 +101,12 @@
style:display="flex"
style:gap="0.5rem"
class="global-hide-on-mobile-down">
<CloneButton {baseUrl} id={repo.rid} name={project.data.name} />
<CloneButton
{enabledArchiveDownload}
{baseUrl}
{currentRefname}
id={repo.rid}
name={project.data.name} />
<SeedButton seedCount={repo.seeding} repoId={repo.rid} />
</div>
<div