Simplify Avatar component and get rid of extra requests

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2023-04-10 14:39:50 +02:00
parent 7caa83e1b6
commit 045890d2e1
5 changed files with 12 additions and 28 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import type { Author } from "@app/lib/cobs";
import Avatar from "@app/components/Comment/Avatar.svelte";
import Avatar from "@app/components/Avatar.svelte";
import { formatNodeId, formatTimestamp } from "@app/lib/utils";
export let author: Author;
@@ -42,7 +42,7 @@
<span class="authorship txt-tiny" title={relativeTimestamp(timestamp)}>
{#if !noAvatar}
<Avatar inline source={author.id} title={author.id} />
<Avatar inline nodeId={author.id} />
{/if}
<span class:highlight class="id highlight layout-desktop">
{formatNodeId(author.id)}
@@ -1,16 +1,9 @@
<script lang="ts">
import { createIcon } from "@app/lib/blockies";
import { isNodeId } from "@app/lib/utils";
export let title: string;
export let source: string;
export let nodeId: string;
export let inline = false;
function handleMissingFile() {
console.warn("Not able to locate", source);
source = createContainer(title);
}
function createContainer(source: string) {
source = source.replace("did:key:", "");
const seed = source.toLowerCase();
@@ -21,10 +14,6 @@
});
return avatar.toDataURL();
}
if (isNodeId(source)) {
source = createContainer(source);
}
</script>
<style>
@@ -48,9 +37,8 @@
</style>
<img
{title}
src={source}
title={nodeId}
src={createContainer(nodeId)}
class="avatar"
alt="avatar"
on:error={handleMissingFile}
class:inline />