Clean up logout and chat

This commit is contained in:
Jonathan Staab 2022-11-26 16:42:06 -08:00
parent 98313091d1
commit 4f313a3617
7 changed files with 39 additions and 20 deletions

View File

@ -10,7 +10,7 @@
import {globalHistory} from "svelte-routing/src/history"
import {hasParent} from 'src/util/html'
import {store as toast} from "src/state/toast"
import {modal} from "src/state/app"
import {modal, logout} from "src/state/app"
import {user} from 'src/state/user'
import NoteDetail from "src/partials/NoteDetail.svelte"
import NotFound from "src/routes/NotFound.svelte"
@ -47,14 +47,6 @@
modal.set(null)
})
})
// Give the animation a moment to finish
const logout = () => {
setTimeout(() => {
user.set(null)
navigate("/login")
}, 200)
}
</script>
<svelte:body on:keydown={e => e.key === 'Escape' && modal.set(null)} />

View File

@ -7,6 +7,6 @@
<div
class="overflow-hidden w-4 h-4 rounded-full bg-cover bg-center shrink-0 border border-solid border-white"
style="background-image: url({user.picture})" />
<span class="text-lg font-bold">{user.name}</span>
<span class="text-lg font-bold">{user.name || ''}</span>
</a>
{/if}

View File

@ -4,6 +4,7 @@
import {navigate} from 'svelte-routing'
import {prop, last} from 'ramda'
import {switcherFn} from 'hurdak/src/core'
import {formatTimestamp} from 'src/util/misc'
import UserBadge from 'src/partials/UserBadge.svelte'
import {channels} from 'src/state/nostr'
import {rooms, accounts, ensureAccounts} from 'src/state/app'
@ -39,6 +40,10 @@
}
onMount(() => {
if (!$user) {
navigate('/login')
}
const isVisible = $el => {
const bodyRect = document.body.getBoundingClientRect()
const {top, height} = $el.getBoundingClientRect()
@ -47,7 +52,11 @@
}
return channels.watcher.sub({
filter: {kinds: [42, 43, 44], '#e': [room]},
filter: {
limit: 100,
kinds: [42, 43, 44],
'#e': [room],
},
cb: e => {
switcherFn(e.kind, {
42: () => {
@ -103,7 +112,10 @@
{#each annotatedMessages as m}
<li in:fly={{y: 20}} class="py-1 chat-message">
{#if m.showAccount}
<UserBadge user={m.account} />
<div class="flex gap-4 items-center justify-between">
<UserBadge user={m.account} />
<p class="text-sm text-light">{formatTimestamp(m.created_at)}</p>
</div>
{/if}
<div class="ml-6">{m.content}</div>
</li>
@ -118,7 +130,7 @@
<div class="w-full">
<div class="flex items-center justify-between w-full">
<div class="text-lg font-bold">{$rooms[room].name}</div>
{#if $rooms[room].pubkey === $user.pubkey}
{#if $rooms[room].pubkey === $user?.pubkey}
<small class="cursor-pointer" on:click={edit}>
<i class="fa-solid fa-edit" /> Edit
</small>

View File

@ -6,6 +6,7 @@
import Input from "src/partials/Input.svelte"
import Anchor from "src/partials/Anchor.svelte"
import {user} from "src/state/user"
import {logout} from "src/state/app"
import toast from "src/state/toast"
const keypairUrl = 'https://www.cloudflare.com/learning/ssl/how-does-public-key-encryption-work/'
@ -17,11 +18,6 @@
toast.show("info", `Your ${type} key has been copied to the clipboard.`)
}
const logout = () => {
navigate("/login")
user.set(null)
}
onMount(async () => {
if (!$user) {
return navigate("/login")

View File

@ -6,6 +6,7 @@
import Input from "src/partials/Input.svelte"
import toast from "src/state/toast"
import {dispatch} from "src/state/dispatch"
import {relays} from "src/state/nostr"
let privKey = ''
@ -25,7 +26,13 @@
} else {
const {found} = await dispatch("account/init", privKey)
await navigate(found ? `/` : '/settings/profile')
if ($relays.length === 0) {
navigate('/settings/relays')
} else if (found) {
navigate('/')
} else {
navigate('/settings/profile')
}
}
}
</script>

View File

@ -58,6 +58,8 @@
</div>
{/each}
</li>
{:else}
<li class="py-4">This user hasn't posted any notes.</li>
{/each}
</ul>
</div>

View File

@ -1,10 +1,11 @@
import {prop, uniq, sortBy, uniqBy, find, last, groupBy} from 'ramda'
import {debounce} from 'throttle-debounce'
import {writable, derived, get} from 'svelte/store'
import {navigate} from "svelte-routing"
import {switcherFn, noop, ensurePlural} from 'hurdak/lib/hurdak'
import {getLocalJson, setLocalJson, now, timedelta} from "src/util/misc"
import {user} from 'src/state/user'
import {channels} from 'src/state/nostr'
import {channels, relays} from 'src/state/nostr'
export const modal = writable(null)
@ -26,6 +27,15 @@ user.subscribe($user => {
}
})
export const logout = () => {
// Give any animations a moment to finish
setTimeout(() => {
user.set(null)
relays.set([])
navigate("/login")
}, 200)
}
// Utils
export const ensureAccounts = async pubkeys => {