forked from coracle/caravel
Remove a lot of ceremony from frontend state management
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
import { createEffect, createMemo, createSignal, For, Show } from "solid-js"
|
||||
import { useNavigate } from "@solidjs/router"
|
||||
import PageContainer from "../components/PageContainer"
|
||||
import LoadingState from "../components/LoadingState"
|
||||
import useMinLoading from "../components/useMinLoading"
|
||||
import { accounts, persistAccounts } from "../lib/nostr"
|
||||
import { updateActiveTenantBilling, useTenant, useTenantInvoices } from "../lib/hooks"
|
||||
|
||||
export default function Account() {
|
||||
const navigate = useNavigate()
|
||||
const [tenant, { refetch: refetchTenant }] = useTenant()
|
||||
const [invoices] = useTenantInvoices()
|
||||
const [nwcUrl, setNwcUrl] = createSignal("")
|
||||
@@ -40,9 +37,8 @@ export default function Account() {
|
||||
}
|
||||
|
||||
function logout() {
|
||||
accounts.clearActive()
|
||||
persistAccounts()
|
||||
navigate("/")
|
||||
localStorage.clear()
|
||||
window.location.href = "/"
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { A } from "@solidjs/router"
|
||||
import PricingTable from "../components/PricingTable"
|
||||
import { useActiveAccount } from "../lib/nostr"
|
||||
import { account } from "../lib/hooks"
|
||||
|
||||
function CheckIcon() {
|
||||
return (
|
||||
@@ -21,8 +21,6 @@ function ExternalLinkIcon() {
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
const account = useActiveAccount()
|
||||
|
||||
return (
|
||||
<div class="min-h-screen bg-white text-gray-900 overflow-x-hidden">
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import { ExtensionAccount, NostrConnectAccount, PasswordAccount, PrivateKeyAccou
|
||||
import { PasswordSigner } from "applesauce-signers"
|
||||
import QrScanner from "qr-scanner"
|
||||
import QRCode from "qrcode"
|
||||
import { activateAccount } from "../lib/nostr"
|
||||
import { PLATFORM_NAME } from "../lib/nostr"
|
||||
import { accountManager, identity, PLATFORM_NAME } from "../lib/hooks"
|
||||
|
||||
const NIP46_RELAYS = ['wss://bucket.coracle.social', 'wss://ephemeral.snowflare.cc']
|
||||
|
||||
@@ -58,8 +57,15 @@ export default function Login() {
|
||||
let abortController: AbortController | undefined
|
||||
|
||||
async function completeLogin(account: ExtensionAccount | NostrConnectAccount | PrivateKeyAccount | PasswordAccount) {
|
||||
activateAccount(account)
|
||||
navigate("/relays")
|
||||
accountManager.addAccount(account)
|
||||
accountManager.setActive(account)
|
||||
|
||||
const dispose = createEffect(() => {
|
||||
if (identity()) {
|
||||
navigate("/relays")
|
||||
dispose()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function loginWithNip07() {
|
||||
|
||||
@@ -4,13 +4,14 @@ import BackLink from "../../components/BackLink"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
import useMinLoading from "../../components/useMinLoading"
|
||||
import { useAdminTenantDetail } from "../../lib/hooks"
|
||||
import { useAdminTenant, useAdminTenantRelays } from "../../lib/hooks"
|
||||
|
||||
export default function AdminTenantDetail() {
|
||||
const params = useParams()
|
||||
const tenantId = () => params.id ?? ""
|
||||
const [detail] = useAdminTenantDetail(tenantId)
|
||||
const loading = useMinLoading(() => detail.loading)
|
||||
const [tenant] = useAdminTenant(tenantId)
|
||||
const [relays] = useAdminTenantRelays(tenantId)
|
||||
const loading = useMinLoading(() => tenant.loading || relays.loading)
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
@@ -19,7 +20,7 @@ export default function AdminTenantDetail() {
|
||||
|
||||
<ResourceState
|
||||
loading={loading()}
|
||||
error={detail.error}
|
||||
error={tenant.error || relays.error}
|
||||
loadingText="Loading tenant..."
|
||||
errorText="Failed to load tenant."
|
||||
class="mb-4"
|
||||
@@ -29,7 +30,7 @@ export default function AdminTenantDetail() {
|
||||
<div class="space-y-6">
|
||||
<section class="bg-white border border-gray-200 rounded-xl p-6">
|
||||
<h2 class="text-lg font-semibold mb-4">Status</h2>
|
||||
<Show when={detail()}>
|
||||
<Show when={tenant()}>
|
||||
<div class="space-y-3">
|
||||
<p class="text-sm text-gray-700">
|
||||
Current: <span class="font-medium uppercase tracking-wide">tenant</span>
|
||||
@@ -40,9 +41,9 @@ export default function AdminTenantDetail() {
|
||||
|
||||
<section class="bg-white border border-gray-200 rounded-xl p-6">
|
||||
<h2 class="text-lg font-semibold mb-4">Relays</h2>
|
||||
<Show when={(detail()?.relays.length ?? 0) > 0} fallback={<p class="text-gray-500">No relays.</p>}>
|
||||
<Show when={(relays()?.length ?? 0) > 0} fallback={<p class="text-gray-500">No relays.</p>}>
|
||||
<ul class="space-y-3">
|
||||
<For each={detail()?.relays ?? []}>
|
||||
<For each={relays() ?? []}>
|
||||
{(relay) => (
|
||||
<li>
|
||||
<A href={`/admin/relays/${relay.id}`} class="block rounded-lg border border-gray-200 p-3 hover:border-gray-300">
|
||||
|
||||
@@ -2,11 +2,10 @@ import { A } from "@solidjs/router"
|
||||
import Fuse from "fuse.js"
|
||||
import { createEffect, createMemo, createSignal, For, onCleanup, Show } from "solid-js"
|
||||
import { getProfilePicture } from "applesauce-core/helpers/profile"
|
||||
import { eventStore, primeProfiles } from "../../lib/nostr"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
import useMinLoading from "../../components/useMinLoading"
|
||||
import { useAdminTenants } from "../../lib/hooks"
|
||||
import { eventStore, primeProfiles, useAdminTenants } from "../../lib/hooks"
|
||||
|
||||
function shortenPubkey(pubkey: string) {
|
||||
if (pubkey.length <= 16) return pubkey
|
||||
|
||||
@@ -6,7 +6,7 @@ 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"
|
||||
import { deactivateRelayById, getRelayMembers, updateRelayById, updateRelayPlanById, useRelay, type Relay } from "../../lib/hooks"
|
||||
|
||||
export default function RelayDetail() {
|
||||
const params = useParams()
|
||||
@@ -16,7 +16,7 @@ export default function RelayDetail() {
|
||||
const subdomain = relay()?.subdomain
|
||||
return subdomain ? `wss://${subdomain}.spaces.coracle.social` : undefined
|
||||
})
|
||||
const [memberCount] = createResource(relayUrl, async (url) => getRelayMemberCount(url))
|
||||
const [members] = createResource(relayUrl, getRelayMembers)
|
||||
const [busy, setBusy] = createSignal(false)
|
||||
const [error, setError] = createSignal("")
|
||||
const loading = useMinLoading(() => relay.loading && !relay())
|
||||
@@ -174,7 +174,7 @@ export default function RelayDetail() {
|
||||
<div class="mb-6">
|
||||
<RelayDetailCard
|
||||
relay={r()}
|
||||
currentMembers={memberCount()}
|
||||
currentMembers={members.length}
|
||||
editHref={`/relays/${params.id}/edit`}
|
||||
onDeactivate={handleDeactivate}
|
||||
deactivating={busy()}
|
||||
|
||||
Reference in New Issue
Block a user