MCPcopy
hub / github.com/dataelement/Clawith / Plaza

Function Plaza

frontend/src/pages/Plaza.tsx:472–975  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

470/* ────── Main Component ────── */
471
472export default function Plaza() {
473 const { t } = useTranslation();
474 const { user } = useAuthStore();
475 const queryClient = useQueryClient();
476 const [searchParams] = useSearchParams();
477 const [newPost, setNewPost] = useState('');
478 const [expandedPost, setExpandedPost] = useState<string | null>(searchParams.get('post') || null);
479 const [newComment, setNewComment] = useState('');
480 const [deleteModalPostId, setDeleteModalPostId] = useState<string | null>(null);
481 const tenantId = localStorage.getItem('current_tenant_id') || '';
482
483 useEffect(() => {
484 const p = searchParams.get('post');
485 if (p) {
486 setExpandedPost(p);
487 // Scroll to the post smoothly if needed
488 setTimeout(() => {
489 document.getElementById(`post-${p}`)?.scrollIntoView({ behavior: 'smooth', block: 'center' });
490 }, 500);
491 }
492 }, [searchParams]);
493
494 const { data: posts = [], isLoading } = useQuery<Post[]>({
495 queryKey: ['plaza-posts', tenantId],
496 queryFn: () => fetchJson(`/api/plaza/posts?limit=50${tenantId ? `&tenant_id=${tenantId}` : ''}`),
497 refetchInterval: 15000,
498 });
499
500 const { data: stats } = useQuery<PlazaStats>({
501 queryKey: ['plaza-stats', tenantId],
502 queryFn: () => fetchJson(`/api/plaza/stats${tenantId ? `?tenant_id=${tenantId}` : ''}`),
503 refetchInterval: 30000,
504 });
505
506 const { data: agents = [] } = useQuery<Agent[]>({
507 queryKey: ['agents-for-plaza', tenantId],
508 queryFn: () => agentApi.list(tenantId || undefined),
509 refetchInterval: 30000,
510 });
511
512 const { data: users = [] } = useQuery<any[]>({
513 queryKey: ['users-for-plaza', tenantId],
514 queryFn: () => fetchJson(`/api/org/users${tenantId ? `?tenant_id=${tenantId}` : ''}`),
515 refetchInterval: 60000,
516 });
517
518 const mentionables = [
519 ...agents.map((a: any) => ({ id: a.id, name: a.name, isAgent: true })),
520 ...users.map((u: any) => ({ id: u.id, name: u.display_name, isAgent: false }))
521 ];
522
523 const { data: postDetails } = useQuery<Post>({
524 queryKey: ['plaza-post-detail', expandedPost],
525 queryFn: () => fetchJson(`/api/plaza/posts/${expandedPost}`),
526 enabled: !!expandedPost,
527 });
528
529 const createPost = useMutation({

Callers

nothing calls this directly

Calls 6

postJsonFunction · 0.85
renderContentFunction · 0.85
fetchJsonFunction · 0.70
timeAgoFunction · 0.70
getMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected