Add wot to discover

This commit is contained in:
Jon Staab
2024-10-17 13:56:53 -07:00
parent 7cf8fac9b6
commit 9c31b12d48
7 changed files with 119 additions and 65 deletions
+19 -15
View File
@@ -9,7 +9,7 @@
createProfile,
isPublishedProfile,
} from "@welshman/util"
import {pubkey, profilesByPubkey, publishThunk, displayNip05} from "@welshman/app"
import {pubkey, profilesByPubkey, publishThunk, displayNip05, deriveProfile} from "@welshman/app"
import {slide} from "@lib/transition"
import Icon from "@lib/components/Icon.svelte"
import Field from "@lib/components/Field.svelte"
@@ -21,26 +21,28 @@
import {pushModal} from "@app/modal"
import {pushToast} from "@app/toast"
const profile = deriveProfile($pubkey!)
const pubkeyDisplay = displayPubkey($pubkey!)
const cloneProfile = () => ({...($profilesByPubkey.get($pubkey!) || makeProfile())})
const cloneProfile = () => ({...($profile || makeProfile())})
const toggleEdit = () => {
editing = !editing
if (!editing) {
profile = cloneProfile()
values = cloneProfile()
}
}
const stopEdit = () => {
editing = false
profile = cloneProfile()
values = cloneProfile()
}
const saveEdit = () => {
const relays = ctx.app.router.WriteRelays().getUrls()
const template = isPublishedProfile(profile) ? editProfile(profile) : createProfile(profile)
const template = isPublishedProfile(values) ? editProfile(values) : createProfile(values)
const event = createEvent(template.kind, template)
publishThunk({event, relays})
@@ -50,7 +52,9 @@
let file: File
let editing = false
let profile = cloneProfile()
let values = cloneProfile()
$: display = editing ? values : $profile
</script>
<div class="content column gap-4">
@@ -58,16 +62,16 @@
<div class="flex justify-between gap-2">
<div class="flex max-w-full gap-3">
<div class="py-1">
<Avatar src={profile?.picture} size={10} />
<Avatar src={display?.picture} size={10} />
</div>
<div class="flex min-w-0 flex-col">
<div class="flex items-center gap-2">
<div class="text-bold overflow-hidden text-ellipsis">
{displayProfile(profile, pubkeyDisplay)}
{displayProfile(display, pubkeyDisplay)}
</div>
</div>
<div class="overflow-hidden text-ellipsis text-sm opacity-75">
{profile?.nip05 ? displayNip05(profile.nip05) : pubkeyDisplay}
{display?.nip05 ? displayNip05(display.nip05) : pubkeyDisplay}
</div>
</div>
</div>
@@ -75,20 +79,20 @@
<Icon icon="pen-new-square" />
</Button>
</div>
{#key profile.about}
<Content event={{content: profile.about, tags: []}} hideMedia />
{#key display?.about}
<Content event={{content: display?.about || "", tags: []}} hideMedia />
{/key}
</div>
{#if editing}
<form class="card2 bg-alt shadow-xl" transition:slide on:submit|preventDefault={saveEdit}>
<div class="flex justify-center py-2">
<InputProfilePicture bind:file bind:url={profile.picture} />
<InputProfilePicture bind:file bind:url={values.picture} />
</div>
<Field>
<p slot="label">Username</p>
<label class="input input-bordered flex w-full items-center gap-2" slot="input">
<Icon icon="user-circle" />
<input bind:value={profile.name} class="grow" type="text" />
<input bind:value={values.name} class="grow" type="text" />
</label>
</Field>
<Field>
@@ -96,14 +100,14 @@
<textarea
class="textarea textarea-bordered leading-4"
rows="3"
bind:value={profile.about}
bind:value={values.about}
slot="input" />
</Field>
<Field>
<p slot="label">Nostr Address</p>
<label class="input input-bordered flex w-full items-center gap-2" slot="input">
<Icon icon="remote-controller-minimalistic" />
<input bind:value={profile.nip05} class="grow" type="text" />
<input bind:value={values.nip05} class="grow" type="text" />
</label>
<p slot="info">
<Button class="link" on:click={() => pushModal(InfoHandle)}
+8 -1
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import {onMount} from 'svelte'
import {derived} from "svelte/store"
import {
getRelayUrls,
@@ -6,6 +7,8 @@
userInboxRelaySelections,
getReadRelayUrls,
getWriteRelayUrls,
relaySelections,
inboxRelaySelections,
} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
@@ -13,7 +16,7 @@
import RelayItem from "@app/components/RelayItem.svelte"
import RelayAdd from "@app/components/RelayAdd.svelte"
import {pushModal} from "@app/modal"
import {setRelayPolicy, setInboxRelayPolicy} from "@app/commands"
import {setRelayPolicy, discoverRelays, setInboxRelayPolicy} from "@app/commands"
const readRelayUrls = derived(userRelaySelections, getReadRelayUrls)
const writeRelayUrls = derived(userRelaySelections, getWriteRelayUrls)
@@ -42,6 +45,10 @@
const removeWriteRelay = (url: string) => setRelayPolicy(url, $readRelayUrls.includes(url), false)
const removeInboxRelay = (url: string) => setInboxRelayPolicy(url, false)
onMount(() => {
discoverRelays([...$relaySelections, ...$inboxRelaySelections])
})
</script>
<div class="content column gap-4">