2025-09-03 15:56:00 +05:30
|
|
|
import { useMemo } from 'react';
|
2025-09-18 17:02:11 +05:30
|
|
|
import { useForumData, CellWithStats } from '../core/useForumData';
|
|
|
|
|
import { useAuth } from '../../contexts/AuthContext';
|
2025-09-18 11:08:42 +05:30
|
|
|
import { EVerificationStatus } from '@opchan/core';
|
2025-09-03 15:56:00 +05:30
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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] || [];
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const isUserAdmin = currentUser
|
2025-09-18 17:02:11 +05:30
|
|
|
? currentUser.address === (cell as unknown as { signature?: string }).signature
|
2025-09-03 15:56:00 +05:30
|
|
|
: false;
|
|
|
|
|
const canModerate = isUserAdmin;
|
|
|
|
|
const canPost = currentUser
|
2025-09-05 13:41:37 +05:30
|
|
|
? currentUser.verificationStatus ===
|
|
|
|
|
EVerificationStatus.ENS_ORDINAL_VERIFIED ||
|
|
|
|
|
currentUser.verificationStatus ===
|
|
|
|
|
EVerificationStatus.WALLET_CONNECTED ||
|
2025-09-03 15:56:00 +05:30
|
|
|
Boolean(currentUser.ensDetails) ||
|
|
|
|
|
Boolean(currentUser.ordinalDetails)
|
|
|
|
|
: false;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...cell,
|
|
|
|
|
posts,
|
|
|
|
|
isUserAdmin,
|
|
|
|
|
canModerate,
|
|
|
|
|
canPost,
|
|
|
|
|
};
|
|
|
|
|
}, [cellId, cellsWithStats, postsByCell, commentsByPost, currentUser]);
|
|
|
|
|
}
|