mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-01-05 14:23:06 +00:00
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
|
|
import { useMemo } from 'react';
|
||
|
|
import { useForumData, CellWithStats } from '@/hooks/core/useForumData';
|
||
|
|
import { useAuth } from '@/hooks/core/useEnhancedAuth';
|
||
|
|
|
||
|
|
export interface CellData extends CellWithStats {
|
||
|
|
posts: Array<{
|
||
|
|
id: string;
|
||
|
|
title: string;
|
||
|
|
content: string;
|
||
|
|
author: string;
|
||
|
|
timestamp: number;
|
||
|
|
voteScore: number;
|
||
|
|
commentCount: number;
|
||
|
|
}>;
|
||
|
|
isUserAdmin: boolean;
|
||
|
|
canModerate: boolean;
|
||
|
|
canPost: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Hook for getting a specific cell with its posts and permissions
|
||
|
|
*/
|
||
|
|
export function useCell(cellId: string | undefined): CellData | null {
|
||
|
|
const { cellsWithStats, postsByCell, commentsByPost } = useForumData();
|
||
|
|
const { currentUser } = useAuth();
|
||
|
|
|
||
|
|
return useMemo(() => {
|
||
|
|
if (!cellId) return null;
|
||
|
|
|
||
|
|
const cell = cellsWithStats.find(c => c.id === cellId);
|
||
|
|
if (!cell) return null;
|
||
|
|
|
||
|
|
const cellPosts = postsByCell[cellId] || [];
|
||
|
|
|
||
|
|
// Transform posts to include comment count
|
||
|
|
const posts = cellPosts.map(post => ({
|
||
|
|
id: post.id,
|
||
|
|
title: post.title,
|
||
|
|
content: post.content,
|
||
|
|
author: post.author,
|
||
|
|
timestamp: post.timestamp,
|
||
|
|
voteScore: post.voteScore,
|
||
|
|
commentCount: (commentsByPost[post.id] || []).length,
|
||
|
|
}));
|
||
|
|
|
||
|
|
// Check user permissions
|
||
|
|
const isUserAdmin = currentUser
|
||
|
|
? currentUser.address === cell.signature
|
||
|
|
: false;
|
||
|
|
const canModerate = isUserAdmin;
|
||
|
|
const canPost = currentUser
|
||
|
|
? currentUser.verificationStatus === 'verified-owner' ||
|
||
|
|
currentUser.verificationStatus === 'verified-basic' ||
|
||
|
|
Boolean(currentUser.ensDetails) ||
|
||
|
|
Boolean(currentUser.ordinalDetails)
|
||
|
|
: false;
|
||
|
|
|
||
|
|
return {
|
||
|
|
...cell,
|
||
|
|
posts,
|
||
|
|
isUserAdmin,
|
||
|
|
canModerate,
|
||
|
|
canPost,
|
||
|
|
};
|
||
|
|
}, [cellId, cellsWithStats, postsByCell, commentsByPost, currentUser]);
|
||
|
|
}
|