Browse Source

implemented $effect and $state

master
Silberengel 10 months ago
parent
commit
03e4d769bb
  1. 63
      src/routes/events/+page.svelte

63
src/routes/events/+page.svelte

@ -13,13 +13,24 @@
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import InlineProfile from '$lib/components/util/InlineProfile.svelte'; import InlineProfile from '$lib/components/util/InlineProfile.svelte';
let searchQuery = ""; let searchQuery = $state("");
let event: NDKEvent | null = null; let event = $state<NDKEvent | null>(null);
let loading = false; let loading = $state(false);
let error: string | null = null; let error = $state<string | null>(null);
let showFullContent = false; let showFullContent = $state(false);
let contentPreview = ''; let parsedContent = $state('');
let parsedContent = ''; let contentPreview = $state('');
let profile = $state<{
name?: string;
display_name?: string;
about?: string;
picture?: string;
banner?: string;
website?: string;
lud16?: string;
nip05?: string;
} | null>(null);
let profileTitle = $state<string | null>(null);
async function searchEvent() { async function searchEvent() {
if (!searchQuery.trim()) return; if (!searchQuery.trim()) return;
@ -193,20 +204,34 @@
} }
}); });
$: if (event && event.kind !== 0 && event.content) { $effect(() => {
parseBasicmarkup(event.content).then(html => { if (event && event.kind !== 0 && event.content) {
parsedContent = html; parseBasicmarkup(event.content).then(html => {
contentPreview = html.slice(0, 250); parsedContent = html;
}); contentPreview = html.slice(0, 250);
} });
}
});
$: profile = event && event.kind === 0 $effect(() => {
? (() => { try { return JSON.parse(event.content); } catch { return null; } })() if (event && event.kind === 0) {
: null; try {
profile = JSON.parse(event.content);
} catch {
profile = null;
}
} else {
profile = null;
}
});
$: profileTitle = event && event.kind === 0 && profile && profile.name $effect(() => {
? profile.name if (event && event.kind === 0 && profile && profile.name) {
: null; profileTitle = profile.name;
} else {
profileTitle = null;
}
});
</script> </script>
<div class="w-full flex justify-center"> <div class="w-full flex justify-center">

Loading…
Cancel
Save