forked from coracle/caravel
Add hooks
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { useParams } from "@solidjs/router"
|
||||
import { createMemo, createResource, createSignal, Show } from "solid-js"
|
||||
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"
|
||||
import RelayDetailCard from "../../components/RelayDetailCard"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
import useMinLoading from "../../components/useMinLoading"
|
||||
import { deactivateRelayById, getRelayMemberCount, updateRelayById, updateRelayPlanById, useRelay, type Relay } from "../../lib/hooks"
|
||||
|
||||
export default function RelayDetail() {
|
||||
const params = useParams()
|
||||
const relayId = () => params.id ?? ""
|
||||
const [relay, { refetch, mutate }] = createResource(relayId, getTenantRelay)
|
||||
const [relay, { refetch, mutate }] = useRelay(relayId)
|
||||
const relayUrl = createMemo(() => {
|
||||
const subdomain = relay()?.subdomain
|
||||
return subdomain ? `wss://${subdomain}.spaces.coracle.social` : undefined
|
||||
@@ -26,7 +26,7 @@ export default function RelayDetail() {
|
||||
setError("")
|
||||
setBusy(true)
|
||||
try {
|
||||
await deactivateTenantRelay(relayId())
|
||||
await deactivateRelayById(relayId())
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Failed to deactivate relay")
|
||||
@@ -53,7 +53,7 @@ export default function RelayDetail() {
|
||||
mutate(next)
|
||||
|
||||
try {
|
||||
await updateTenantRelay(relayId(), next)
|
||||
await updateRelayById(relayId(), next)
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
mutate(previous)
|
||||
@@ -148,7 +148,7 @@ export default function RelayDetail() {
|
||||
mutate(next)
|
||||
|
||||
try {
|
||||
await updateTenantRelayPlan(relayId(), plan)
|
||||
await updateRelayPlanById(relayId(), plan)
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
mutate(previous)
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { useNavigate, useParams } from "@solidjs/router"
|
||||
import { Show, createEffect, createResource, createSignal } from "solid-js"
|
||||
import { getTenantRelay, updateTenantRelay } from "../../lib/api"
|
||||
import { Show, createEffect, createSignal } from "solid-js"
|
||||
import RelayForm from "../../components/RelayForm"
|
||||
import { slugify } from "../../lib/slugify"
|
||||
import BackLink from "../../components/BackLink"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
import useMinLoading from "../../components/useMinLoading"
|
||||
import { updateRelayById, useRelay } from "../../lib/hooks"
|
||||
|
||||
export default function RelayEdit() {
|
||||
const navigate = useNavigate()
|
||||
const params = useParams()
|
||||
const relayId = () => params.id ?? ""
|
||||
const [relay] = createResource(relayId, getTenantRelay)
|
||||
const [relay] = useRelay(relayId)
|
||||
const loading = useMinLoading(() => relay.loading)
|
||||
|
||||
const [name, setName] = createSignal("")
|
||||
@@ -36,7 +36,7 @@ export default function RelayEdit() {
|
||||
setError("")
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await updateTenantRelay(relayId(), {
|
||||
await updateRelayById(relayId(), {
|
||||
subdomain: slugify(subdomain()),
|
||||
info_name: name().trim(),
|
||||
info_icon: icon().trim(),
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { A } from "@solidjs/router"
|
||||
import Fuse from "fuse.js"
|
||||
import { createMemo, createResource, createSignal, For, Show } from "solid-js"
|
||||
import { listTenantRelays } from "../../lib/api"
|
||||
import { createMemo, createSignal, For, Show } from "solid-js"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
import useMinLoading from "../../components/useMinLoading"
|
||||
import { useTenantRelays } from "../../lib/hooks"
|
||||
|
||||
export default function RelayList() {
|
||||
const [relays] = createResource(listTenantRelays)
|
||||
const [relays] = useTenantRelays()
|
||||
const [query, setQuery] = createSignal("")
|
||||
const [status, setStatus] = createSignal("all")
|
||||
const loading = useMinLoading(() => relays.loading)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Show, createSignal } from "solid-js"
|
||||
import { useNavigate } from "@solidjs/router"
|
||||
import { createTenantRelay } from "../../lib/api"
|
||||
import { slugify } from "../../lib/slugify"
|
||||
import { createRelayForActiveTenant } from "../../lib/hooks"
|
||||
|
||||
const PLANS = [
|
||||
{ id: "free", label: "Free", price: 0, members: "Up to 10", blossom: false, livekit: false },
|
||||
@@ -34,7 +34,7 @@ export default function RelayNew() {
|
||||
setSubmitting(true)
|
||||
|
||||
try {
|
||||
const relay = await createTenantRelay({
|
||||
const relay = await createRelayForActiveTenant({
|
||||
subdomain: slugify(subdomain()),
|
||||
plan: plan(),
|
||||
info_name: name().trim(),
|
||||
|
||||
Reference in New Issue
Block a user