Browse Source

fixed a-tag links

master
Silberengel 8 months ago
parent
commit
d39daa855c
  1. 25
      src/lib/components/EventDetails.svelte
  2. 6
      src/routes/events/+page.svelte

25
src/lib/components/EventDetails.svelte

@ -10,6 +10,7 @@
import ProfileHeader from "$components/cards/ProfileHeader.svelte"; import ProfileHeader from "$components/cards/ProfileHeader.svelte";
import { getUserMetadata } from "$lib/utils/nostrUtils"; import { getUserMetadata } from "$lib/utils/nostrUtils";
import CopyToClipboard from '$lib/components/util/CopyToClipboard.svelte'; import CopyToClipboard from '$lib/components/util/CopyToClipboard.svelte';
import { goto } from '$app/navigation';
const { event, profile = null, searchValue = null } = $props<{ const { event, profile = null, searchValue = null } = $props<{
event: NDKEvent; event: NDKEvent;
@ -48,15 +49,17 @@
return MTag[1].split('/')[1] || `Event Kind ${event.kind}`; return MTag[1].split('/')[1] || `Event Kind ${event.kind}`;
} }
function renderTag(tag: string[]): string { function getTagButtonInfo(tag: string[]): { text: string, gotoValue?: string } {
if (tag[0] === 'a' && tag.length > 1) { if (tag[0] === 'a' && tag.length > 1) {
const [kind, pubkey, d] = tag[1].split(':'); const [kind, pubkey, d] = tag[1].split(':');
return `<a href='/events?id=${naddrEncode({kind: +kind, pubkey, tags: [['d', d]], content: '', id: '', sig: ''} as any, standardRelays)}' class='underline text-primary-700 dark:text-primary-300'>a:${tag[1]}</a>`; const naddr = naddrEncode({kind: +kind, pubkey, tags: [['d', d]], content: '', id: '', sig: ''} as any, standardRelays);
} else if (tag[0] === 'e' && tag.length > 1) { return { text: `a:${tag[1]}`, gotoValue: naddr };
return `<a href='/events?id=${neventEncode({id: tag[1], kind: 1, content: '', tags: [], pubkey: '', sig: ''} as any, standardRelays)}' class='underline text-primary-700 dark:text-primary-300'>e:${tag[1]}</a>`; }
} else { if (tag[0] === 'e' && tag.length > 1) {
return `<span class='bg-primary-50 text-primary-800 px-2 py-1 rounded text-xs font-mono'>${tag[0]}:${tag[1]}</span>`; const nevent = neventEncode({id: tag[1], kind: 1, content: '', tags: [], pubkey: '', sig: ''} as any, standardRelays);
return { text: `e:${tag[1]}`, gotoValue: nevent };
} }
return { text: '' };
} }
$effect(() => { $effect(() => {
@ -180,7 +183,15 @@
<span class="text-gray-700 dark:text-gray-300">Event Tags:</span> <span class="text-gray-700 dark:text-gray-300">Event Tags:</span>
<div class="flex flex-wrap gap-2"> <div class="flex flex-wrap gap-2">
{#each event.tags as tag} {#each event.tags as tag}
{@html renderTag(tag)} {@const tagInfo = getTagButtonInfo(tag)}
{#if tagInfo.text && tagInfo.gotoValue}
<button
onclick={() => goto(`/events?id=${encodeURIComponent(tagInfo.gotoValue!)}`)}
class="underline text-primary-700 dark:text-primary-300 cursor-pointer bg-transparent border-none p-0 text-left hover:text-primary-900 dark:hover:text-primary-100"
>
{tagInfo.text}
</button>
{/if}
{/each} {/each}
</div> </div>
</div> </div>

6
src/routes/events/+page.svelte

@ -38,12 +38,14 @@
} }
} }
onMount(async () => { $effect(() => {
const id = $page.url.searchParams.get('id'); const id = $page.url.searchParams.get('id');
if (id) { if (id !== searchValue) {
searchValue = id; searchValue = id;
} }
});
onMount(async () => {
// Get user's pubkey and relay preference from localStorage // Get user's pubkey and relay preference from localStorage
userPubkey = localStorage.getItem('userPubkey'); userPubkey = localStorage.getItem('userPubkey');
userRelayPreference = localStorage.getItem('useUserRelays') === 'true'; userRelayPreference = localStorage.getItem('useUserRelays') === 'true';

Loading…
Cancel
Save