mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 02:47:06 +00:00
Support invite links on discover page
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Snippet} from "svelte"
|
import type {Snippet} from "svelte"
|
||||||
import {tryCatch, fromPairs} from "@welshman/lib"
|
|
||||||
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"
|
||||||
import {slideAndFade} from "@lib/transition"
|
import {slideAndFade} from "@lib/transition"
|
||||||
@@ -19,6 +17,7 @@
|
|||||||
import {pushToast} from "@app/util/toast"
|
import {pushToast} from "@app/util/toast"
|
||||||
import {pushModal} from "@app/util/modal"
|
import {pushModal} from "@app/util/modal"
|
||||||
import {attemptRelayAccess} from "@app/core/commands"
|
import {attemptRelayAccess} from "@app/core/commands"
|
||||||
|
import {parseInviteLink} from "@app/core/state"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
invite: string
|
invite: string
|
||||||
@@ -57,24 +56,7 @@
|
|||||||
|
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
|
|
||||||
const inviteData = $derived.by(
|
const inviteData = $derived(parseInviteLink(invite))
|
||||||
() =>
|
|
||||||
tryCatch(() => {
|
|
||||||
const {r: relay = "", c: claim = ""} = fromPairs(Array.from(new URL(invite).searchParams))
|
|
||||||
const url = normalizeRelayUrl(relay)
|
|
||||||
|
|
||||||
if (isRelayUrl(url)) {
|
|
||||||
return {url, claim}
|
|
||||||
}
|
|
||||||
}) ||
|
|
||||||
tryCatch(() => {
|
|
||||||
const url = normalizeRelayUrl(invite)
|
|
||||||
|
|
||||||
if (isRelayUrl(url)) {
|
|
||||||
return {url, claim: ""}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form class="column gap-4" onsubmit={preventDefault(join)}>
|
<form class="column gap-4" onsubmit={preventDefault(join)}>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import {
|
|||||||
groupBy,
|
groupBy,
|
||||||
always,
|
always,
|
||||||
tryCatch,
|
tryCatch,
|
||||||
|
fromPairs,
|
||||||
} from "@welshman/lib"
|
} from "@welshman/lib"
|
||||||
import type {Socket} from "@welshman/net"
|
import type {Socket} from "@welshman/net"
|
||||||
import {
|
import {
|
||||||
@@ -1004,3 +1005,22 @@ export const deriveRelayAuthError = (url: string, claim = "") => {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type InviteData = {url: string; claim: string}
|
||||||
|
|
||||||
|
export const parseInviteLink = (invite: string): InviteData | undefined =>
|
||||||
|
tryCatch(() => {
|
||||||
|
const {r: relay = "", c: claim = ""} = fromPairs(Array.from(new URL(invite).searchParams))
|
||||||
|
const url = normalizeRelayUrl(relay)
|
||||||
|
|
||||||
|
if (isRelayUrl(url)) {
|
||||||
|
return {url, claim}
|
||||||
|
}
|
||||||
|
}) ||
|
||||||
|
tryCatch(() => {
|
||||||
|
const url = normalizeRelayUrl(invite)
|
||||||
|
|
||||||
|
if (isRelayUrl(url)) {
|
||||||
|
return {url, claim: ""}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
import {debounce} from "throttle-debounce"
|
import {debounce} from "throttle-debounce"
|
||||||
import {dec, tryCatch} from "@welshman/lib"
|
import {dec} from "@welshman/lib"
|
||||||
import type {RelayProfile} from "@welshman/util"
|
import type {RelayProfile} from "@welshman/util"
|
||||||
import {ROOMS, normalizeRelayUrl, isRelayUrl} from "@welshman/util"
|
import {ROOMS} from "@welshman/util"
|
||||||
import {Router} from "@welshman/router"
|
import {Router} from "@welshman/router"
|
||||||
import {load} from "@welshman/net"
|
import {load} from "@welshman/net"
|
||||||
import {relays, createSearch, loadRelay} from "@welshman/app"
|
import {relays, createSearch, loadRelay} from "@welshman/app"
|
||||||
@@ -28,13 +28,12 @@
|
|||||||
loadGroupSelections,
|
loadGroupSelections,
|
||||||
getSpaceUrlsFromGroupSelections,
|
getSpaceUrlsFromGroupSelections,
|
||||||
groupSelectionsPubkeysByUrl,
|
groupSelectionsPubkeysByUrl,
|
||||||
|
parseInviteLink,
|
||||||
} from "@app/core/state"
|
} from "@app/core/state"
|
||||||
import {pushModal} from "@app/util/modal"
|
import {pushModal} from "@app/util/modal"
|
||||||
|
|
||||||
const openMenu = () => pushModal(SpaceAdd, {hideDiscover: true})
|
const openMenu = () => pushModal(SpaceAdd, {hideDiscover: true})
|
||||||
|
|
||||||
const termUrl = $derived(tryCatch(() => normalizeRelayUrl(term)) || "")
|
|
||||||
|
|
||||||
const toggleScanner = () => {
|
const toggleScanner = () => {
|
||||||
showScanner = !showScanner
|
showScanner = !showScanner
|
||||||
}
|
}
|
||||||
@@ -60,7 +59,7 @@
|
|||||||
|
|
||||||
const relaySearch = $derived(
|
const relaySearch = $derived(
|
||||||
createSearch(
|
createSearch(
|
||||||
$relays.filter(r => $groupSelectionsPubkeysByUrl.has(r.url) && r.url !== termUrl),
|
$relays.filter(r => $groupSelectionsPubkeysByUrl.has(r.url) && r.url !== inviteData?.url),
|
||||||
{
|
{
|
||||||
getValue: (relay: RelayProfile) => relay.url,
|
getValue: (relay: RelayProfile) => relay.url,
|
||||||
sortFn: ({score, item}) => {
|
sortFn: ({score, item}) => {
|
||||||
@@ -78,13 +77,21 @@
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const openSpace = (url: string) => pushModal(SpaceCheck, {url})
|
const openSpace = (url: string, claim = "") => {
|
||||||
|
if (claim) {
|
||||||
|
pushModal(SpaceInviteAccept, {invite: term})
|
||||||
|
} else {
|
||||||
|
pushModal(SpaceCheck, {url})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let term = $state("")
|
let term = $state("")
|
||||||
let limit = $state(20)
|
let limit = $state(20)
|
||||||
let showScanner = $state(false)
|
let showScanner = $state(false)
|
||||||
let element: Element
|
let element: Element
|
||||||
|
|
||||||
|
const inviteData = $derived(parseInviteLink(term))
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const scroller = createScroller({
|
const scroller = createScroller({
|
||||||
element,
|
element,
|
||||||
@@ -114,7 +121,11 @@
|
|||||||
<div class="row-2 min-w-0 flex-grow items-center">
|
<div class="row-2 min-w-0 flex-grow items-center">
|
||||||
<label class="input input-bordered flex flex-grow items-center gap-2">
|
<label class="input input-bordered flex flex-grow items-center gap-2">
|
||||||
<Icon icon={Magnifier} />
|
<Icon icon={Magnifier} />
|
||||||
<input bind:value={term} class="grow" type="text" placeholder="Search for spaces..." />
|
<input
|
||||||
|
bind:value={term}
|
||||||
|
class="grow"
|
||||||
|
type="text"
|
||||||
|
placeholder="Search for spaces or paste invite link..." />
|
||||||
<Button onclick={toggleScanner} class="center">
|
<Button onclick={toggleScanner} class="center">
|
||||||
<Icon icon={QrCode} />
|
<Icon icon={QrCode} />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -131,15 +142,15 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet content()}
|
{#snippet content()}
|
||||||
<div class="col-2 scroll-container" bind:this={element}>
|
<div class="col-2 scroll-container" bind:this={element}>
|
||||||
{#key termUrl}
|
{#if inviteData}
|
||||||
{#if isRelayUrl(termUrl)}
|
{#key inviteData.url}
|
||||||
<Button
|
<Button
|
||||||
class="card2 bg-alt shadow-xl transition-all hover:shadow-2xl hover:dark:brightness-[1.1]"
|
class="card2 bg-alt shadow-xl transition-all hover:shadow-2xl hover:dark:brightness-[1.1]"
|
||||||
onclick={() => openSpace(termUrl)}>
|
onclick={() => openSpace(inviteData.url, inviteData.claim)}>
|
||||||
<RelaySummary url={termUrl} />
|
<RelaySummary url={inviteData.url} />
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/key}
|
||||||
{/key}
|
{/if}
|
||||||
{#each relaySearch.searchOptions(term).slice(0, limit) as relay (relay.url)}
|
{#each relaySearch.searchOptions(term).slice(0, limit) as relay (relay.url)}
|
||||||
<Button
|
<Button
|
||||||
class="card2 bg-alt shadow-xl transition-all hover:shadow-2xl hover:dark:brightness-[1.1]"
|
class="card2 bg-alt shadow-xl transition-all hover:shadow-2xl hover:dark:brightness-[1.1]"
|
||||||
|
|||||||
Reference in New Issue
Block a user