diff --git a/frontend/src/components/AppShell.tsx b/frontend/src/components/AppShell.tsx index 26ec95f..c4e5801 100644 --- a/frontend/src/components/AppShell.tsx +++ b/frontend/src/components/AppShell.tsx @@ -50,7 +50,7 @@ export default function AppShell(props: { children?: any }) { if (!query) return list const fuse = new Fuse(list, { - keys: ["name", "subdomain"], + keys: ["info_name", "subdomain"], threshold: 0.35, ignoreLocation: true, }) @@ -224,7 +224,7 @@ export default function AppShell(props: { children?: any }) { class="block rounded-lg border border-gray-200 bg-white p-3" onClick={closeSearchModal} > -
{relay.name}
+{relay.info_name || relay.subdomain}
{relay.subdomain}.spaces.coracle.social
diff --git a/frontend/src/components/RelayDetailCard.tsx b/frontend/src/components/RelayDetailCard.tsx index 79e2ec5..30ea4c7 100644 --- a/frontend/src/components/RelayDetailCard.tsx +++ b/frontend/src/components/RelayDetailCard.tsx @@ -97,7 +97,11 @@ type RelayDetailCardProps = { export default function RelayDetailCard(props: RelayDetailCardProps) { const r = () => props.relay - const cfg = () => r().config + const flag = (value: number, fallback: boolean) => { + if (value === 0) return false + if (value === 1) return true + return fallback + } const [menuOpen, setMenuOpen] = createSignal(false) const [planModalOpen, setPlanModalOpen] = createSignal(false) const [selectedPlan, setSelectedPlan] = createSignal{r().description}
+{r().info_description}
{new Date(invoice.created_at).toLocaleString()}
-{invoice.invoice}
+{new Date(invoice.created_at * 1000).toLocaleString()}
+{invoice.bolt11}
{relay.name}
+{relay.info_name || relay.subdomain}
{relay.subdomain}.spaces.coracle.social
Tenant: {relay.tenant}
- Current: {d().tenant.status} + Current: tenant
-{relay.name}
+{relay.info_name || relay.subdomain}
{relay.subdomain}.spaces.coracle.social
{error()}
-{tenant.pubkey}
{tenant.status}
+tenant
diff --git a/frontend/src/pages/relays/RelayDetail.tsx b/frontend/src/pages/relays/RelayDetail.tsx index 1ab7b33..54678a5 100644 --- a/frontend/src/pages/relays/RelayDetail.tsx +++ b/frontend/src/pages/relays/RelayDetail.tsx @@ -1,6 +1,6 @@ import { useParams } from "@solidjs/router" import { createMemo, createResource, createSignal, Show } from "solid-js" -import { deactivateTenantRelay, getRelayMemberCount, getTenantRelay, updateTenantRelay, updateTenantRelayPlan, type RelayConfig } from "../../lib/api" +import { deactivateTenantRelay, getRelayMemberCount, getTenantRelay, updateTenantRelay, updateTenantRelayPlan, type Relay } from "../../lib/api" import type { RelayPlanId } from "../../lib/relayPlans" import BackLink from "../../components/BackLink" import PageContainer from "../../components/PageContainer" @@ -35,114 +35,100 @@ export default function RelayDetail() { } } - function withDefaults(config?: RelayConfig): RelayConfig { - return { - policy: { - public_join: config?.policy.public_join ?? false, - strip_signatures: config?.policy.strip_signatures ?? false, - }, - groups: { - enabled: config?.groups.enabled ?? true, - auto_join: config?.groups.auto_join ?? true, - }, - management: { - enabled: config?.management.enabled ?? true, - }, - blossom: { - enabled: config?.blossom.enabled ?? (relay()?.plan !== "free"), - }, - livekit: { - enabled: config?.livekit.enabled ?? (relay()?.plan !== "free"), - }, - push: { - enabled: config?.push.enabled ?? true, - }, - } + function toBool(value: number | undefined, fallback: boolean): boolean { + if (value === 0) return false + if (value === 1) return true + return fallback } - async function updateFlags(nextConfig: RelayConfig, previousConfig: RelayConfig) { + function toInt(value: boolean): number { + return value ? 1 : 0 + } + + async function updateRelay(next: Relay, previous: Relay) { const current = relay() if (!current) return setError("") - mutate({ ...current, config: nextConfig }) + mutate(next) try { - await updateTenantRelay(relayId(), { - name: current.name, - subdomain: current.subdomain, - icon: current.icon, - description: current.description, - config: nextConfig, - }) + await updateTenantRelay(relayId(), next) await refetch() } catch (e) { - mutate({ ...current, config: previousConfig }) + mutate(previous) setError(e instanceof Error ? e.message : "Failed to update relay settings") } } function togglePublicJoin() { - const config = withDefaults(relay()?.config) - const nextConfig = { - ...config, - policy: { ...config.policy, public_join: !config.policy.public_join }, + const current = relay() + if (!current) return + const next = { + ...current, + policy_public_join: toInt(!toBool(current.policy_public_join, false)), } - void updateFlags(nextConfig, config) + void updateRelay(next, current) } function toggleStripSignatures() { - const config = withDefaults(relay()?.config) - const nextConfig = { - ...config, - policy: { ...config.policy, strip_signatures: !config.policy.strip_signatures }, + const current = relay() + if (!current) return + const next = { + ...current, + policy_strip_signatures: toInt(!toBool(current.policy_strip_signatures, false)), } - void updateFlags(nextConfig, config) + void updateRelay(next, current) } function toggleGroups() { - const config = withDefaults(relay()?.config) - const nextConfig = { - ...config, - groups: { ...config.groups, enabled: !config.groups.enabled }, + const current = relay() + if (!current) return + const next = { + ...current, + groups_enabled: toInt(!toBool(current.groups_enabled, true)), } - void updateFlags(nextConfig, config) + void updateRelay(next, current) } function toggleManagement() { - const config = withDefaults(relay()?.config) - const nextConfig = { - ...config, - management: { enabled: !config.management.enabled }, + const current = relay() + if (!current) return + const next = { + ...current, + management_enabled: toInt(!toBool(current.management_enabled, true)), } - void updateFlags(nextConfig, config) + void updateRelay(next, current) } function toggleMediaStorage() { - const config = withDefaults(relay()?.config) - const nextConfig = { - ...config, - blossom: { enabled: !config.blossom.enabled }, + const current = relay() + if (!current) return + const next = { + ...current, + blossom_enabled: toInt(!toBool(current.blossom_enabled, current.plan !== "free")), } - void updateFlags(nextConfig, config) + void updateRelay(next, current) } function togglePushNotifications() { - const config = withDefaults(relay()?.config) - const nextConfig = { - ...config, - push: { enabled: !config.push.enabled }, + const current = relay() + if (!current) return + const next = { + ...current, + push_enabled: toInt(!toBool(current.push_enabled, true)), } - void updateFlags(nextConfig, config) + void updateRelay(next, current) } function toggleLivekitSupport() { - const config = withDefaults(relay()?.config) - const nextConfig = { - ...config, - livekit: { enabled: !config.livekit.enabled }, + const current = relay() + if (!current) return + const next = { + ...current, + livekit_enabled: toInt(!toBool(current.livekit_enabled, current.plan !== "free")), } - void updateFlags(nextConfig, config) + void updateRelay(next, current) } async function handleUpdatePlan(plan: RelayPlanId) { @@ -152,13 +138,14 @@ export default function RelayDetail() { const previous = current setError("") - const nextConfig = withDefaults(current.config) + const next = { ...current } if (plan === "free") { - nextConfig.blossom = { enabled: false } - nextConfig.livekit = { enabled: false } + next.blossom_enabled = 0 + next.livekit_enabled = 0 } - mutate({ ...current, plan, config: nextConfig }) + next.plan = plan + mutate(next) try { await updateTenantRelayPlan(relayId(), plan) diff --git a/frontend/src/pages/relays/RelayEdit.tsx b/frontend/src/pages/relays/RelayEdit.tsx index 78a08b7..80542dc 100644 --- a/frontend/src/pages/relays/RelayEdit.tsx +++ b/frontend/src/pages/relays/RelayEdit.tsx @@ -1,6 +1,6 @@ import { useNavigate, useParams } from "@solidjs/router" import { Show, createEffect, createResource, createSignal } from "solid-js" -import { getTenantRelay, updateTenantRelay, type RelayConfig } from "../../lib/api" +import { getTenantRelay, updateTenantRelay } from "../../lib/api" import RelayForm from "../../components/RelayForm" import { slugify } from "../../lib/slugify" import BackLink from "../../components/BackLink" @@ -8,15 +8,6 @@ import PageContainer from "../../components/PageContainer" import ResourceState from "../../components/ResourceState" import useMinLoading from "../../components/useMinLoading" -const DEFAULT_CONFIG: RelayConfig = { - policy: { public_join: false, strip_signatures: false }, - groups: { enabled: false, auto_join: false }, - management: { enabled: false }, - blossom: { enabled: false }, - livekit: { enabled: false }, - push: { enabled: false }, -} - export default function RelayEdit() { const navigate = useNavigate() const params = useParams() @@ -34,10 +25,10 @@ export default function RelayEdit() { createEffect(() => { const data = relay() if (!data) return - setName(data.name) + setName(data.info_name) setSubdomain(data.subdomain) - setIcon(data.icon) - setDescription(data.description) + setIcon(data.info_icon) + setDescription(data.info_description) }) async function handleSubmit(e: Event) { @@ -46,11 +37,10 @@ export default function RelayEdit() { setSubmitting(true) try { await updateTenantRelay(relayId(), { - name: name().trim(), subdomain: slugify(subdomain()), - icon: icon().trim(), - description: description().trim(), - config: relay()?.config ?? DEFAULT_CONFIG, + info_name: name().trim(), + info_icon: icon().trim(), + info_description: description().trim(), }) navigate(`/relays/${relayId()}`) } catch (e) { diff --git a/frontend/src/pages/relays/RelayList.tsx b/frontend/src/pages/relays/RelayList.tsx index 53d1078..137d27b 100644 --- a/frontend/src/pages/relays/RelayList.tsx +++ b/frontend/src/pages/relays/RelayList.tsx @@ -17,7 +17,7 @@ export default function RelayList() { const q = query().trim() const searched = q ? new Fuse(list, { - keys: ["name", "subdomain"], + keys: ["info_name", "subdomain"], threshold: 0.35, ignoreLocation: true, }).search(q).map((result) => result.item) @@ -90,7 +90,7 @@ export default function RelayList() { >{relay.name}
+{relay.info_name || relay.subdomain}
https://{relay.subdomain}.spaces.coracle.social
{relay.status}
diff --git a/frontend/src/pages/relays/RelayNew.tsx b/frontend/src/pages/relays/RelayNew.tsx index f29d3d1..ce8e3ee 100644 --- a/frontend/src/pages/relays/RelayNew.tsx +++ b/frontend/src/pages/relays/RelayNew.tsx @@ -1,6 +1,6 @@ import { Show, createSignal } from "solid-js" import { useNavigate } from "@solidjs/router" -import { createTenantRelay, type RelayConfig } from "../../lib/api" +import { createTenantRelay } from "../../lib/api" import { slugify } from "../../lib/slugify" const PLANS = [ @@ -11,15 +11,6 @@ const PLANS = [ type PlanId = (typeof PLANS)[number]["id"] -const DEFAULT_CONFIG: RelayConfig = { - policy: { public_join: false, strip_signatures: false }, - groups: { enabled: true, auto_join: true }, - management: { enabled: true }, - blossom: { enabled: false }, - livekit: { enabled: false }, - push: { enabled: true }, -} - export default function RelayNew() { const navigate = useNavigate() const [name, setName] = createSignal("") @@ -44,16 +35,18 @@ export default function RelayNew() { try { const relay = await createTenantRelay({ - name: name().trim(), subdomain: slugify(subdomain()), - icon: icon().trim(), - description: description().trim(), plan: plan(), - config: { - ...DEFAULT_CONFIG, - blossom: { enabled: plan() !== "free" }, - livekit: { enabled: plan() !== "free" }, - }, + info_name: name().trim(), + info_icon: icon().trim(), + info_description: description().trim(), + policy_public_join: 0, + policy_strip_signatures: 0, + groups_enabled: 1, + management_enabled: 1, + blossom_enabled: plan() === "free" ? 0 : 1, + livekit_enabled: plan() === "free" ? 0 : 1, + push_enabled: 1, }) navigate(`/relays/${relay.id}`) } catch (e) {