Browse Source

Extract user profile to new interface

master
buttercat1791 7 months ago
parent
commit
43eddd3ede
  1. 12
      src/lib/components/EventDetails.svelte
  2. 14
      src/lib/components/embedded_events/EmbeddedEvent.svelte
  3. 12
      src/lib/models/user_profile.ts
  4. 13
      src/lib/snippets/UserSnippets.svelte
  5. 15
      src/routes/events/+page.svelte

12
src/lib/components/EventDetails.svelte

@ -15,22 +15,14 @@ @@ -15,22 +15,14 @@
import ContainingIndexes from "$lib/components/util/ContainingIndexes.svelte";
import Notifications from "$lib/components/Notifications.svelte";
import EmbeddedEvent from "./embedded_events/EmbeddedEvent.svelte";
import type { UserProfile } from "$lib/models/user_profile";
const {
event,
profile = null,
} = $props<{
event: NDKEvent;
profile?: {
name?: string;
display_name?: string;
about?: string;
picture?: string;
banner?: string;
website?: string;
lud16?: string;
nip05?: string;
} | null;
profile?: UserProfile | null;
}>();
let authorDisplayName = $state<string | undefined>(undefined);

14
src/lib/components/embedded_events/EmbeddedEvent.svelte

@ -10,7 +10,8 @@ @@ -10,7 +10,8 @@
import { nip19 } from "nostr-tools";
import { repostKinds } from "$lib/consts";
import { UserOutline } from "flowbite-svelte-icons";
import type { UserProfile } from "$lib/models/user_profile";
const {
nostrIdentifier,
nestingLevel = 0,
@ -22,16 +23,7 @@ @@ -22,16 +23,7 @@
const ndk = getNdkContext();
let event = $state<NDKEvent | null>(null);
let profile = $state<{
name?: string;
display_name?: string;
about?: string;
picture?: string;
banner?: string;
website?: string;
lud16?: string;
nip05?: string;
} | null>(null);
let profile = $state< UserProfile | null>(null);
let loading = $state(true);
let error = $state<string | null>(null);
let authorDisplayName = $state<string | undefined>(undefined);

12
src/lib/models/user_profile.ts

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
export interface UserProfile {
name?: string;
display_name?: string;
about?: string;
picture?: string;
banner?: string;
website?: string;
lud16?: string;
nip05?: string;
isInUserLists?: boolean;
listKinds?: number[];
}

13
src/lib/snippets/UserSnippets.svelte

@ -5,14 +5,7 @@ @@ -5,14 +5,7 @@
toNpub,
getUserMetadata,
} from "$lib/utils/nostrUtils";
// Extend NostrProfile locally to allow display_name for legacy support
type NostrProfileWithLegacy = {
displayName?: string;
display_name?: string;
name?: string;
[key: string]: any;
};
import type { UserProfile } from "$lib/models/user_profile";
export { userBadge };
</script>
@ -22,13 +15,13 @@ @@ -22,13 +15,13 @@
{#if npub}
{#if !displayText || displayText.trim().toLowerCase() === "unknown"}
{#await getUserMetadata(npub, undefined, false) then profile}
{@const p = profile as NostrProfileWithLegacy}
{@const p = profile as UserProfile}
<span class="inline-flex items-center gap-0.5">
<button
class="npub-badge bg-transparent border-none p-0 underline cursor-pointer"
onclick={() => goto(`/events?id=${npub}`)}
>
@{p.displayName ||
@{p.display_name ||
p.display_name ||
p.name ||
npub.slice(0, 8) + "..." + npub.slice(-4)}

15
src/routes/events/+page.svelte

@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
import { userStore } from "$lib/stores/userStore";
import { fetchCurrentUserLists, isPubkeyInUserLists } from "$lib/utils/user_lists";
import { UserOutline } from "flowbite-svelte-icons";
import { clearAllCaches, clearProfileCaches, getCacheStats } from "$lib/utils/cache_manager";
import type { UserProfile } from "$lib/models/user_profile";
let loading = $state(false);
let error = $state<string | null>(null);
@ -35,18 +35,7 @@ @@ -35,18 +35,7 @@
let originalAddresses = $state<Set<string>>(new Set());
let searchType = $state<string | null>(null);
let searchTerm = $state<string | null>(null);
let profile = $state<{
name?: string;
display_name?: string;
about?: string;
picture?: string;
banner?: string;
website?: string;
lud16?: string;
nip05?: string;
isInUserLists?: boolean;
listKinds?: number[];
} | null>(null);
let profile = $state<UserProfile | null>(null);
let userRelayPreference = $state(false);
let showSidePanel = $state(false);
let searchInProgress = $state(false);

Loading…
Cancel
Save