Browse Source

fixed commentbox userbadge display

master
silberengel 7 months ago
parent
commit
550ae84a9f
  1. 31
      src/lib/components/CommentBox.svelte

31
src/lib/components/CommentBox.svelte

@ -10,6 +10,7 @@
} from "$lib/utils/search_utility"; } from "$lib/utils/search_utility";
import { userPubkey } from "$lib/stores/authStore.Svelte"; import { userPubkey } from "$lib/stores/authStore.Svelte";
import { userStore } from "$lib/stores/userStore";
import type { NDKEvent } from "$lib/utils/nostrUtils"; import type { NDKEvent } from "$lib/utils/nostrUtils";
import { import {
extractRootEventInfo, extractRootEventInfo,
@ -67,17 +68,12 @@
} }
}); });
// Get user profile from userStore
$effect(() => { $effect(() => {
const trimmedPubkey = $userPubkey?.trim(); const currentUser = $userStore;
const npub = toNpub(trimmedPubkey); if (currentUser?.signedIn && currentUser.profile) {
if (npub) { userProfile = currentUser.profile;
// Call an async function, but don't make the effect itself async error = null;
getUserMetadata(npub).then((metadata) => {
userProfile = metadata;
});
} else if (trimmedPubkey) {
userProfile = null;
error = "Invalid public key: must be a 64-character hex string.";
} else { } else {
userProfile = null; userProfile = null;
error = null; error = null;
@ -590,17 +586,20 @@
<img <img
src={userProfile.picture} src={userProfile.picture}
alt={userProfile.name || "Profile"} alt={userProfile.name || "Profile"}
class="w-8 h-8 rounded-full" class="w-8 h-8 rounded-full object-cover"
onerror={(e) => { onerror={(e) => (e.target as HTMLImageElement).style.display = 'none'}
const img = e.target as HTMLImageElement;
img.src = `https://api.dicebear.com/7.x/avataaars/svg?seed=${encodeURIComponent(img.alt)}`;
}}
/> />
{:else}
<div class="w-8 h-8 rounded-full bg-gray-300 dark:bg-gray-600 flex items-center justify-center">
<span class="text-sm font-medium text-gray-600 dark:text-gray-300">
{(userProfile.displayName || userProfile.name || "U").charAt(0).toUpperCase()}
</span>
</div>
{/if} {/if}
<span class="text-gray-900 dark:text-gray-100"> <span class="text-gray-900 dark:text-gray-100">
{userProfile.displayName || {userProfile.displayName ||
userProfile.name || userProfile.name ||
nip19.npubEncode($userPubkey || "").slice(0, 8) + "..."} `${$userPubkey?.slice(0, 8)}...${$userPubkey?.slice(-4)}`}
</span> </span>
</div> </div>
{/if} {/if}

Loading…
Cancel
Save