Convert cob actions into customized desktop actions

This commit allows us to e.g. convert the Set of DIDs we obtain from
assignee actions on cobs into a Set of Authors with their Aliases.

Also it introduces the `FromRadicleAction` trait which can be
implemented for any type of enum we get from the `radicle` create to
convert into a type which is better suited for us.

Removes also any calling the `alias` command in the `PatchTimeline` or
`IssueTimeline` since we already get the alias from the backend the
first time now.
This commit is contained in:
Sebastian Martinez
2025-03-18 13:10:26 -06:00
committed by Rūdolfs Ošiņš
parent b1bf3c510d
commit c730e82187
15 changed files with 278 additions and 80 deletions
+5 -25
View File
@@ -18,11 +18,9 @@
formatTimestamp,
issueStatusColor,
pluralize,
publicKeyFromDid,
} from "@app/lib/utils";
import Icon from "./Icon.svelte";
import NodeId from "./NodeId.svelte";
import { invoke } from "@app/lib/invoke";
import Id from "./Id.svelte";
interface Props {
@@ -66,7 +64,7 @@
return result;
}
function itemDiff(previousState: string[], newState: string[]) {
function itemDiff<A>(previousState: A[], newState: A[]) {
const removed = previousState.filter(x => !newState.includes(x));
const added = newState.filter(x => !previousState.includes(x));
return { removed, added };
@@ -169,7 +167,7 @@
<div class="wrapper">
<NodeId {...authorForNodeId(op.author)} />
{#if op.previous && op.previous.type === op.type}
{@const changed = itemDiff(
{@const changed = itemDiff<Author>(
op.previous?.assignees ?? [],
op.assignees,
)}
@@ -177,38 +175,20 @@
{#if changed.added.length}
assigned
{#each changed.added as assignee}
{#await invoke<string | null>( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias}
<NodeId
{...authorForNodeId({
did: assignee,
alias: alias ?? undefined,
})} />
{/await}
<NodeId {...authorForNodeId(assignee)} />
{/each}
{/if}
{#if changed.removed.length}
unassigned
{#each changed.removed as assignee}
{#await invoke<string | null>( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias}
<NodeId
{...authorForNodeId({
did: assignee,
alias: alias ?? undefined,
})} />
{/await}
<NodeId {...authorForNodeId(assignee)} />
{/each}
{/if}
{/if}
{:else}
assigned
{#each op.assignees as assignee}
{#await invoke<string | null>( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias}
<NodeId
{...authorForNodeId({
did: assignee,
alias: alias ?? undefined,
})} />
{/await}
<NodeId {...authorForNodeId(assignee)} />
{/each}
{/if}
<div title={absoluteTimestamp(op.timestamp)}>
+5 -25
View File
@@ -18,12 +18,10 @@
formatTimestamp,
patchStatusColor,
pluralize,
publicKeyFromDid,
} from "@app/lib/utils";
import Icon from "./Icon.svelte";
import Id from "./Id.svelte";
import NodeId from "./NodeId.svelte";
import { invoke } from "@app/lib/invoke";
interface Props {
patchId: string;
@@ -67,7 +65,7 @@
return result;
}
function itemDiff(previousState: string[], newState: string[]) {
function itemDiff<A>(previousState: A[], newState: A[]) {
const removed = previousState.filter(x => !newState.includes(x));
const added = newState.filter(x => !previousState.includes(x));
return { removed, added };
@@ -190,44 +188,26 @@
<div class="wrapper">
<NodeId {...authorForNodeId(op.author)} />
{#if op.previous && op.previous.type === op.type}
{@const changed = itemDiff(
{@const changed = itemDiff<Author>(
op.previous?.assignees ?? [],
op.assignees,
)}
{#if changed.added.length}
assigned
{#each changed.added as assignee}
{#await invoke<string | null>( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias}
<NodeId
{...authorForNodeId({
did: assignee,
alias: alias ?? undefined,
})} />
{/await}
<NodeId {...authorForNodeId(assignee)} />
{/each}
{/if}
{#if changed.removed.length}
unassigned
{#each changed.removed as assignee}
{#await invoke<string | null>( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias}
<NodeId
{...authorForNodeId({
did: assignee,
alias: alias ?? undefined,
})} />
{/await}
<NodeId {...authorForNodeId(assignee)} />
{/each}
{/if}
{:else}
assigned
{#each op.assignees as assignee}
{#await invoke<string | null>( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias}
<NodeId
{...authorForNodeId({
did: assignee,
alias: alias ?? undefined,
})} />
{/await}
<NodeId {...authorForNodeId(assignee)} />
{/each}
{/if}
<div title={absoluteTimestamp(op.timestamp)}>
+1 -1
View File
@@ -126,7 +126,7 @@
cobId: issue.id,
action: {
type: "assign",
assignees: assignees.map(a => a.did),
assignees,
},
opts: { announce: $nodeRunning && $announce },
});
+1 -1
View File
@@ -157,7 +157,7 @@
cobId: patch.id,
action: {
type: "assign",
assignees: assignees.map(a => a.did),
assignees,
},
opts: { announce: $nodeRunning && $announce },
});