forked from coracle/caravel
Update frontend to fit backend
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useParams } from "@solidjs/router"
|
||||
import { createResource, createSignal, Show } from "solid-js"
|
||||
import { adminDeactivateRelay, adminGetRelay, adminUpdateRelay, type RelayConfig } from "../../lib/api"
|
||||
import { adminDeactivateRelay, adminGetRelay, adminUpdateRelay, type Relay } from "../../lib/api"
|
||||
import BackLink from "../../components/BackLink"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import RelayDetailCard from "../../components/RelayDetailCard"
|
||||
@@ -29,118 +29,100 @@ export default function AdminRelayDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
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("")
|
||||
const optimisticRelay = {
|
||||
...current,
|
||||
config: nextConfig,
|
||||
}
|
||||
mutate(optimisticRelay)
|
||||
mutate(next)
|
||||
|
||||
try {
|
||||
await adminUpdateRelay(relayId(), {
|
||||
name: current.name,
|
||||
subdomain: current.subdomain,
|
||||
icon: current.icon,
|
||||
description: current.description,
|
||||
config: nextConfig,
|
||||
})
|
||||
await adminUpdateRelay(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)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate, useParams } from "@solidjs/router"
|
||||
import { Show, createEffect, createResource, createSignal } from "solid-js"
|
||||
import { adminGetRelay, adminUpdateRelay, type RelayConfig } from "../../lib/api"
|
||||
import { adminGetRelay, adminUpdateRelay } 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 AdminRelayEdit() {
|
||||
const navigate = useNavigate()
|
||||
const params = useParams()
|
||||
@@ -34,10 +25,10 @@ export default function AdminRelayEdit() {
|
||||
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 AdminRelayEdit() {
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await adminUpdateRelay(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(`/admin/relays/${relayId()}`)
|
||||
} catch (e) {
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function AdminRelayList() {
|
||||
if (!q) return list
|
||||
|
||||
return new Fuse(list, {
|
||||
keys: ["name", "subdomain", "tenant"],
|
||||
keys: ["info_name", "subdomain", "tenant"],
|
||||
threshold: 0.35,
|
||||
ignoreLocation: true,
|
||||
}).search(q).map((result) => result.item)
|
||||
@@ -60,7 +60,7 @@ export default function AdminRelayList() {
|
||||
<A href={`/admin/relays/${relay.id}`} class="block border border-gray-200 rounded-lg p-4 bg-white hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<p class="font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="font-medium text-gray-900">{relay.info_name || relay.subdomain}</p>
|
||||
<p class="text-xs text-gray-500">{relay.subdomain}.spaces.coracle.social</p>
|
||||
<p class="text-xs text-gray-500 break-all mt-1">Tenant: {relay.tenant}</p>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useParams, A } from "@solidjs/router"
|
||||
import { createResource, createSignal, For, Show } from "solid-js"
|
||||
import { adminGetTenant, adminUpdateTenantStatus } from "../../lib/api"
|
||||
import { createResource, For, Show } from "solid-js"
|
||||
import { adminGetTenant } from "../../lib/api"
|
||||
import BackLink from "../../components/BackLink"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
@@ -9,25 +9,9 @@ import useMinLoading from "../../components/useMinLoading"
|
||||
export default function AdminTenantDetail() {
|
||||
const params = useParams()
|
||||
const tenantId = () => params.id ?? ""
|
||||
const [detail, { refetch }] = createResource(tenantId, adminGetTenant)
|
||||
const [busy, setBusy] = createSignal(false)
|
||||
const [error, setError] = createSignal("")
|
||||
const [detail] = createResource(tenantId, adminGetTenant)
|
||||
const loading = useMinLoading(() => detail.loading)
|
||||
|
||||
async function setStatus(status: string) {
|
||||
if (busy()) return
|
||||
setBusy(true)
|
||||
setError("")
|
||||
try {
|
||||
await adminUpdateTenantStatus(tenantId(), status)
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Failed to update tenant")
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<BackLink href="/admin/tenants" label="Tenants" />
|
||||
@@ -49,24 +33,8 @@ export default function AdminTenantDetail() {
|
||||
{(d) => (
|
||||
<div class="space-y-3">
|
||||
<p class="text-sm text-gray-700">
|
||||
Current: <span class="font-medium uppercase tracking-wide">{d().tenant.status}</span>
|
||||
Current: <span class="font-medium uppercase tracking-wide">tenant</span>
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
class="py-2 px-4 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 disabled:opacity-50"
|
||||
onClick={() => void setStatus("active")}
|
||||
disabled={busy()}
|
||||
>
|
||||
Activate
|
||||
</button>
|
||||
<button
|
||||
class="py-2 px-4 border border-red-300 text-red-600 rounded-lg hover:bg-red-50 disabled:opacity-50"
|
||||
onClick={() => void setStatus("deactivated")}
|
||||
disabled={busy()}
|
||||
>
|
||||
Deactivate
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
@@ -82,7 +50,7 @@ export default function AdminTenantDetail() {
|
||||
<A href={`/admin/relays/${relay.id}`} class="block rounded-lg border border-gray-200 p-3 hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div>
|
||||
<p class="font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="font-medium text-gray-900">{relay.info_name || relay.subdomain}</p>
|
||||
<p class="text-xs text-gray-500">{relay.subdomain}.spaces.coracle.social</p>
|
||||
</div>
|
||||
<span class="text-xs uppercase tracking-wide text-gray-500">{relay.status}</span>
|
||||
@@ -94,9 +62,6 @@ export default function AdminTenantDetail() {
|
||||
</ul>
|
||||
</Show>
|
||||
</section>
|
||||
<Show when={error()}>
|
||||
<p class="text-sm text-red-600">{error()}</p>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
</PageContainer>
|
||||
|
||||
@@ -115,7 +115,7 @@ export default function AdminTenantList() {
|
||||
<p class="mt-1 text-xs text-gray-500 break-all">{tenant.pubkey}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-xs uppercase tracking-wide text-gray-500">{tenant.status}</p>
|
||||
<p class="text-xs uppercase tracking-wide text-gray-500">tenant</p>
|
||||
</div>
|
||||
</A>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user