mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-11-16 08:30:43 +08:00
Allow seeding a missing repo from a reference
Following a link to a repo we don't have only led to the explorer, but the reason it's missing is usually that we haven't seeded it yet. A deep link that can't be opened now says so instead of doing nothing.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
|
||||
import { writeToClipboard } from "@app/lib/invoke";
|
||||
import { seedRepo } from "@app/lib/seedRepo";
|
||||
import { explorerHost } from "@app/lib/utils";
|
||||
|
||||
import ContextMenu from "@app/components/ContextMenu.svelte";
|
||||
@@ -35,33 +36,37 @@
|
||||
x: number;
|
||||
y: number;
|
||||
target: HTMLElement;
|
||||
url: string;
|
||||
url?: string;
|
||||
uri: string;
|
||||
/** A repo that isn't on this node, offered for seeding. */
|
||||
seedRid?: string;
|
||||
config: Config;
|
||||
onclose: () => void;
|
||||
}
|
||||
|
||||
const { x, y, target, url, uri, config, onclose }: Props = $props();
|
||||
const { x, y, target, url, uri, seedRid, config, onclose }: Props = $props();
|
||||
</script>
|
||||
|
||||
<ContextMenu {x} {y} {target} {onclose}>
|
||||
<a
|
||||
class="menu-item"
|
||||
role="menuitem"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener">
|
||||
<Icon name="open-external" />
|
||||
Open in {explorerHost(config)}
|
||||
</a>
|
||||
<button
|
||||
class="menu-item"
|
||||
role="menuitem"
|
||||
onclick={() => writeToClipboard(url)}>
|
||||
<Icon name="link" />
|
||||
Copy link to {explorerHost(config)}
|
||||
</button>
|
||||
<div class="menu-separator"></div>
|
||||
{#if url}
|
||||
<a
|
||||
class="menu-item"
|
||||
role="menuitem"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener">
|
||||
<Icon name="open-external" />
|
||||
Open in {explorerHost(config)}
|
||||
</a>
|
||||
<button
|
||||
class="menu-item"
|
||||
role="menuitem"
|
||||
onclick={() => writeToClipboard(url)}>
|
||||
<Icon name="link" />
|
||||
Copy link to {explorerHost(config)}
|
||||
</button>
|
||||
<div class="menu-separator"></div>
|
||||
{/if}
|
||||
<button
|
||||
class="menu-item"
|
||||
role="menuitem"
|
||||
@@ -69,4 +74,14 @@
|
||||
<Icon name="copy" />
|
||||
Copy rad: URI
|
||||
</button>
|
||||
{#if seedRid}
|
||||
<div class="menu-separator"></div>
|
||||
<button
|
||||
class="menu-item"
|
||||
role="menuitem"
|
||||
onclick={() => void seedRepo(seedRid).catch(console.error)}>
|
||||
<Icon name="seed" />
|
||||
Seed repository
|
||||
</button>
|
||||
{/if}
|
||||
</ContextMenu>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
} from "@app/lib/mentions";
|
||||
import type { Route } from "@app/lib/router";
|
||||
import { push, routeToPath } from "@app/lib/router";
|
||||
import { fetchingRepos } from "@app/lib/seedRepo";
|
||||
import {
|
||||
formatOid,
|
||||
issueStatusColor,
|
||||
@@ -69,20 +70,32 @@
|
||||
|
||||
const repoName = $derived(resolvedRepoName ?? fallback);
|
||||
|
||||
const fetching = $derived(
|
||||
target.type !== "node" && $fetchingRepos.includes(target.rid),
|
||||
);
|
||||
let repoLocal: boolean | undefined = $state(undefined);
|
||||
const seedRid = $derived(
|
||||
repoLocal === false && !fetching && target.type !== "node"
|
||||
? target.rid
|
||||
: undefined,
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
if (target.type !== "repo") return;
|
||||
if (target.type === "node" || fetching) return;
|
||||
const isRepo = target.type === "repo";
|
||||
let cancelled = false;
|
||||
void cachedRepoById(target.rid)
|
||||
.then(result => {
|
||||
if (cancelled) return;
|
||||
if (!result) {
|
||||
missing = true;
|
||||
return;
|
||||
}
|
||||
resolvedRepoName = result.payloads["xyz.radicle.project"]?.data.name;
|
||||
repoLocal = result !== null;
|
||||
if (!isRepo) return;
|
||||
missing = !result;
|
||||
resolvedRepoName = result?.payloads["xyz.radicle.project"]?.data.name;
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) missing = true;
|
||||
if (cancelled) return;
|
||||
repoLocal = false;
|
||||
if (isRepo) missing = true;
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
@@ -164,7 +177,7 @@
|
||||
let menu: MenuPosition | undefined = $state(undefined);
|
||||
|
||||
function openMenu(event: MouseEvent) {
|
||||
if (explorerHref) menu = menuPosition(event);
|
||||
if (explorerHref || seedRid) menu = menuPosition(event);
|
||||
}
|
||||
|
||||
function handleClick(event: MouseEvent) {
|
||||
@@ -377,13 +390,14 @@
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
{#if menu && explorerHref && config}
|
||||
{#if menu && config}
|
||||
<ExplorerMenu
|
||||
x={menu.x}
|
||||
y={menu.y}
|
||||
target={menu.target}
|
||||
url={explorerHref}
|
||||
uri={entityUri(target)}
|
||||
{seedRid}
|
||||
{config}
|
||||
onclose={() => (menu = undefined)} />
|
||||
{/if}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { describeLink, referenceRoute } from "@app/lib/mentions";
|
||||
import { formatReference, parseReference } from "@app/lib/radUri";
|
||||
import { push, routeToPath } from "@app/lib/router";
|
||||
import { fetchingRepos } from "@app/lib/seedRepo";
|
||||
import { explorerLink } from "@app/lib/utils";
|
||||
|
||||
import ExplorerMenu, {
|
||||
@@ -42,11 +43,15 @@
|
||||
});
|
||||
|
||||
const route = $derived(reference && referenceRoute(reference));
|
||||
let local = $state(false);
|
||||
const rid = $derived(
|
||||
reference?.type === "uri" ? `rad:${reference.uri.repo}` : undefined,
|
||||
);
|
||||
const fetching = $derived(rid !== undefined && $fetchingRepos.includes(rid));
|
||||
let local: boolean | undefined = $state(undefined);
|
||||
$effect(() => {
|
||||
if (!route) return;
|
||||
if (!rid || fetching) return;
|
||||
let cancelled = false;
|
||||
void cachedRepoById(route.rid)
|
||||
void cachedRepoById(rid)
|
||||
.then(repo => {
|
||||
if (!cancelled) local = repo !== null;
|
||||
})
|
||||
@@ -57,8 +62,9 @@
|
||||
cancelled = true;
|
||||
};
|
||||
});
|
||||
const inApp = $derived(local && route !== undefined);
|
||||
const inApp = $derived(local === true && route !== undefined);
|
||||
const linkHref = $derived(inApp && route ? routeToPath(route) : url);
|
||||
const seedRid = $derived(local === false && !fetching ? rid : undefined);
|
||||
|
||||
function handleClick(event: MouseEvent) {
|
||||
if (!inApp || !route) return;
|
||||
@@ -69,7 +75,7 @@
|
||||
let menu: MenuPosition | undefined = $state(undefined);
|
||||
|
||||
function openMenu(event: MouseEvent) {
|
||||
if (url) menu = menuPosition(event);
|
||||
if (url || seedRid) menu = menuPosition(event);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -95,13 +101,14 @@
|
||||
{/if}{label}
|
||||
</a>
|
||||
|
||||
{#if menu && url && config}
|
||||
{#if menu && config}
|
||||
<ExplorerMenu
|
||||
x={menu.x}
|
||||
y={menu.y}
|
||||
target={menu.target}
|
||||
{url}
|
||||
uri={reference ? formatReference(reference) : href}
|
||||
{seedRid}
|
||||
{config}
|
||||
onclose={() => (menu = undefined)} />
|
||||
{/if}
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
import { show } from "@app/lib/modal";
|
||||
import { repoListScope } from "@app/lib/repoListScope";
|
||||
import * as router from "@app/lib/router";
|
||||
import { seededRepos, seedRepo, setFetchingRepos } from "@app/lib/seedRepo";
|
||||
import {
|
||||
ariaKeyShortcuts,
|
||||
modifierHeld,
|
||||
@@ -346,6 +347,13 @@
|
||||
setOrder: rids => withPinAnimation(() => (pinnedRepoIds.value = rids)),
|
||||
});
|
||||
|
||||
$effect(() => setFetchingRepos(seededNotReplicated));
|
||||
|
||||
$effect(() => {
|
||||
if ($seededRepos === 0) return;
|
||||
untrack(() => void reloadRepos());
|
||||
});
|
||||
|
||||
async function reloadRepos() {
|
||||
invalidateReposSummary();
|
||||
[repos, seededNotReplicated] = await Promise.all([
|
||||
@@ -393,15 +401,11 @@
|
||||
// network. Nothing is destroyed, so it runs straight off the menu item.
|
||||
async function startSeeding(rid: string) {
|
||||
try {
|
||||
await invoke<null>("seed", { rid });
|
||||
await seedRepo(rid);
|
||||
} catch (error) {
|
||||
console.error("Seed failed", error);
|
||||
} finally {
|
||||
await reloadRepos().catch(error =>
|
||||
console.error("Reloading repos failed", error),
|
||||
);
|
||||
await refreshActiveRepo(rid);
|
||||
}
|
||||
await refreshActiveRepo(rid);
|
||||
}
|
||||
|
||||
// The pending-fetch list's trash button, which stays quiet on failure. The
|
||||
|
||||
Reference in New Issue
Block a user