diff --git a/src/components/CommunikeyViewer.tsx b/src/components/CommunikeyViewer.tsx index 5db33a9..89b9b60 100644 --- a/src/components/CommunikeyViewer.tsx +++ b/src/components/CommunikeyViewer.tsx @@ -1,7 +1,8 @@ -import { useEffect } from "react"; +import { useEffect, useState, lazy, Suspense } from "react"; import { useEventStore, use$ } from "applesauce-react/hooks"; import { addressLoader } from "@/services/loaders"; import { useProfile } from "@/hooks/useProfile"; +import { useTimeline } from "@/hooks/useTimeline"; import { getDisplayName } from "@/lib/nostr-utils"; import { useGrimoire } from "@/core/state"; import { @@ -14,8 +15,7 @@ import { getCommunikeyTos, } from "@/lib/communikeys-helpers"; import { Badge } from "@/components/ui/badge"; -import { Button } from "@/components/ui/button"; -import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Users, Radio, @@ -29,12 +29,22 @@ import { Copy, CopyCheck, User as UserIcon, + Info, + Loader2, } from "lucide-react"; import { nip19 } from "nostr-tools"; import { UserName } from "./nostr/UserName"; import { useCopy } from "@/hooks/useCopy"; import { getKindName, getKindIcon } from "@/constants/kinds"; +import { KindRenderer } from "./nostr/kinds"; +import { EventErrorBoundary } from "./EventErrorBoundary"; import type { ContentSection } from "@/lib/communikeys-helpers"; +import type { NostrEvent } from "@/types/nostr"; + +// Lazy load ChatViewer to avoid circular dependency +const ChatViewer = lazy(() => + import("./ChatViewer").then((m) => ({ default: m.ChatViewer })), +); const COMMUNIKEY_KIND = 10222; @@ -45,13 +55,14 @@ export interface CommunikeyViewerProps { /** * CommunikeyViewer - View a Communikey community - * Shows community profile, configuration, and content sections + * Shows community profile with tabbed content sections and chat */ export function CommunikeyViewer({ pubkey, relays }: CommunikeyViewerProps) { - const { state, addWindow } = useGrimoire(); + const { state } = useGrimoire(); const accountPubkey = state.activeAccount?.pubkey; const eventStore = useEventStore(); const { copy, copied } = useCopy(); + const [activeTab, setActiveTab] = useState("chat"); // Resolve $me alias const resolvedPubkey = pubkey === "$me" ? accountPubkey : pubkey; @@ -112,27 +123,6 @@ export function CommunikeyViewer({ pubkey, relays }: CommunikeyViewerProps) { // Generate npub for copying const npub = resolvedPubkey ? nip19.npubEncode(resolvedPubkey) : ""; - // Open chat for this community - const openChat = () => { - if (resolvedPubkey) { - addWindow("chat", { - protocol: "communikeys", - identifier: { - type: "communikey", - value: resolvedPubkey, - relays: communityRelays, - }, - }); - } - }; - - // View community profile - const viewProfile = () => { - if (resolvedPubkey) { - addWindow("profile", { pubkey: resolvedPubkey }); - } - }; - if (pubkey === "$me" && !accountPubkey) { return (
+ {description?.slice(0, 60)} + {description && description.length > 60 ? "..." : ""} +
+No content in this section yet
++ Content types: {section.kinds.map((k) => getKindName(k)).join(", ")} +
++ {description} +
+ )} - -- {description} -
- )} - - {/* Location */} - {location && ( -- No community configuration found (kind 10222). This pubkey may - not have set up a Communikey community yet. -
-{relay}
- {index === 0 && (
- {server}
- {mint.url}
- {mint.protocol && (
- {tos.id}
- {tos.relay && (
- - Relay: {tos.relay} -
- )} -+ No community configuration found (kind 10222). This pubkey may not + have set up a Communikey community yet. +
+{relay}
+ {index === 0 && (
+ {server}
+ {mint.url}
+ {mint.protocol && (
+ {tos.id}
+ {tos.relay && (
+ + Relay: {tos.relay} +
+ )} +
- Requires badge: {section.badgeRequirement}
-
+ Requires badge: {section.badgeRequirement}
+