flotilla/src/routes/settings/profile/+page.svelte

158 lines
5.3 KiB
Svelte
Raw Normal View History

2024-10-02 23:36:08 +00:00
<script lang="ts">
2025-04-09 22:32:18 +00:00
import * as nip19 from "nostr-tools/nip19"
import {hexToBytes} from "@noble/hashes/utils"
2024-11-15 22:25:18 +00:00
import {displayPubkey, displayProfile} from "@welshman/util"
import {pubkey, session, displayNip05, deriveProfile} from "@welshman/app"
import {slideAndFade} from "@lib/transition"
2024-10-02 23:36:08 +00:00
import Icon from "@lib/components/Icon.svelte"
import FieldInline from "@lib/components/FieldInline.svelte"
2024-10-02 23:36:08 +00:00
import Button from "@lib/components/Button.svelte"
import Avatar from "@lib/components/Avatar.svelte"
2024-10-08 18:39:16 +00:00
import Content from "@app/components/Content.svelte"
2024-11-15 22:25:18 +00:00
import ProfileEdit from "@app/components/ProfileEdit.svelte"
2025-02-14 23:59:20 +00:00
import ProfileDelete from "@app/components/ProfileDelete.svelte"
2024-11-27 00:39:49 +00:00
import InfoKeys from "@app/components/InfoKeys.svelte"
2025-03-20 16:38:57 +00:00
import Alerts from "@app/components/Alerts.svelte"
2024-11-27 00:39:49 +00:00
import {PLATFORM_NAME} from "@app/state"
2024-10-02 23:36:08 +00:00
import {pushModal} from "@app/modal"
2024-11-15 22:25:18 +00:00
import {clip} from "@app/toast"
2024-10-02 23:36:08 +00:00
2024-10-17 20:56:53 +00:00
const profile = deriveProfile($pubkey!)
2024-10-02 23:36:08 +00:00
const pubkeyDisplay = displayPubkey($pubkey!)
const copyNpub = () => clip(nip19.npubEncode($session!.pubkey))
const copyNsec = () => clip(nip19.nsecEncode(hexToBytes($session!.secret!)))
2024-11-15 22:25:18 +00:00
const startEdit = () => pushModal(ProfileEdit)
2024-11-27 00:39:49 +00:00
const startEject = () => pushModal(InfoKeys)
2025-02-14 23:59:20 +00:00
const startDelete = () => pushModal(ProfileDelete)
let showAdvanced = false
2024-10-02 23:36:08 +00:00
</script>
<div class="content column gap-4">
2024-10-03 21:32:55 +00:00
<div class="card2 bg-alt shadow-xl">
2024-10-08 18:39:16 +00:00
<div class="flex justify-between gap-2">
<div class="flex max-w-full gap-3">
2024-10-03 21:32:55 +00:00
<div class="py-1">
2024-11-15 22:25:18 +00:00
<Avatar src={$profile?.picture} size={10} />
2024-10-03 21:32:55 +00:00
</div>
2024-10-08 18:39:16 +00:00
<div class="flex min-w-0 flex-col">
<div class="flex items-center gap-2">
<div class="text-bold overflow-hidden text-ellipsis">
2024-11-15 22:25:18 +00:00
{displayProfile($profile, pubkeyDisplay)}
2024-10-02 23:36:08 +00:00
</div>
</div>
2024-10-08 18:39:16 +00:00
<div class="overflow-hidden text-ellipsis text-sm opacity-75">
2024-11-15 22:25:18 +00:00
{$profile?.nip05 ? displayNip05($profile.nip05) : pubkeyDisplay}
2024-10-03 21:32:55 +00:00
</div>
2024-10-02 23:36:08 +00:00
</div>
</div>
<Button class="center btn btn-circle btn-neutral -mr-4 -mt-4 h-12 w-12" onclick={startEdit}>
2024-10-03 21:32:55 +00:00
<Icon icon="pen-new-square" />
</Button>
2024-10-02 23:36:08 +00:00
</div>
2024-11-15 22:25:18 +00:00
{#key $profile?.about}
2025-02-11 23:37:50 +00:00
<Content event={{content: $profile?.about || "", tags: []}} hideMediaAtDepth={0} />
2024-10-03 21:32:55 +00:00
{/key}
2024-10-02 23:36:08 +00:00
</div>
2024-11-27 00:39:49 +00:00
{#if $session?.email}
<div class="card2 bg-alt col-4 shadow-xl">
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Email Address</p>
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
<Icon icon="user-rounded" />
<input readonly value={$session.email} class="grow" />
</label>
{/snippet}
{#snippet info()}
<p>
Your email and password can only be used to log into {PLATFORM_NAME}.
<Button class="link" onclick={startEject}>Start holding your own keys</Button>
2025-02-04 00:37:14 +00:00
</p>
{/snippet}
2024-11-27 00:39:49 +00:00
</FieldInline>
</div>
{/if}
2024-11-15 23:16:06 +00:00
<div class="card2 bg-alt col-4 shadow-xl">
2024-11-15 22:25:18 +00:00
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
2025-03-04 18:58:14 +00:00
<p class="flex items-center gap-3">
<Icon icon="key" />
Public Key
</p>
2025-02-04 00:37:14 +00:00
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center justify-between gap-2">
<div class="row-2 flex-grow items-center">
<Icon icon="link-round" />
<input readonly class="ellipsize flex-grow" value={$session?.pubkey} />
</div>
<Button class="flex items-center" onclick={copyNpub}>
<Icon icon="copy" />
</Button>
</label>
2025-02-04 00:37:14 +00:00
{/snippet}
{#snippet info()}
<p>
Your public key is your nostr user identifier. It also allows other people to authenticate
your messages.
</p>
{/snippet}
</FieldInline>
{#if $session?.method === "nip01"}
<FieldInline>
{#snippet label()}
2025-03-04 18:58:14 +00:00
<p class="flex items-center gap-3">
<Icon icon="key" />
Private Key
</p>
2025-02-04 00:37:14 +00:00
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
<Icon icon="link-round" />
<input readonly value={$session.secret} class="grow" type="password" />
<Button class="flex items-center" onclick={copyNsec}>
2025-02-04 00:37:14 +00:00
<Icon icon="copy" />
</Button>
</label>
{/snippet}
{#snippet info()}
<p>Your private key is your nostr password. Keep this somewhere safe!</p>
{/snippet}
2024-11-15 22:25:18 +00:00
</FieldInline>
{/if}
</div>
2025-03-20 16:38:57 +00:00
<Alerts />
<div class="card2 bg-alt shadow-xl">
<div class="flex items-center justify-between">
2025-03-04 18:58:14 +00:00
<strong class="flex items-center gap-3">
<Icon icon="settings" />
Advanced
</strong>
<Button onclick={() => (showAdvanced = !showAdvanced)}>
{#if showAdvanced}
<Icon icon="alt-arrow-down" />
{:else}
<Icon icon="alt-arrow-up" />
{/if}
</Button>
</div>
{#if showAdvanced}
2025-03-04 18:58:14 +00:00
<div transition:slideAndFade class="flex flex-col gap-2 pt-4">
<Button class="btn btn-outline btn-error" onclick={startDelete}>
<Icon icon="trash-bin-2" />
Delete your profile
</Button>
</div>
{/if}
2025-02-14 23:59:20 +00:00
</div>
2024-10-02 23:36:08 +00:00
</div>