Show tenant links, remove plan from relay edit form
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { A } from "@solidjs/router"
|
||||
import { Show } from "solid-js"
|
||||
import { createEffect, createSignal, onCleanup, Show } from "solid-js"
|
||||
import { getProfilePicture } from "applesauce-core/helpers/profile"
|
||||
import type { Relay } from "@/lib/api"
|
||||
import { eventStore } from "@/lib/state"
|
||||
|
||||
type RelayListItemProps = {
|
||||
relay: Relay
|
||||
@@ -8,17 +10,51 @@ type RelayListItemProps = {
|
||||
showTenant?: boolean
|
||||
}
|
||||
|
||||
function shortenPubkey(pubkey: string) {
|
||||
return pubkey.length <= 16 ? pubkey : `${pubkey.slice(0, 8)}...${pubkey.slice(-8)}`
|
||||
}
|
||||
|
||||
export default function RelayListItem(props: RelayListItemProps) {
|
||||
const [tenantProfile, setTenantProfile] = createSignal<{ name?: string; picture?: string }>({})
|
||||
|
||||
// Resolve the owning tenant's profile from the event store. The list that
|
||||
// passes `showTenant` is responsible for priming these profiles in one batch.
|
||||
createEffect(() => {
|
||||
if (!props.showTenant) return
|
||||
const pubkey = props.relay.tenant_pubkey
|
||||
if (!pubkey) return
|
||||
|
||||
const sub = eventStore.profile(pubkey).subscribe((metadata) => {
|
||||
setTenantProfile({
|
||||
name: metadata?.name || metadata?.display_name,
|
||||
picture: getProfilePicture(metadata),
|
||||
})
|
||||
})
|
||||
onCleanup(() => sub.unsubscribe())
|
||||
})
|
||||
|
||||
return (
|
||||
<li>
|
||||
<A href={props.href} class="block rounded-lg border border-gray-200 bg-white p-4 hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="min-w-0">
|
||||
<p class="font-medium text-gray-900">{props.relay.info_name || props.relay.subdomain}</p>
|
||||
<p class="text-xs text-gray-500">{props.relay.subdomain}.spaces.coracle.social</p>
|
||||
{props.showTenant && (
|
||||
<p class="text-xs text-gray-500 break-all mt-1">Tenant: {props.relay.tenant_pubkey}</p>
|
||||
)}
|
||||
<Show when={props.showTenant}>
|
||||
<div class="mt-1.5 flex items-center gap-2">
|
||||
<Show
|
||||
when={tenantProfile().picture}
|
||||
fallback={
|
||||
<div class="h-5 w-5 flex-shrink-0 rounded-full bg-gray-200 flex items-center justify-center text-[10px] text-gray-500">
|
||||
{(tenantProfile().name || props.relay.tenant_pubkey).slice(0, 1).toUpperCase()}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<img src={tenantProfile().picture} alt="" class="h-5 w-5 flex-shrink-0 rounded-full object-cover" />
|
||||
</Show>
|
||||
<span class="text-xs text-gray-500 truncate">{tenantProfile().name || shortenPubkey(props.relay.tenant_pubkey)}</span>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
<Show
|
||||
when={props.relay.sync_error}
|
||||
|
||||
Reference in New Issue
Block a user