forked from coracle/flotilla
Refine space join dialogs and discover page
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
onchange src -ik -- npx svelte-kit sync &
|
|
||||||
|
|
||||||
onchange src -ik -- bash -c 'unbuffer npx svelte-check --tsconfig ./tsconfig.json | less -R' &
|
|
||||||
|
|
||||||
wait
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {dissoc} from "@welshman/lib"
|
import {debounce} from "throttle-debounce"
|
||||||
|
import {dissoc, maybe} from "@welshman/lib"
|
||||||
import {goto} from "$app/navigation"
|
import {goto} from "$app/navigation"
|
||||||
import {preventDefault} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
import {slideAndFade} from "@lib/transition"
|
import {slideAndFade} from "@lib/transition"
|
||||||
@@ -10,6 +11,8 @@
|
|||||||
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
||||||
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
|
import Scanner from "@lib/components/Scanner.svelte"
|
||||||
|
import QrCode from "@assets/icons/qr-code.svg?dataurl"
|
||||||
import Modal from "@lib/components/Modal.svelte"
|
import Modal from "@lib/components/Modal.svelte"
|
||||||
import ModalBody from "@lib/components/ModalBody.svelte"
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
||||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||||
@@ -17,10 +20,17 @@
|
|||||||
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
||||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||||
import RelaySummary from "@app/components/RelaySummary.svelte"
|
import RelaySummary from "@app/components/RelaySummary.svelte"
|
||||||
|
import SpaceJoinSettings from "@app/components/SpaceJoinSettings.svelte"
|
||||||
import {pushToast} from "@app/util/toast"
|
import {pushToast} from "@app/util/toast"
|
||||||
import {makeSpacePath} from "@app/util/routes"
|
import {makeSpacePath} from "@app/util/routes"
|
||||||
import {relaysMostlyRestricted, parseInviteLink} from "@app/core/state"
|
import {Push} from "@app/util/notifications"
|
||||||
import {attemptRelayAccess, addSpaceMembership, broadcastUserData} from "@app/core/commands"
|
import {relaysMostlyRestricted, notificationSettings, parseInviteLink} from "@app/core/state"
|
||||||
|
import {
|
||||||
|
attemptRelayAccess,
|
||||||
|
addSpaceMembership,
|
||||||
|
broadcastUserData,
|
||||||
|
setSpaceNotifications,
|
||||||
|
} from "@app/core/commands"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
invite: string
|
invite: string
|
||||||
@@ -29,21 +39,42 @@
|
|||||||
|
|
||||||
let {invite = "", back = () => history.back()}: Props = $props()
|
let {invite = "", back = () => history.back()}: Props = $props()
|
||||||
|
|
||||||
|
const toggleScanner = () => {
|
||||||
|
showScanner = !showScanner
|
||||||
|
}
|
||||||
|
|
||||||
|
const onScan = debounce(1000, async (data: string) => {
|
||||||
|
showScanner = false
|
||||||
|
invite = data
|
||||||
|
})
|
||||||
|
|
||||||
const joinRelay = async () => {
|
const joinRelay = async () => {
|
||||||
const {url, claim} = inviteData!
|
const {url, claim} = inviteData!
|
||||||
|
|
||||||
const error = await attemptRelayAccess(url, claim)
|
error = await attemptRelayAccess(url, claim)
|
||||||
|
|
||||||
if (error) {
|
if (!error) {
|
||||||
return pushToast({theme: "error", message: error, timeout: 30_000})
|
if (notifications) {
|
||||||
|
if (!notificationSettings.get().push) {
|
||||||
|
await setSpaceNotifications(url, true)
|
||||||
|
} else {
|
||||||
|
const permissions = await Push.request()
|
||||||
|
|
||||||
|
if (permissions === "granted") {
|
||||||
|
await setSpaceNotifications(url, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await setSpaceNotifications(url, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
await addSpaceMembership(url)
|
||||||
|
await goto(makeSpacePath(url), {replaceState: true})
|
||||||
|
|
||||||
|
broadcastUserData([url])
|
||||||
|
relaysMostlyRestricted.update(dissoc(url))
|
||||||
|
pushToast({message: "Welcome to the space!"})
|
||||||
}
|
}
|
||||||
|
|
||||||
await addSpaceMembership(url)
|
|
||||||
await goto(makeSpacePath(url), {replaceState: true})
|
|
||||||
|
|
||||||
broadcastUserData([url])
|
|
||||||
relaysMostlyRestricted.update(dissoc(url))
|
|
||||||
pushToast({message: "Welcome to the space!"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const join = async () => {
|
const join = async () => {
|
||||||
@@ -56,7 +87,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let error = $state(maybe<string>())
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
|
let showScanner = $state(false)
|
||||||
|
let notifications = $state(true)
|
||||||
|
|
||||||
const inviteData = $derived(parseInviteLink(invite))
|
const inviteData = $derived(parseInviteLink(invite))
|
||||||
</script>
|
</script>
|
||||||
@@ -76,15 +110,22 @@
|
|||||||
<label class="input input-bordered flex w-full items-center gap-2">
|
<label class="input input-bordered flex w-full items-center gap-2">
|
||||||
<Icon icon={LinkRound} />
|
<Icon icon={LinkRound} />
|
||||||
<input bind:value={invite} class="grow" type="text" />
|
<input bind:value={invite} class="grow" type="text" />
|
||||||
|
<Button onclick={toggleScanner} class="center">
|
||||||
|
<Icon icon={QrCode} />
|
||||||
|
</Button>
|
||||||
</label>
|
</label>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Field>
|
</Field>
|
||||||
|
{#if showScanner}
|
||||||
|
<Scanner onscan={onScan} />
|
||||||
|
{/if}
|
||||||
{#if inviteData}
|
{#if inviteData}
|
||||||
<div class="-my-4">
|
<div class="-my-4">
|
||||||
<div transition:slideAndFade class="flex flex-col gap-4 py-4">
|
<div transition:slideAndFade class="flex flex-col gap-4 py-4">
|
||||||
<div class="card2 bg-alt flex flex-col gap-4">
|
<div class="card2 bg-alt flex flex-col gap-4">
|
||||||
<p class="opacity-75">You're about to join:</p>
|
<p class="opacity-75">You're about to join:</p>
|
||||||
<RelaySummary url={inviteData.url} />
|
<RelaySummary url={inviteData.url} />
|
||||||
|
<SpaceJoinSettings url={inviteData.url} bind:error bind:notifications />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
import {goto} from "$app/navigation"
|
import {goto} from "$app/navigation"
|
||||||
import {dissoc} from "@welshman/lib"
|
import {dissoc, maybe} from "@welshman/lib"
|
||||||
import {preventDefault} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
||||||
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
||||||
import DangerTriangle from "@assets/icons/danger-triangle.svg?dataurl"
|
|
||||||
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 Spinner from "@lib/components/Spinner.svelte"
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import Modal from "@lib/components/Modal.svelte"
|
import Modal from "@lib/components/Modal.svelte"
|
||||||
import ModalBody from "@lib/components/ModalBody.svelte"
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
||||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||||
import StatusIndicator from "@lib/components/StatusIndicator.svelte"
|
|
||||||
import RelaySummary from "@app/components/RelaySummary.svelte"
|
import RelaySummary from "@app/components/RelaySummary.svelte"
|
||||||
import SocketStatusIndicator from "@app/components/SocketStatusIndicator.svelte"
|
|
||||||
import SpaceAccessRequest from "@app/components/SpaceAccessRequest.svelte"
|
import SpaceAccessRequest from "@app/components/SpaceAccessRequest.svelte"
|
||||||
|
import SpaceJoinSettings from "@app/components/SpaceJoinSettings.svelte"
|
||||||
import {
|
import {
|
||||||
attemptRelayAccess,
|
attemptRelayAccess,
|
||||||
addSpaceMembership,
|
addSpaceMembership,
|
||||||
@@ -72,7 +70,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let error: string | undefined = $state()
|
let error = $state(maybe<string>())
|
||||||
let loading = $state(true)
|
let loading = $state(true)
|
||||||
let notifications = $state(true)
|
let notifications = $state(true)
|
||||||
|
|
||||||
@@ -85,33 +83,7 @@
|
|||||||
<Modal tag="form" onsubmit={preventDefault(join)}>
|
<Modal tag="form" onsubmit={preventDefault(join)}>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<RelaySummary {url} />
|
<RelaySummary {url} />
|
||||||
<div class="card2 card2-sm bg-alt">
|
<SpaceJoinSettings {url} bind:error bind:notifications />
|
||||||
<div class="flex justify-between gap-12">
|
|
||||||
<div class="col-1">
|
|
||||||
<strong>Enable notifications for this space</strong>
|
|
||||||
<p class="text-xs opacity-75">
|
|
||||||
Get notified about new activity in this space. You can change this later in settings.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<input type="checkbox" class="toggle toggle-primary" bind:checked={notifications} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card2 card2-sm bg-alt flex flex-col gap-2">
|
|
||||||
<div class="flex justify-between">
|
|
||||||
<strong>Connection Status</strong>
|
|
||||||
{#if error}
|
|
||||||
<StatusIndicator class="bg-error">Error</StatusIndicator>
|
|
||||||
{:else}
|
|
||||||
<SocketStatusIndicator {url} />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{#if error}
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Icon icon={DangerTriangle} />
|
|
||||||
<p class="text-sm opacity-75">{error}</p>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button class="btn btn-link" onclick={back} disabled={loading}>
|
<Button class="btn btn-link" onclick={back} disabled={loading}>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import DangerTriangle from "@assets/icons/danger-triangle.svg?dataurl"
|
||||||
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
|
import StatusIndicator from "@lib/components/StatusIndicator.svelte"
|
||||||
|
import SocketStatusIndicator from "@app/components/SocketStatusIndicator.svelte"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
url: string
|
||||||
|
error?: string
|
||||||
|
notifications: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
let {url, error = $bindable(), notifications = $bindable()}: Props = $props()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="card2 card2-sm bg-alt">
|
||||||
|
<div class="flex justify-between gap-12">
|
||||||
|
<div class="col-1">
|
||||||
|
<strong>Enable notifications for this space</strong>
|
||||||
|
<p class="text-xs opacity-75">
|
||||||
|
Get notified about new activity in this space. You can change this later in settings.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<input type="checkbox" class="toggle toggle-primary" bind:checked={notifications} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card2 card2-sm bg-alt flex flex-col gap-2">
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<strong>Connection Status</strong>
|
||||||
|
{#if error}
|
||||||
|
<StatusIndicator class="bg-error">Error</StatusIndicator>
|
||||||
|
{:else}
|
||||||
|
<SocketStatusIndicator {url} />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{#if error}
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Icon icon={DangerTriangle} />
|
||||||
|
<p class="text-sm opacity-75">{error}</p>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -8,7 +8,7 @@ const FALLBACK_APP_NAME = "Flotilla"
|
|||||||
const staticTitles = new Map<string, string>([
|
const staticTitles = new Map<string, string>([
|
||||||
["/", "Redirecting"],
|
["/", "Redirecting"],
|
||||||
["/home", "Home"],
|
["/home", "Home"],
|
||||||
["/discover", "Discover Spaces"],
|
["/discover", "Join a Space"],
|
||||||
["/spaces", "Your Spaces"],
|
["/spaces", "Your Spaces"],
|
||||||
["/spaces/create", "Create a Space"],
|
["/spaces/create", "Create a Space"],
|
||||||
["/spaces/[relay]", "Space"],
|
["/spaces/[relay]", "Space"],
|
||||||
|
|||||||
@@ -1,39 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
import {derived as _derived} from "svelte/store"
|
import {derived as _derived} from "svelte/store"
|
||||||
import {debounce} from "throttle-debounce"
|
|
||||||
import {dec, sleep} from "@welshman/lib"
|
import {dec, sleep} from "@welshman/lib"
|
||||||
import type {RelayProfile} from "@welshman/util"
|
import type {RelayProfile} from "@welshman/util"
|
||||||
import {throttled} from "@welshman/store"
|
import {throttled} from "@welshman/store"
|
||||||
import {relays, createSearch} from "@welshman/app"
|
import {relays, createSearch} from "@welshman/app"
|
||||||
import {createScroller} from "@lib/html"
|
import {createScroller} from "@lib/html"
|
||||||
import QrCode from "@assets/icons/qr-code.svg?dataurl"
|
|
||||||
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
||||||
|
import Login from "@assets/icons/login-3.svg?dataurl"
|
||||||
import Magnifier from "@assets/icons/magnifier.svg?dataurl"
|
import Magnifier from "@assets/icons/magnifier.svg?dataurl"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Page from "@lib/components/Page.svelte"
|
import Page from "@lib/components/Page.svelte"
|
||||||
import Scanner from "@lib/components/Scanner.svelte"
|
|
||||||
import Spinner from "@lib/components/Spinner.svelte"
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
|
import Divider from "@lib/components/Divider.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import CardButton from "@lib/components/CardButton.svelte"
|
||||||
|
import Link from "@lib/components/Link.svelte"
|
||||||
import PageHeader from "@lib/components/PageHeader.svelte"
|
import PageHeader from "@lib/components/PageHeader.svelte"
|
||||||
import ContentSearch from "@lib/components/ContentSearch.svelte"
|
import ContentSearch from "@lib/components/ContentSearch.svelte"
|
||||||
import SpaceAdd from "@app/components/SpaceAdd.svelte"
|
|
||||||
import SpaceInviteAccept from "@app/components/SpaceInviteAccept.svelte"
|
import SpaceInviteAccept from "@app/components/SpaceInviteAccept.svelte"
|
||||||
import RelaySummary from "@app/components/RelaySummary.svelte"
|
import RelaySummary from "@app/components/RelaySummary.svelte"
|
||||||
import SpaceJoin from "@app/components/SpaceJoin.svelte"
|
import SpaceJoin from "@app/components/SpaceJoin.svelte"
|
||||||
import {groupListPubkeysByUrl, parseInviteLink} from "@app/core/state"
|
import {groupListPubkeysByUrl, parseInviteLink} from "@app/core/state"
|
||||||
import {pushModal} from "@app/util/modal"
|
import {pushModal} from "@app/util/modal"
|
||||||
|
|
||||||
const openMenu = () => pushModal(SpaceAdd, {hideDiscover: true})
|
const startJoin = () => pushModal(SpaceInviteAccept)
|
||||||
|
|
||||||
const toggleScanner = () => {
|
|
||||||
showScanner = !showScanner
|
|
||||||
}
|
|
||||||
|
|
||||||
const onScan = debounce(1000, async (data: string) => {
|
|
||||||
showScanner = false
|
|
||||||
pushModal(SpaceInviteAccept, {invite: data})
|
|
||||||
})
|
|
||||||
|
|
||||||
const relaySearch = _derived(throttled(1000, relays), $relays => {
|
const relaySearch = _derived(throttled(1000, relays), $relays => {
|
||||||
const options = $relays.filter(r => $groupListPubkeysByUrl.has(r.url))
|
const options = $relays.filter(r => $groupListPubkeysByUrl.has(r.url))
|
||||||
@@ -64,7 +55,6 @@
|
|||||||
|
|
||||||
let term = $state("")
|
let term = $state("")
|
||||||
let limit = $state(20)
|
let limit = $state(20)
|
||||||
let showScanner = $state(false)
|
|
||||||
let element: Element
|
let element: Element
|
||||||
|
|
||||||
const options = $derived($relaySearch.searchOptions(term).filter(r => r.url !== inviteData?.url))
|
const options = $derived($relaySearch.searchOptions(term).filter(r => r.url !== inviteData?.url))
|
||||||
@@ -90,36 +80,51 @@
|
|||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<PageHeader>
|
<PageHeader>
|
||||||
{#snippet title()}
|
{#snippet title()}
|
||||||
Discover Spaces
|
Join a Space
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet info()}
|
{#snippet info()}
|
||||||
Find communities all across the nostr network
|
Find communities all across the nostr network
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<div class="row-2 min-w-0 flex-grow items-center">
|
<div class="grid gap-3 sm:grid-cols-2">
|
||||||
<label class="input input-bordered flex flex-grow items-center gap-2">
|
<Button onclick={startJoin} class="w-full">
|
||||||
<Icon icon={Magnifier} />
|
<CardButton class="btn-primary w-full">
|
||||||
<input
|
{#snippet icon()}
|
||||||
bind:value={term}
|
<div><Icon icon={Login} size={7} /></div>
|
||||||
class="grow"
|
{/snippet}
|
||||||
type="text"
|
{#snippet title()}
|
||||||
placeholder="Search for spaces or paste invite link..." />
|
<div>Join with an invite</div>
|
||||||
<Button onclick={toggleScanner} class="center">
|
{/snippet}
|
||||||
<Icon icon={QrCode} />
|
{#snippet info()}
|
||||||
</Button>
|
<div>Paste a link and jump right in.</div>
|
||||||
</label>
|
{/snippet}
|
||||||
<Button class="btn btn-primary" onclick={openMenu}>
|
</CardButton>
|
||||||
<Icon icon={AddCircle} />
|
|
||||||
<span class="hidden sm:inline">Add Space</span>
|
|
||||||
</Button>
|
</Button>
|
||||||
|
<Link href="/spaces/create" class="w-full">
|
||||||
|
<CardButton class="btn-neutral w-full">
|
||||||
|
{#snippet icon()}
|
||||||
|
<div><Icon icon={AddCircle} size={7} /></div>
|
||||||
|
{/snippet}
|
||||||
|
{#snippet title()}
|
||||||
|
<div>Create a new space</div>
|
||||||
|
{/snippet}
|
||||||
|
{#snippet info()}
|
||||||
|
<div>Launch a place for your people.</div>
|
||||||
|
{/snippet}
|
||||||
|
</CardButton>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<Divider>Or</Divider>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<label class="input input-bordered flex items-center gap-2">
|
||||||
|
<Icon icon={Magnifier} />
|
||||||
|
<input bind:value={term} class="grow" type="text" placeholder="Search for spaces..." />
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
{#if showScanner}
|
|
||||||
<Scanner onscan={onScan} />
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet content()}
|
{#snippet content()}
|
||||||
<div class="col-2 scroll-container" bind:this={element}>
|
<div class="col-2" bind:this={element}>
|
||||||
{#if inviteData}
|
{#if inviteData}
|
||||||
{#key inviteData.url}
|
{#key inviteData.url}
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user