Remove a lot of ceremony from frontend state management

This commit is contained in:
Jon Staab
2026-03-26 17:07:44 -07:00
parent a2f9ca9688
commit 6415bcd7b7
15 changed files with 188 additions and 415 deletions
+3 -14
View File
@@ -1,8 +1,7 @@
import { A, useLocation, useNavigate } from "@solidjs/router"
import { A, useLocation } from "@solidjs/router"
import { createEffect, createMemo, createSignal, For, onCleanup, Show } from "solid-js"
import Fuse from "fuse.js"
import { eventStore, primeProfiles, useActiveAccount, useProfilePicture } from "../lib/nostr"
import { useIdentity, useTenantRelays, type Relay } from "../lib/hooks"
import { account, eventStore, identity, primeProfiles, useProfilePicture, useTenantRelays, type Relay } from "../lib/hooks"
import serverIcon from "../assets/server.svg"
import Modal from "./Modal"
@@ -32,16 +31,12 @@ function RelayIcon() {
export default function AppShell(props: { children?: any }) {
const location = useLocation()
const navigate = useNavigate()
const account = useActiveAccount()
const picture = useProfilePicture(() => account()?.pubkey)
const [identity] = useIdentity(() => account()?.pubkey)
const [tenantRelays] = useTenantRelays()
const [profile, setProfile] = createSignal<Profile>({})
const [searchOpen, setSearchOpen] = createSignal(false)
const [searchQuery, setSearchQuery] = createSignal("")
const isAdmin = createMemo(() => !!identity()?.is_admin)
const username = createMemo(() => profile().name || profile().display_name || shortenPubkey(account()?.pubkey))
const nip05 = createMemo(() => profile().nip05 || "No NIP-05")
const searchedRelays = createMemo<Relay[]>(() => {
@@ -83,12 +78,6 @@ export default function AppShell(props: { children?: any }) {
})
})
createEffect(() => {
const currentIdentity = identity()
if (!currentIdentity || currentIdentity.is_admin || currentIdentity.is_tenant || location.pathname === "/") return
navigate("/", { replace: true })
})
const myResources = [{ href: "/relays", label: "My Relays" }]
const adminResources = [
{ href: "/admin/tenants", label: "Tenants" },
@@ -117,7 +106,7 @@ export default function AppShell(props: { children?: any }) {
<For each={myResources}>{(item) => <li><A href={item.href} class={navItemClass(item.href)}>{item.label}</A></li>}</For>
</ul>
<Show when={isAdmin()}>
<Show when={identity()?.is_admin}>
<div class="mt-8">
<h2 class="px-3 text-xs font-semibold uppercase tracking-wider text-white/60">Administration</h2>
<ul class="mt-2 space-y-1">