forked from coracle/flotilla
Switch to implicit state
This commit is contained in:
@@ -2,12 +2,14 @@
|
|||||||
import {nip19} from "nostr-tools"
|
import {nip19} from "nostr-tools"
|
||||||
import {goto} from "$app/navigation"
|
import {goto} from "$app/navigation"
|
||||||
import {ctx} from "@welshman/lib"
|
import {ctx} from "@welshman/lib"
|
||||||
|
import {toNostrURI} from "@welshman/util"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||||
import {roomsByUrl} from "@app/state"
|
import {roomsByUrl} from "@app/state"
|
||||||
import {makeRoomPath} from "@app/routes"
|
import {makeRoomPath} from "@app/routes"
|
||||||
|
import {setKey} from "@app/implicit"
|
||||||
|
|
||||||
export let url
|
export let url
|
||||||
export let event
|
export let event
|
||||||
@@ -17,7 +19,10 @@
|
|||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const onSubmit = () => goto(makeRoomPath(url, selection) + "?content=nostr:" + nevent)
|
const onSubmit = () => {
|
||||||
|
setKey('content', toNostrURI(nevent))
|
||||||
|
goto(makeRoomPath(url, selection), {replaceState: true})
|
||||||
|
}
|
||||||
|
|
||||||
const toggleRoom = (room: string) => {
|
const toggleRoom = (room: string) => {
|
||||||
selection = room === selection ? "" : room
|
selection = room === selection ? "" : room
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Use this for passing state between pages implicitly
|
||||||
|
const state = new Map<string, any>()
|
||||||
|
|
||||||
|
export const setKey = <T>(key: string, value: T) => state.set(key, value)
|
||||||
|
|
||||||
|
export const getKey = <T>(key: string) => state.get(key) as T | undefined
|
||||||
|
|
||||||
|
export const popKey = <T>(key: string) => {
|
||||||
|
const value: T | undefined = state.get(key)
|
||||||
|
|
||||||
|
state.delete(key)
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
@@ -38,9 +38,10 @@
|
|||||||
} from "@app/state"
|
} from "@app/state"
|
||||||
import {addRoomMembership, removeRoomMembership} from "@app/commands"
|
import {addRoomMembership, removeRoomMembership} from "@app/commands"
|
||||||
import {pushDrawer} from "@app/modal"
|
import {pushDrawer} from "@app/modal"
|
||||||
|
import {popKey} from "@app/implicit"
|
||||||
|
|
||||||
const {room = GENERAL} = $page.params
|
const {room = GENERAL} = $page.params
|
||||||
const {content = ""} = fromPairs(Array.from($page.url.searchParams))
|
const content = popKey<string>('content') || ""
|
||||||
const url = decodeRelay($page.params.relay)
|
const url = decodeRelay($page.params.relay)
|
||||||
const channel = deriveChannel(makeChannelId(url, room))
|
const channel = deriveChannel(makeChannelId(url, room))
|
||||||
const thunks = writable({} as Record<string, Thunk>)
|
const thunks = writable({} as Record<string, Thunk>)
|
||||||
|
|||||||
@@ -6,13 +6,16 @@
|
|||||||
import {deriveEvents} from "@welshman/store"
|
import {deriveEvents} from "@welshman/store"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Link from "@lib/components/Link.svelte"
|
import Link from "@lib/components/Link.svelte"
|
||||||
|
import PageBar from "@lib/components/PageBar.svelte"
|
||||||
import Spinner from "@lib/components/Spinner.svelte"
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Content from "@app/components/Content.svelte"
|
import Content from "@app/components/Content.svelte"
|
||||||
import NoteCard from "@app/components/NoteCard.svelte"
|
import NoteCard from "@app/components/NoteCard.svelte"
|
||||||
|
import MenuSpace from "@app/components/MenuSpace.svelte"
|
||||||
import ThreadActions from "@app/components/ThreadActions.svelte"
|
import ThreadActions from "@app/components/ThreadActions.svelte"
|
||||||
import ThreadReply from "@app/components/ThreadReply.svelte"
|
import ThreadReply from "@app/components/ThreadReply.svelte"
|
||||||
import {COMMENT, deriveEvent, decodeRelay} from "@app/state"
|
import {COMMENT, deriveEvent, decodeRelay} from "@app/state"
|
||||||
|
import {pushDrawer} from "@app/modal"
|
||||||
import {makeSpacePath} from "@app/routes"
|
import {makeSpacePath} from "@app/routes"
|
||||||
|
|
||||||
const {relay, id} = $page.params
|
const {relay, id} = $page.params
|
||||||
@@ -23,6 +26,8 @@
|
|||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
|
const openMenu = () => pushDrawer(MenuSpace, {url})
|
||||||
|
|
||||||
const openReply = () => {
|
const openReply = () => {
|
||||||
showReply = true
|
showReply = true
|
||||||
}
|
}
|
||||||
@@ -40,7 +45,7 @@
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative flex flex-col-reverse gap-3 p-2">
|
<div class="relative flex flex-col-reverse gap-3 px-2">
|
||||||
<div class="absolute left-[51px] top-20 h-[calc(100%-200px)] w-[2px] bg-neutral" />
|
<div class="absolute left-[51px] top-20 h-[calc(100%-200px)] w-[2px] bg-neutral" />
|
||||||
{#if $event}
|
{#if $event}
|
||||||
{#if !showReply}
|
{#if !showReply}
|
||||||
@@ -72,15 +77,19 @@
|
|||||||
<p>Failed to load thread.</p>
|
<p>Failed to load thread.</p>
|
||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex items-center justify-between">
|
<PageBar>
|
||||||
<Button class="mb-2 mt-5 flex items-center gap-2" on:click={back}>
|
<div slot="icon">
|
||||||
<Icon icon="alt-arrow-left" />
|
<Button class="btn btn-neutral btn-sm" on:click={back}>
|
||||||
Go back
|
<Icon icon="alt-arrow-left" />
|
||||||
</Button>
|
Go back
|
||||||
<Link href={makeSpacePath(url)}>
|
</Button>
|
||||||
@<span class="text-primary">{displayUrl(url)}</span>
|
</div>
|
||||||
</Link>
|
<div slot="action">
|
||||||
</div>
|
<Button on:click={openMenu} class="btn btn-neutral btn-sm md:hidden">
|
||||||
|
<Icon icon="menu-dots" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</PageBar>
|
||||||
</div>
|
</div>
|
||||||
{#if showReply}
|
{#if showReply}
|
||||||
<ThreadReply {url} event={$event} onClose={closeReply} onSubmit={closeReply} />
|
<ThreadReply {url} event={$event} onClose={closeReply} onSubmit={closeReply} />
|
||||||
|
|||||||
Reference in New Issue
Block a user