mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Improve forms for entering invite codes
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
# 1.0.5
|
# 1.0.5
|
||||||
|
|
||||||
* Add better theming support
|
* Add better theming support
|
||||||
|
* Improve forms for entering invite codes
|
||||||
|
|
||||||
# 1.0.4
|
# 1.0.4
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex pr-3">
|
<div class="flex pr-3">
|
||||||
{#each props.pubkeys.slice(0, 15) as pubkey (pubkey)}
|
{#each props.pubkeys.toSorted().slice(0, 15) as pubkey (pubkey)}
|
||||||
<div class="z-feature -mr-3 inline-block">
|
<div class="z-feature -mr-3 inline-block">
|
||||||
<ProfileCircle class="h-8 w-8 bg-base-300" {pubkey} {...props} />
|
<ProfileCircle class="h-8 w-8 bg-base-300" {pubkey} {...props} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
84
src/app/components/SpaceAccessRequest.svelte
Normal file
84
src/app/components/SpaceAccessRequest.svelte
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {displayUrl} from "@welshman/lib"
|
||||||
|
import {Pool, AuthStatus} from "@welshman/net"
|
||||||
|
import {preventDefault} from "@lib/html"
|
||||||
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import Field from "@lib/components/Field.svelte"
|
||||||
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||||
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||||
|
import SpaceJoinConfirm, {confirmSpaceJoin} from "@app/components/SpaceJoinConfirm.svelte"
|
||||||
|
import {pushToast} from "@app/toast"
|
||||||
|
import {pushModal} from "@app/modal"
|
||||||
|
import {attemptRelayAccess} from "@app/commands"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const {url}: Props = $props()
|
||||||
|
|
||||||
|
const back = () => history.back()
|
||||||
|
|
||||||
|
const joinRelay = async () => {
|
||||||
|
const error = await attemptRelayAccess(url, claim)
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return pushToast({theme: "error", message: error, timeout: 30_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
const socket = Pool.get().get(url)
|
||||||
|
|
||||||
|
if (socket.auth.status === AuthStatus.None) {
|
||||||
|
pushModal(SpaceJoinConfirm, {url}, {replaceState: true})
|
||||||
|
} else {
|
||||||
|
await confirmSpaceJoin(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const join = async () => {
|
||||||
|
loading = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
await joinRelay()
|
||||||
|
} finally {
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let claim = $state("")
|
||||||
|
let loading = $state(false)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form class="column gap-4" onsubmit={preventDefault(join)}>
|
||||||
|
<ModalHeader>
|
||||||
|
{#snippet title()}
|
||||||
|
<div>Request Access</div>
|
||||||
|
{/snippet}
|
||||||
|
{#snippet info()}
|
||||||
|
<div>Enter an invite code below to request access to {displayUrl(url)}.</div>
|
||||||
|
{/snippet}
|
||||||
|
</ModalHeader>
|
||||||
|
<Field>
|
||||||
|
{#snippet label()}
|
||||||
|
<p>Invite code*</p>
|
||||||
|
{/snippet}
|
||||||
|
{#snippet input()}
|
||||||
|
<label class="input input-bordered flex w-full items-center gap-2">
|
||||||
|
<Icon icon="link-round" />
|
||||||
|
<input bind:value={claim} class="grow" type="text" />
|
||||||
|
</label>
|
||||||
|
{/snippet}
|
||||||
|
</Field>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button class="btn btn-link" onclick={back}>
|
||||||
|
<Icon icon="alt-arrow-left" />
|
||||||
|
Go back
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" class="btn btn-primary" disabled={loading}>
|
||||||
|
<Spinner {loading}>Join Space</Spinner>
|
||||||
|
<Icon icon="alt-arrow-right" />
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</form>
|
||||||
@@ -1,49 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {displayRelayUrl} from "@welshman/util"
|
import {displayRelayUrl} from "@welshman/util"
|
||||||
import {parse, renderAsHtml} from "@welshman/content"
|
import {parse, renderAsHtml} from "@welshman/content"
|
||||||
import Spinner from "@lib/components/Spinner.svelte"
|
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import {preventDefault} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
import {ucFirst} from "@lib/util"
|
import {ucFirst} from "@lib/util"
|
||||||
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 {pushToast} from "@app/toast"
|
import SpaceAccessRequest from "@app/components/SpaceAccessRequest.svelte"
|
||||||
import {clearModals} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {attemptRelayAccess} from "@app/commands"
|
|
||||||
|
|
||||||
const {url, error} = $props()
|
const {url, error} = $props()
|
||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const joinRelay = async () => {
|
const requestAccess = () => pushModal(SpaceAccessRequest, {url})
|
||||||
const error = await attemptRelayAccess(url)
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return pushToast({theme: "error", message: error})
|
|
||||||
}
|
|
||||||
|
|
||||||
pushToast({
|
|
||||||
message: "You have successfully joined the space!",
|
|
||||||
})
|
|
||||||
|
|
||||||
clearModals()
|
|
||||||
}
|
|
||||||
|
|
||||||
const join = async () => {
|
|
||||||
loading = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
await joinRelay()
|
|
||||||
} finally {
|
|
||||||
loading = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let loading = $state(false)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form class="column gap-4" onsubmit={preventDefault(join)}>
|
<form class="column gap-4" onsubmit={preventDefault(requestAccess)}>
|
||||||
<ModalHeader>
|
<ModalHeader>
|
||||||
{#snippet title()}
|
{#snippet title()}
|
||||||
<div>Access Error</div>
|
<div>Access Error</div>
|
||||||
@@ -63,8 +37,8 @@
|
|||||||
<Icon icon="alt-arrow-left" />
|
<Icon icon="alt-arrow-left" />
|
||||||
Go back
|
Go back
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" class="btn btn-primary" disabled={loading}>
|
<Button type="submit" class="btn btn-primary">
|
||||||
<Spinner {loading}>Request Access</Spinner>
|
Request Access
|
||||||
<Icon icon="alt-arrow-right" />
|
<Icon icon="alt-arrow-right" />
|
||||||
</Button>
|
</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {tryCatch} from "@welshman/lib"
|
import {tryCatch, first, removeNil} from "@welshman/lib"
|
||||||
import {isRelayUrl, normalizeRelayUrl} from "@welshman/util"
|
import {isRelayUrl, normalizeRelayUrl} from "@welshman/util"
|
||||||
import {Pool, AuthStatus} from "@welshman/net"
|
import {Pool, AuthStatus} from "@welshman/net"
|
||||||
import {preventDefault} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
@@ -17,21 +17,36 @@
|
|||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const joinRelay = async (invite: string) => {
|
const joinRelay = async () => {
|
||||||
const [raw, claim] = invite.split("|")
|
const promises: Promise<string | undefined>[] = []
|
||||||
const url = normalizeRelayUrl(raw)
|
|
||||||
const error = await attemptRelayAccess(url, claim)
|
const [rawUrl, rawClaim] = url.split("|")
|
||||||
|
const normalizedUrl = normalizeRelayUrl(rawUrl)
|
||||||
|
|
||||||
|
if (claim) {
|
||||||
|
promises.push(attemptRelayAccess(normalizedUrl, claim))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rawClaim) {
|
||||||
|
promises.push(attemptRelayAccess(normalizedUrl, rawClaim))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (promises.length === 0) {
|
||||||
|
promises.push(attemptRelayAccess(normalizedUrl, ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = first(removeNil(await Promise.all(promises)))
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return pushToast({theme: "error", message: error, timeout: 30_000})
|
return pushToast({theme: "error", message: error, timeout: 30_000})
|
||||||
}
|
}
|
||||||
|
|
||||||
const socket = Pool.get().get(url)
|
const socket = Pool.get().get(normalizedUrl)
|
||||||
|
|
||||||
if (socket.auth.status === AuthStatus.None) {
|
if (socket.auth.status === AuthStatus.None) {
|
||||||
pushModal(SpaceJoinConfirm, {url}, {replaceState: true})
|
pushModal(SpaceJoinConfirm, {url: normalizedUrl}, {replaceState: true})
|
||||||
} else {
|
} else {
|
||||||
await confirmSpaceJoin(url)
|
await confirmSpaceJoin(normalizedUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,13 +54,14 @@
|
|||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await joinRelay(url)
|
await joinRelay()
|
||||||
} finally {
|
} finally {
|
||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = $state("")
|
let url = $state("")
|
||||||
|
let claim = $state("")
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
|
|
||||||
const linkIsValid = $derived(
|
const linkIsValid = $derived(
|
||||||
@@ -59,12 +75,12 @@
|
|||||||
<div>Join a Space</div>
|
<div>Join a Space</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet info()}
|
{#snippet info()}
|
||||||
<div>Enter an invite code below to join an existing space.</div>
|
<div>Enter a relay URL below to join an existing space.</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<Field>
|
<Field>
|
||||||
{#snippet label()}
|
{#snippet label()}
|
||||||
<p>Invite code*</p>
|
<p>Relay URL*</p>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet input()}
|
{#snippet input()}
|
||||||
<label class="input input-bordered flex w-full items-center gap-2">
|
<label class="input input-bordered flex w-full items-center gap-2">
|
||||||
@@ -74,11 +90,25 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet info()}
|
{#snippet info()}
|
||||||
<p>
|
<p>
|
||||||
You can also directly join any relay by entering its URL here.
|
Enter the URL of the relay that hosts the space you'd like to join.
|
||||||
<Button class="link" onclick={() => pushModal(InfoRelay)}>What is a relay?</Button>
|
<Button class="link" onclick={() => pushModal(InfoRelay)}>What is a relay?</Button>
|
||||||
</p>
|
</p>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Field>
|
</Field>
|
||||||
|
<Field>
|
||||||
|
{#snippet label()}
|
||||||
|
<p>Invite Code (optional)</p>
|
||||||
|
{/snippet}
|
||||||
|
{#snippet input()}
|
||||||
|
<label class="input input-bordered flex w-full items-center gap-2">
|
||||||
|
<Icon icon="ticket" />
|
||||||
|
<input bind:value={claim} class="grow" type="text" />
|
||||||
|
</label>
|
||||||
|
{/snippet}
|
||||||
|
{#snippet info()}
|
||||||
|
<p>If you have an invite code, enter it here to get access.</p>
|
||||||
|
{/snippet}
|
||||||
|
</Field>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button class="btn btn-link" onclick={back}>
|
<Button class="btn btn-link" onclick={back}>
|
||||||
<Icon icon="alt-arrow-left" />
|
<Icon icon="alt-arrow-left" />
|
||||||
|
|||||||
4
src/assets/icons/Ticket.svg
Normal file
4
src/assets/icons/Ticket.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.0 KiB |
@@ -74,6 +74,7 @@
|
|||||||
import SettingsMinimalistic from "@assets/icons/Settings Minimalistic.svg?dataurl"
|
import SettingsMinimalistic from "@assets/icons/Settings Minimalistic.svg?dataurl"
|
||||||
import Station from "@assets/icons/Station.svg?dataurl"
|
import Station from "@assets/icons/Station.svg?dataurl"
|
||||||
import TagHorizontal from "@assets/icons/Tag Horizontal.svg?dataurl"
|
import TagHorizontal from "@assets/icons/Tag Horizontal.svg?dataurl"
|
||||||
|
import Ticket from "@assets/icons/Ticket.svg?dataurl"
|
||||||
import ShareCircle from "@assets/icons/Share Circle.svg?dataurl"
|
import ShareCircle from "@assets/icons/Share Circle.svg?dataurl"
|
||||||
import ShopMinimalistic from "@assets/icons/Shop Minimalistic.svg?dataurl"
|
import ShopMinimalistic from "@assets/icons/Shop Minimalistic.svg?dataurl"
|
||||||
import SmileCircle from "@assets/icons/Smile Circle.svg?dataurl"
|
import SmileCircle from "@assets/icons/Smile Circle.svg?dataurl"
|
||||||
@@ -171,6 +172,7 @@
|
|||||||
"settings-minimalistic": SettingsMinimalistic,
|
"settings-minimalistic": SettingsMinimalistic,
|
||||||
station: Station,
|
station: Station,
|
||||||
"tag-horizontal": TagHorizontal,
|
"tag-horizontal": TagHorizontal,
|
||||||
|
ticket: Ticket,
|
||||||
"trash-bin-2": TrashBin2,
|
"trash-bin-2": TrashBin2,
|
||||||
"ufo-3": UFO3,
|
"ufo-3": UFO3,
|
||||||
"square-share-line": SquareShareLine,
|
"square-share-line": SquareShareLine,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type {Snippet} from 'svelte'
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
interface Props {
|
|
||||||
children?: import("svelte").Snippet
|
type Props = {
|
||||||
|
children?: Snippet
|
||||||
}
|
}
|
||||||
|
|
||||||
const {children}: Props = $props()
|
const {children}: Props = $props()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type {Snippet} from "svelte"
|
||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
import {ago, WEEK} from "@welshman/lib"
|
import {ago, WEEK} from "@welshman/lib"
|
||||||
@@ -16,8 +17,9 @@
|
|||||||
import {decodeRelay, userRoomsByUrl} from "@app/state"
|
import {decodeRelay, userRoomsByUrl} from "@app/state"
|
||||||
import {pullConservatively} from "@app/requests"
|
import {pullConservatively} from "@app/requests"
|
||||||
import {notifications} from "@app/notifications"
|
import {notifications} from "@app/notifications"
|
||||||
interface Props {
|
|
||||||
children?: import("svelte").Snippet
|
type Props = {
|
||||||
|
children?: Snippet
|
||||||
}
|
}
|
||||||
|
|
||||||
const {children}: Props = $props()
|
const {children}: Props = $props()
|
||||||
|
|||||||
Reference in New Issue
Block a user