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

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

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

12
src/lib/models/user_profile.ts

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

15
src/routes/events/+page.svelte

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

Loading…
Cancel
Save