desktop: Add an actor profile editor behind the actorRepos lab

Co-authored-by: Brandon Oxendine <brandon.oxendine@gmail.com>
This commit is contained in:
Ioannis T.
2026-11-20 17:33:55 +01:00
co-authored by Brandon Oxendine
parent 442e58780f
commit bc2914f06b
74 changed files with 15563 additions and 35 deletions
+97
View File
@@ -0,0 +1,97 @@
<script lang="ts">
import type { ActorInfo } from "@bindings/actor/ActorInfo";
import UserAvatar from "@radicle-gui/ui/components/UserAvatar.svelte";
import { onDestroy } from "svelte";
import { RepoImages } from "@app/lib/repoImages";
interface Props {
// The profile whose picture is shown. Without a profile, or without a
// picture that can be shown, the pattern generated from an ID stands in:
// the profile's, or `fallbackId` when there is no profile.
actor: Pick<ActorInfo, "rid" | "head" | "profile"> | null;
fallbackId?: string;
styleWidth: string;
}
const { actor, fallbackId, styleWidth }: Props = $props();
const images = new RepoImages();
onDestroy(() => images.dispose());
const rid = $derived(actor?.rid);
const head = $derived(actor?.head);
// A value with a colon is a web address. It is not fetched: that would
// tell its host who is looking, each time the picture is shown.
const path = $derived.by(() => {
const named = actor?.profile?.avatar?.trim();
return named && !named.includes(":") ? named : undefined;
});
// The picture shown and the profile it belongs to. A save moves `head`
// whether or not it changed the picture, so the one shown stays until the
// next has loaded.
let src = $state<string>();
let shownOf: string | undefined;
let broken = $state(false);
// The profile names a picture, so the pattern stands in only once that
// picture has failed to load: it must not show for a moment before it.
const named = $derived(Boolean(rid && head && path));
let failed = $state(false);
function showPicture(url: string | undefined) {
src = url;
broken = false;
failed = url === undefined;
// Releases the pictures loaded before this one.
images.sweep();
}
$effect(() => {
if (rid !== shownOf) {
shownOf = rid;
src = undefined;
}
if (!rid || !head || !path) {
showPicture(undefined);
return;
}
let gone = false;
void images
.load(rid, head, path)
.then(image => {
if (!gone) showPicture(image?.url);
})
.catch((e: unknown) => {
console.warn("Could not load the profile's avatar", e);
if (!gone) showPicture(undefined);
});
return () => {
gone = true;
};
});
const patternId = $derived(actor?.rid ?? fallbackId);
</script>
<style>
img {
display: block;
object-fit: cover;
}
</style>
{#if src && !broken}
<img
style:width={styleWidth}
style:height={styleWidth}
{src}
alt="Avatar"
onerror={() => (broken = true)} />
{:else if patternId && (!named || failed || broken)}
<UserAvatar nodeId={patternId} {styleWidth} />
{/if}
+7 -6
View File
@@ -3,12 +3,11 @@
</script>
<script lang="ts">
import type { RepoSummary } from "@bindings/repo/RepoSummary";
import { z } from "zod";
import { nodeRunning } from "@app/lib/events";
import { invoke } from "@app/lib/invoke";
import { cachedListReposWithActors, invoke } from "@app/lib/invoke";
import { repoListScope } from "@app/lib/repoListScope";
import { seedTarget } from "@app/lib/seedRepo";
import useLocalStorage from "@app/lib/useLocalStorage.svelte";
import { twemoji } from "@app/lib/utils";
@@ -24,11 +23,10 @@
interface Props {
reload: () => Promise<void>;
repos: RepoSummary[];
seededNotReplicated: string[];
}
const { reload, repos, seededNotReplicated }: Props = $props();
const { reload, seededNotReplicated }: Props = $props();
let popoverExpanded: boolean = $state(false);
let rid = $state("");
@@ -61,10 +59,13 @@
return;
}
// The project list hides actor repositories, so this check uses the full
// list.
const stored = await cachedListReposWithActors(repoListScope.value);
const target = seedTarget(
rid,
seededNotReplicated,
repos.map(r => r.rid),
stored.map(r => r.rid),
);
if ("error" in target) {
validationMessage = target.error;
+3 -1
View File
@@ -634,7 +634,9 @@
<div class="body">
<div class="nav">
{#if !mini}
<IdentityButton config={sidebarData.config} />
<IdentityButton
config={sidebarData.config}
actor={sidebarData.actor} />
{/if}
<a
+7 -2
View File
@@ -210,8 +210,13 @@
<path
d="M7.89634 2.39647C9.0581 1.23471 10.9416 1.23471 12.1034 2.39647C13.2651 3.55823 13.2651 5.44174 12.1034 6.6035L7.35337 11.3535C6.60582 12.101 5.39388 12.101 4.64634 11.3535C3.89879 10.606 3.89879 9.39401 4.64634 8.64647L8.64634 4.64647L9.35337 5.3535L5.35337 9.3535C4.99634 9.71052 4.99634 10.2894 5.35337 10.6465C5.71039 11.0035 6.28931 11.0035 6.64634 10.6465L11.3963 5.89647C12.1676 5.12523 12.1676 3.87473 11.3963 3.1035C10.6251 2.33226 9.3746 2.33226 8.60337 3.1035L3.85337 7.8535C2.66792 9.03895 2.66792 10.961 3.85337 12.1465C5.03882 13.3319 6.96089 13.3319 8.14634 12.1465L12.6463 7.64647L13.3534 8.3535L8.85337 12.8535C7.27739 14.4295 4.72231 14.4295 3.14634 12.8535C1.57036 11.2775 1.57036 8.72244 3.14634 7.14647L7.89634 2.39647Z" />
{:else if name === "avatar-incognito"}
<path
d="M13.5 8C13.5 4.96243 11.0376 2.5 8 2.5C4.96243 2.5 2.5 4.96243 2.5 8C2.5 9.74051 3.3094 11.291 4.57129 12.2988C4.61586 12.0809 4.68106 11.8667 4.7666 11.6602C4.94249 11.2357 5.2005 10.8503 5.52539 10.5254C5.85028 10.2005 6.23569 9.94249 6.66016 9.7666C7.0848 9.59071 7.54037 9.5 8 9.5C8.45963 9.5 8.9152 9.59071 9.33984 9.7666C9.76431 9.94249 10.1497 10.2005 10.4746 10.5254C10.7995 10.8503 11.0575 11.2357 11.2334 11.6602C11.3189 11.8666 11.3832 12.081 11.4277 12.2988C12.69 11.291 13.5 9.74078 13.5 8ZM8 10.5C7.6717 10.5 7.34628 10.5648 7.04297 10.6904C6.73978 10.8161 6.46449 11.0004 6.23242 11.2324C6.00036 11.4645 5.81606 11.7398 5.69043 12.043C5.57752 12.3155 5.51565 12.6061 5.50391 12.9004C6.25321 13.2828 7.10103 13.5 8 13.5C8.89866 13.5 9.74601 13.2826 10.4951 12.9004C10.4834 12.6061 10.4225 12.3155 10.3096 12.043C10.1839 11.7398 9.99964 11.4645 9.76758 11.2324C9.53551 11.0004 9.26022 10.8161 8.95703 10.6904C8.65372 10.5648 8.32831 10.5 8 10.5ZM9 6.5C9 5.94772 8.55228 5.5 8 5.5C7.44772 5.5 7 5.94772 7 6.5C7 7.05228 7.44772 7.5 8 7.5C8.55228 7.5 9 7.05228 9 6.5ZM14.5 8C14.5 10.3005 13.3033 12.3194 11.5 13.4746V13.5H11.4619C10.4593 14.1324 9.27294 14.5 8 14.5C6.72706 14.5 5.54065 14.1324 4.53809 13.5H4.5V13.4746C2.69675 12.3194 1.5 10.3005 1.5 8C1.5 4.41015 4.41015 1.5 8 1.5C11.5899 1.5 14.5 4.41015 14.5 8ZM10 6.5C10 7.60457 9.10457 8.5 8 8.5C6.89543 8.5 6 7.60457 6 6.5C6 5.39543 6.89543 4.5 8 4.5C9.10457 4.5 10 5.39543 10 6.5Z" />
<g fill="none" stroke="currentColor">
<circle cx="8" cy="8" r="6" />
<circle cx="8" cy="6.5" r="1.5" />
<path
d="M5 13L5.87868 9.87868L10.1213 9.87868L11 13"
stroke-linecap="square" />
</g>
{:else if name === "badge"}
<path
d="M4.64602 8.34829L5.35313 7.64118L7.00488 9.29294L10.6613 5.63656L11.3684 6.34367L7.00488 10.7072L4.64602 8.34829Z" />
+22 -4
View File
@@ -1,13 +1,16 @@
<script lang="ts">
import type { ActorInfo } from "@bindings/actor/ActorInfo";
import type { Config } from "@bindings/config/Config";
import UserAvatar from "@radicle-gui/ui/components/UserAvatar.svelte";
import debounce from "lodash/debounce";
import { writeToClipboard } from "@app/lib/invoke";
import { labs } from "@app/lib/labs";
import { entityUrl } from "@app/lib/mentions";
import * as router from "@app/lib/router";
import { didFromPublicKey, explorerHost, truncateDid } from "@app/lib/utils";
import ActorAvatar from "@app/components/ActorAvatar.svelte";
import Button from "@app/components/Button.svelte";
import DropdownListItem from "@app/components/DropdownListItem.svelte";
import Icon from "@app/components/Icon.svelte";
@@ -16,9 +19,10 @@
interface Props {
config: Config;
actor: ActorInfo | null;
}
const { config }: Props = $props();
const { config, actor }: Props = $props();
let popoverExpanded: boolean = $state(false);
let copyIcon: "copy" | "checkmark" = $state("copy");
@@ -35,8 +39,9 @@
styleJustifyContent="flex-start"
active={popoverExpanded}
{onclick}>
<UserAvatar nodeId={config.publicKey} styleWidth="1rem" />
<span class="label">{config.alias}</span>
<!-- A profile looks the same on each of its devices. -->
<ActorAvatar {actor} fallbackId={config.publicKey} styleWidth="1rem" />
<span class="label">{actor?.profile?.displayName || config.alias}</span>
<span class="label" style:color="var(--color-text-tertiary)">
<Icon name={popoverExpanded ? "chevron-up" : "chevron-down"} />
</span>
@@ -48,6 +53,19 @@
style:border-radius="var(--border-radius-md)"
style:background-color="var(--color-surface-canvas)"
style:padding="0.25rem">
{#if labs.actorRepos}
<DropdownListItem
styleGap="0.5rem"
styleWidth="100%"
selected={false}
onclick={async () => {
closeFocused();
await router.push({ resource: "profile", tab: "profile" });
}}>
<Icon name="avatar-incognito" />
{actor ? "Profile" : "Set up profile"}
</DropdownListItem>
{/if}
<DropdownListItem
styleGap="0.5rem"
styleWidth="100%"
@@ -390,10 +390,12 @@
async function reloadRepos() {
invalidateReposSummary();
[repos, seededNotReplicated] = await Promise.all([
const [reloaded, fetching] = await Promise.all([
cachedListReposSummary(repoListScope.value),
invoke<string[]>("seeded_not_replicated"),
]);
repos = reloaded;
seededNotReplicated = fetching;
}
// The route loader already fetched the list for the scope in force, so the
@@ -1127,7 +1129,7 @@
data-flip
onclick={e => e.stopPropagation()}
role="none">
<AddRepoButton reload={reloadRepos} {repos} {seededNotReplicated} />
<AddRepoButton reload={reloadRepos} {seededNotReplicated} />
</span>
</div>