diff --git a/packages/web/src/components/chat/ExplorePage.tsx b/packages/web/src/components/chat/ExplorePage.tsx index 155f7ee5..875cd914 100644 --- a/packages/web/src/components/chat/ExplorePage.tsx +++ b/packages/web/src/components/chat/ExplorePage.tsx @@ -7,13 +7,13 @@ import { Mascot } from '../ui/Mascot'; import { getSpaceGradient } from '../../utils/gradients'; import { extractDominantColors, colorsToGradient } from '../../utils/colorExtractor'; import { MemberListToggleButton } from '../layout/MemberListToggleButton'; +import { useSpaceJoin } from '../../hooks/useSpaceJoin'; export function ExplorePage() { const navigate = useNavigate(); const setCurrentSpace = useSpaceStore((s) => s.setCurrentSpace); const spaces = useExploreStore((s) => s.spaces); - const myRequests = useExploreStore((s) => s.myRequests); const isLoading = useExploreStore((s) => s.isLoading); const discoveryEnabled = useExploreStore((s) => s.discoveryEnabled); const error = useExploreStore((s) => s.error); @@ -150,7 +150,6 @@ export function ExplorePage() { r.spaceId === space.id && r.status === 'pending')} onJoinSuccess={handleJoinSuccess} /> ))} @@ -187,7 +186,6 @@ export function ExplorePage() { ))} @@ -204,26 +202,29 @@ export function ExplorePage() { function SpaceCard({ space, - isPending, onJoinSuccess, }: { space: TaggedExploreSpace; - isPending: boolean; onJoinSuccess: (spaceId: string) => void; }) { - const publicJoin = useExploreStore((s) => s.publicJoin); - const requestJoin = useExploreStore((s) => s.requestJoin); + const { + isJoined, + isPublic, + isPending, + joining, + joinError, + showRequestForm, + requestMessage, + setRequestMessage, + openRequestForm, + cancelRequestForm, + join, + sendRequest, + } = useSpaceJoin(space); - const [joining, setJoining] = useState(false); - const [showRequestForm, setShowRequestForm] = useState(false); - const [requestMessage, setRequestMessage] = useState(''); - const [requestSent, setRequestSent] = useState(isPending); - const [joinError, setJoinError] = useState(''); const [iconGradient, setIconGradient] = useState(null); const fallbackGradient = getSpaceGradient(space.id, space.name, space.avatarColor).gradient; - const isPublic = space.visibility === 'public'; - const isJoined = space.joined === true; const originLabel = space._instanceOrigin ? (() => { try { return new URL(space._instanceOrigin).host; } catch { return space._instanceOrigin; } })() : null; @@ -248,29 +249,8 @@ function SpaceCard({ }, [iconUrl, bannerUrl]); const handlePublicJoin = async () => { - setJoining(true); - setJoinError(''); - try { - const fullSpace = await publicJoin(space); - onJoinSuccess(fullSpace.id); - } catch (err) { - setJoinError(err instanceof Error ? err.message : 'Failed to join'); - setJoining(false); - } - }; - - const handleRequestJoin = async () => { - setJoining(true); - setJoinError(''); - try { - await requestJoin(space, requestMessage.trim() || undefined); - setRequestSent(true); - setShowRequestForm(false); - } catch (err) { - setJoinError(err instanceof Error ? err.message : 'Failed to send request'); - } finally { - setJoining(false); - } + const full = await join(); + if (full) onJoinSuccess(full.id); }; const handleViewSpace = () => { @@ -397,7 +377,7 @@ function SpaceCard({ 'Join Space' )} - ) : requestSent ? ( + ) : isPending ? (