'use client'; import React, { useEffect, useRef, useState } from 'react'; import type { FounderClubContext } from '../../lib/club-data'; import { sanitizePortalError } from '../../lib/club-data'; import { createWallPost, deleteWallPost, replyToWallPost, setWallPostPinned, subscribeClubWall, type WallPost } from '../../lib/club-community'; import { CommunityDialog, communityButton, communityInput } from './community-dialog'; function postDate(value: string): string { if (!value) return 'Sending…'; const date = new Date(value); return Number.isNaN(date.getTime()) ? 'Date unavailable' : date.toLocaleString(); } export function FounderWall({ context }: { context: FounderClubContext }) { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const [loadError, setLoadError] = useState(null); const [actionError, setActionError] = useState(null); const [content, setContent] = useState(''); const [pinned, setPinned] = useState(false); const [replies, setReplies] = useState>({}); const [busy, setBusy] = useState(null); const busyRef = useRef(false); const [removing, setRemoving] = useState(null); const [retry, setRetry] = useState(0); const [notice, setNotice] = useState(''); useEffect(() => { setLoading(true); setLoadError(null); setPosts([]); if (context.isDemoFixture) { setLoading(false); return; } return subscribeClubWall(context.club.id, (items) => { setPosts(items); setLoading(false); }, (err) => { setPosts([]); setLoading(false); setLoadError(sanitizePortalError(err, 'The club wall could not be loaded.')); }); }, [context, retry]); async function perform(key: string, action: () => Promise, after: () => void) { if (busyRef.current || context.isDemoFixture) return; busyRef.current = true; setBusy(key); setActionError(null); setNotice(''); try { await action(); after(); setNotice('Changes saved.'); } catch (err) { setActionError(sanitizePortalError(err, 'Your changes could not be saved. Please try again.')); } finally { busyRef.current = false; setBusy(null); } } const disabled = context.isDemoFixture || !!busy || loading || !!loadError; return (

CLUB MANAGEMENT / COMMUNITY

Club Wall

Leadership announcements and conversations with your club.

{context.isDemoFixture &&

Development preview • changes are disabled.

}
{ event.preventDefault(); void perform('compose', () => createWallPost(context.club.id, content, pinned), () => { setContent(''); setPinned(false); }); }}>