mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-26 08:40:34 +08:00
Add patch deletion
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
didFromPublicKey,
|
||||
formatTimestamp,
|
||||
patchStatusLabel,
|
||||
publicKeyFromDid,
|
||||
} from "@app/lib/utils";
|
||||
|
||||
import { announce } from "@app/components/AnnounceSwitch.svelte";
|
||||
@@ -121,6 +122,14 @@
|
||||
),
|
||||
);
|
||||
|
||||
// Deleting drops the COB ref under our own namespace, so peers prune it when
|
||||
// they next fetch. We hold no such ref on anyone else's patch, where deleting
|
||||
// would only evict the local cache and the patch would return on the next
|
||||
// fetch — so the action is author-only.
|
||||
const isOwnPatch = $derived(
|
||||
publicKeyFromDid(patch.author.did) === config.publicKey,
|
||||
);
|
||||
|
||||
// svelte-ignore state_referenced_locally
|
||||
let tab: "patch" | "revisions" | "timeline" = $state(
|
||||
revisions.length > 1 ? "revisions" : "patch",
|
||||
@@ -560,6 +569,30 @@
|
||||
cancelled = true;
|
||||
};
|
||||
});
|
||||
|
||||
let deleteMenuExpanded = $state(false);
|
||||
let deleting = $state(false);
|
||||
async function deletePatch() {
|
||||
if (deleting) return;
|
||||
deleting = true;
|
||||
try {
|
||||
await invoke("delete_patch", {
|
||||
rid: repo.rid,
|
||||
cobId: patch.id,
|
||||
opts: { announce: $nodeRunning && $announce },
|
||||
});
|
||||
void router.push({
|
||||
resource: "repo.patches",
|
||||
rid: repo.rid,
|
||||
status: patch.state.status,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Deleting patch failed", error);
|
||||
} finally {
|
||||
deleting = false;
|
||||
deleteMenuExpanded = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -573,6 +606,45 @@
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
.confirm-delete {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
min-width: 16rem;
|
||||
}
|
||||
.confirm-delete-text {
|
||||
color: var(--color-text-primary);
|
||||
}
|
||||
.confirm-delete-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.confirm-delete-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
height: 2rem;
|
||||
padding: 0 0.75rem;
|
||||
border: 0;
|
||||
border-radius: var(--border-radius-sm);
|
||||
background-color: var(--color-feedback-error-fill);
|
||||
color: var(--color-text-on-brand);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.1s ease;
|
||||
}
|
||||
.confirm-delete-button:hover:not(:disabled),
|
||||
.confirm-delete-button:focus-visible:not(:disabled) {
|
||||
background-color: var(--color-feedback-error-fill-hover);
|
||||
}
|
||||
.confirm-delete-button:active:not(:disabled) {
|
||||
background-color: var(--color-feedback-error-fill-active);
|
||||
}
|
||||
.confirm-delete-button:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.breadcrumb-link {
|
||||
cursor: pointer;
|
||||
background: none;
|
||||
@@ -886,6 +958,53 @@
|
||||
style:margin-left="auto"
|
||||
style:gap="0.5rem"
|
||||
style:z-index="40">
|
||||
{#if isOwnPatch}
|
||||
<Popover
|
||||
popoverPadding="0"
|
||||
placement="bottom-end"
|
||||
bind:expanded={deleteMenuExpanded}>
|
||||
{#snippet toggle(onclick)}
|
||||
<Button
|
||||
variant="naked"
|
||||
{onclick}
|
||||
active={deleteMenuExpanded}
|
||||
title="Delete patch from your node">
|
||||
<Icon name="trash" />
|
||||
<span class="global-hide-on-medium-desktop-down">Delete</span>
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#snippet popover()}
|
||||
<div
|
||||
style:border="1px solid var(--color-border-subtle)"
|
||||
style:border-radius="var(--border-radius-sm)"
|
||||
style:background-color="var(--color-surface-canvas)">
|
||||
<div class="confirm-delete">
|
||||
<div class="confirm-delete-text txt-body-m-regular">
|
||||
Delete this patch from your node? This removes your copy
|
||||
only — you won't be able to restore it here, and peers who
|
||||
have already replicated the patch keep theirs.
|
||||
</div>
|
||||
<div class="confirm-delete-actions">
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={deleting}
|
||||
onclick={() => (deleteMenuExpanded = false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<button
|
||||
type="button"
|
||||
class="confirm-delete-button txt-body-m-medium"
|
||||
disabled={deleting}
|
||||
onclick={deletePatch}>
|
||||
<Icon name="trash" />
|
||||
{deleting ? "Deleting…" : "Delete"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Popover>
|
||||
{/if}
|
||||
<ShareButton
|
||||
explorerPath={`${repo.rid}/patches/${patch.id}`}
|
||||
id={patch.id}
|
||||
|
||||
Reference in New Issue
Block a user