explorer: Add open in app to a share menu

Copy link becomes a split button like desktop's, which can also copy the
ID or rad: URI, or open the URI in whichever app handles it. Commits and
releases get their own share button too.

Browsers don't tell us whether the app opened, so instead of redirecting
we show a notice linking to the desktop download page, unless the window
loses focus within a second.

Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Brandon Oxendine
2026-11-13 13:54:42 +01:00
committed by Rūdolfs Ošiņš
co-authored by Rūdolfs Ošiņš
parent 65e102b965
commit efc6ae961f
9 changed files with 332 additions and 39 deletions
+17
View File
@@ -0,0 +1,17 @@
import storedWritable from "@app/lib/localStore";
import { z } from "zod";
const shareActionSchema = z.enum([
"openInApp",
"copyLink",
"copyId",
"copyUri",
]);
export type ShareAction = z.infer<typeof shareActionSchema>;
export const shareAction = storedWritable<ShareAction>(
"shareAction",
shareActionSchema,
"copyLink",
!window.localStorage,
);
+7 -1
View File
@@ -20,6 +20,7 @@
import Link from "@app/components/Link.svelte";
import Popover from "@app/components/Popover.svelte";
import Separator from "./Separator.svelte";
import Share from "./Share.svelte";
export let baseUrl: BaseUrl;
export let commit: Commit;
@@ -75,7 +76,7 @@
}
</style>
<Layout {node} {baseUrl} {repo} {repoId}>
<Layout {node} {baseUrl} {repo} {repoId} hideShare>
<svelte:fragment slot="breadcrumb">
<Separator />
<Link
@@ -110,6 +111,11 @@
<InlineTitle fontSize="heading-l" content={header.summary} />
{/if}
<div class="button-container">
<Share
rid={repo.rid}
resource="commit/{commit.commit.id}"
id={commit.commit.id}
idLabel="commit" />
<Link
route={{
resource: "repo.source",
+9 -21
View File
@@ -7,31 +7,25 @@
import type { BaseUrl, Repo } from "@http-client";
import type { RepoNode } from "./router";
import config from "@app/lib/config";
import debounce from "lodash/debounce";
import { routeToPath } from "@app/lib/router";
import { toClipboard } from "@app/lib/utils";
import Button from "@app/components/Button.svelte";
import Icon from "@app/components/Icon.svelte";
import Link from "@app/components/Link.svelte";
import SeedButton from "@app/views/repos/Header/SeedButton.svelte";
import Share from "@app/views/repos/Share.svelte";
export let baseUrl: BaseUrl;
export let activeTab: ActiveTab = undefined;
export let repo: Repo;
export let repoId: string;
export let node: RepoNode;
// Pages that share a specific resource render their own share button.
export let hideShare = false;
// Undefined when the node cannot count the releases.
$: releaseCount = repo.releaseCount;
let shareIcon: "link" | "checkmark" = "link";
const restoreIcon = debounce(() => {
shareIcon = "link";
}, 1000);
function tabRoute(): string {
if (activeTab === "issues") {
return routeToPath({
@@ -60,13 +54,6 @@
});
}
}
async function copyLink() {
const origin = new URL(config.nodes.fallbackPublicExplorer).origin;
await toClipboard(origin.concat(tabRoute()));
shareIcon = "checkmark";
restoreIcon();
}
</script>
<style>
@@ -198,11 +185,12 @@
<div class="spacer"></div>
<div class="actions">
{#if activeTab !== "issues" && activeTab !== "patches" && activeTab !== "releases"}
<Button variant="outline" size="regular" on:click={copyLink}>
<Icon name={shareIcon} />
<span class="global-hide-on-small-desktop-down">Copy link</span>
</Button>
{#if !hideShare && activeTab !== "issues" && activeTab !== "patches" && activeTab !== "releases"}
<Share
rid={repo.rid}
id={repo.rid}
idLabel="repository"
path={tabRoute()} />
{/if}
<slot name="actions" />
<SeedButton seedCount={repo.seeding} repoId={repo.rid} />
+7 -1
View File
@@ -166,7 +166,13 @@
<span style:color="var(--color-text-tertiary)">No title</span>
{/if}
</div>
<Share />
<div class="global-flex-item">
<Share
rid={repo.rid}
resource="cob/xyz.radicle.issue/{issue.id}"
id={issue.id}
idLabel="issue" />
</div>
</svelte:fragment>
<svelte:fragment slot="state">
{#if issue.state.status === "open"}
+2 -1
View File
@@ -25,6 +25,7 @@
export let repoId: string;
export let stylePaddingBottom: string = "2.5rem";
export let node: RepoNode;
export let hideShare = false;
$: route = $activeRouteStore;
$: project = repo.payloads["xyz.radicle.project"];
@@ -240,7 +241,7 @@
</div>
<div class="tab-bar">
<RepoHeader {activeTab} {baseUrl} {repo} {repoId} {node}>
<RepoHeader {activeTab} {baseUrl} {repo} {repoId} {node} {hideShare}>
<svelte:fragment slot="actions">
<slot name="actions" />
</svelte:fragment>
+5 -1
View File
@@ -380,7 +380,11 @@
<span style:color="var(--color-text-tertiary)">No title</span>
{/if}
<div class="global-flex-item">
<Share />
<Share
rid={repo.rid}
resource="cob/xyz.radicle.patch/{patch.id}"
id={patch.id}
idLabel="patch" />
<div class="global-hide-on-mobile-down">
<CheckoutButton id={patch.id} />
</div>
+8
View File
@@ -28,6 +28,7 @@
import Link from "@app/components/Link.svelte";
import NodeId from "@app/components/NodeId.svelte";
import Separator from "./Separator.svelte";
import Share from "./Share.svelte";
import UntrustedWarning from "./Release/UntrustedWarning.svelte";
export let baseUrl: BaseUrl;
@@ -392,6 +393,13 @@
<Icon name="parcel" />
<InlineTitle fontSize="heading-l" content={title} />
</div>
<div class="global-flex-item">
<Share
rid={repo.rid}
resource="cob/dev.radicle.artifact/{release.id}"
id={release.id}
idLabel="release" />
</div>
</svelte:fragment>
<svelte:fragment slot="state">
{#if release.tagName}
+266 -14
View File
@@ -1,28 +1,280 @@
<script lang="ts">
import type { ComponentProps } from "svelte";
import type { ShareAction } from "@app/lib/shareAction";
import config from "@app/lib/config";
import debounce from "lodash/debounce";
import { onDestroy } from "svelte";
import { shareAction } from "@app/lib/shareAction";
import { toClipboard } from "@app/lib/utils";
import Button from "@app/components/Button.svelte";
import DropdownList from "@app/components/DropdownList.svelte";
import DropdownListItem from "@app/components/DropdownList/DropdownListItem.svelte";
import Icon from "@app/components/Icon.svelte";
import IconButton from "@app/components/IconButton.svelte";
import Link from "@app/components/Link.svelte";
import Popover, { closeFocused } from "@app/components/Popover.svelte";
let shareIcon: "link" | "checkmark" = "link";
// Canonical RID, never the URL's alias segment. It and `id` come from the
// seed, so they are validated before we navigate to or copy them.
export let rid: string;
export let resource: string | undefined = undefined;
export let id: string;
export let idLabel: string;
export let path: string | undefined = undefined;
const restoreIcon = debounce(() => {
shareIcon = "link";
const origin = new URL(config.nodes.fallbackPublicExplorer).origin;
const host = new URL(origin).host;
// Same grammar as desktop's `radUri.ts`.
const ridPattern = /^rad:z[1-9A-HJ-NP-Za-km-z]{27,28}$/;
const oidPattern = /^[0-9a-f]{40}$/;
const resourcePattern = /^(commit|cob\/[a-z0-9.]+)\/[0-9a-f]{40}$/;
$: uri = resource ? `${rid}/${resource}` : rid;
$: validUri =
ridPattern.test(rid) &&
(resource === undefined || resourcePattern.test(resource));
$: validId = ridPattern.test(id) || oidPattern.test(id);
$: actions = (
[
{
kind: "openInApp",
icon: "device",
label: "Open in app",
title: "Open in app",
tooltip: uri,
},
{
kind: "copyLink",
icon: "link",
label: "Copy link",
title: `Copy link to ${host}`,
tooltip: undefined,
},
{
kind: "copyId",
icon: "copy",
label: "Copy ID",
title: `Copy ${idLabel} ID`,
tooltip: undefined,
},
{
kind: "copyUri",
icon: "copy",
label: "Copy URI",
title: "Copy rad: URI",
tooltip: uri,
},
] satisfies {
kind: ShareAction;
icon: ComponentProps<Icon>["name"];
label: string;
title: string;
tooltip: string | undefined;
}[]
).filter(a => {
if (a.kind === "openInApp") return validUri;
if (a.kind === "copyId") return validId;
// Without a resource the URI is just the RID, i.e. the same as Copy ID.
if (a.kind === "copyUri") return validUri && resource !== undefined;
return true;
});
$: selected =
actions.find(a => a.kind === $shareAction) ??
actions.find(a => a.kind === "copyLink") ??
actions[0];
let copied = false;
const restore = debounce(() => {
copied = false;
}, 1000);
async function copy() {
const text = new URL(config.nodes.fallbackPublicExplorer).origin.concat(
window.location.pathname,
);
await toClipboard(text);
shareIcon = "checkmark";
restoreIcon();
let notice = false;
let container: HTMLDivElement;
let pendingNotice: ReturnType<typeof setTimeout> | undefined = undefined;
function hideNotice() {
clearTimeout(pendingNotice);
pendingNotice = undefined;
notice = false;
}
function onLeave() {
if (pendingNotice !== undefined) hideNotice();
}
function reset() {
hideNotice();
restore.cancel();
copied = false;
}
// The same instance is reused when navigating between resources.
// Passing `uri` makes the statement rerun when it changes.
$: resetFor(uri);
function resetFor(_uri: string) {
reset();
}
function openInApp() {
hideNotice();
if (!validUri) return;
// Start the timer first: some browsers throw on an unknown scheme, and
// then the notice is exactly what we want to show.
pendingNotice = setTimeout(() => {
pendingNotice = undefined;
notice = document.hasFocus();
}, 1000);
try {
window.location.assign(uri);
} catch {
// Handled by the notice.
}
}
onDestroy(reset);
function dismissOutside(event: MouseEvent | TouchEvent) {
if (!event.composedPath().includes(container)) hideNotice();
}
async function run(kind: ShareAction) {
if (kind === "openInApp") {
openInApp();
return;
}
hideNotice();
try {
await toClipboard(
kind === "copyLink"
? origin.concat(path ?? window.location.pathname)
: kind === "copyUri"
? uri
: id,
);
} catch {
return;
}
copied = true;
restore();
}
</script>
<Button variant="outline" size="regular" on:click={copy}>
<Icon name={shareIcon} />
<span class="global-hide-on-small-desktop-down">Copy link</span>
</Button>
<style>
.split {
display: inline-flex;
position: relative;
}
.notice {
position: absolute;
top: 2.5rem;
right: 0;
z-index: 10;
display: flex;
align-items: flex-start;
gap: 0.5rem;
width: max-content;
max-width: 18rem;
padding: 0.75rem;
background: var(--color-surface-canvas);
border: 1px solid var(--color-border-subtle);
border-radius: var(--border-radius-md);
box-shadow: var(--elevation-low);
font: var(--txt-body-m-regular);
}
.notice-text {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.25rem;
}
.notice-link {
text-decoration: underline;
}
.toggle {
margin-left: -1px;
}
</style>
<svelte:document on:visibilitychange={onLeave} />
<svelte:window
on:blur={onLeave}
on:click={dismissOutside}
on:touchstart={dismissOutside}
on:keydown={event => {
if (event.key === "Escape") hideNotice();
}} />
<div class="split" bind:this={container}>
<Button
variant="outline"
title={selected.tooltip ?? selected.title}
styleBorderRadius="var(--border-radius-sm) 0 0 var(--border-radius-sm)"
on:click={() => run(selected.kind)}>
<Icon
name={copied && selected.kind !== "openInApp"
? "checkmark"
: selected.icon} />
<span class="global-hide-on-small-desktop-down">{selected.label}</span>
</Button>
<div class="toggle">
<Popover
popoverPadding="0"
popoverPositionTop="2.5rem"
popoverPositionRight="0">
<Button
slot="toggle"
let:expanded
let:toggle
variant="outline"
title="Share options"
ariaLabel="Share options"
stylePadding="0 0.5rem"
styleBorderRadius="0 var(--border-radius-sm) var(--border-radius-sm) 0"
on:click={() => {
hideNotice();
toggle();
}}>
<Icon name={expanded ? "chevron-up" : "chevron-down"} />
</Button>
<DropdownList slot="popover" items={actions}>
<DropdownListItem
slot="item"
let:item
selected={item.kind === selected.kind}
title={item.tooltip}
on:click={() => {
$shareAction = item.kind;
closeFocused();
void run(item.kind);
}}>
<Icon name={item.icon} />
{item.title}
</DropdownListItem>
</DropdownList>
</Popover>
</div>
{#if notice}
<div class="notice" role="status">
<div class="notice-text">
<span>Opening in app. Didn't open?</span>
<Link
route={{ resource: "desktop", params: undefined }}
on:afterNavigate={() => (notice = false)}>
<span class="notice-link">Get Radicle Desktop</span>
</Link>
</div>
<IconButton ariaLabel="Dismiss" on:click={() => (notice = false)}>
<Icon name="close" />
</IconButton>
</div>
{/if}
</div>
+11
View File
@@ -6,3 +6,14 @@ test("navigate single issue", async ({ page }) => {
await expect(page).toHaveURL(/\/issues\/[0-9a-f]{40}/);
});
test("open in app offers the download page", async ({ page }) => {
await page.goto(`${cobUrl}/issues`);
await page.getByText("This title has **markdown**").click();
await page.getByRole("button", { name: "Share options" }).click();
await page.getByText("Open in app").click();
await expect(page.getByRole("status")).toContainText("Didn't open?");
await page.getByRole("link", { name: "Get Radicle Desktop" }).click();
await expect(page).toHaveURL(/\/desktop$/);
});