mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(board status): resolve offline indicators with strict community refs
This commit is contained in:
@@ -1,35 +1,9 @@
|
||||
import { useMemo } from 'react';
|
||||
import useCommunitiesStore from '@bitsocialnet/bitsocial-react-hooks/dist/stores/communities';
|
||||
import { normalizeBoardAddress, useDirectoryByAddress } from '../../hooks/use-directories';
|
||||
import { useCommunity } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { useCommunityIdentifier } from '../../hooks/use-community-identifiers';
|
||||
import { useDirectoryByAddress } from '../../hooks/use-directories';
|
||||
import useIsCommunityOffline from '../../hooks/use-is-community-offline';
|
||||
import { useResolvedCommunityAddress } from '../../hooks/use-resolved-community-address';
|
||||
|
||||
const BOARD_ALIAS_SUFFIXES = ['.bso', '.eth'] as const;
|
||||
|
||||
const getBoardAddressCandidates = (addresses: Array<string | undefined>) => {
|
||||
const uniqueCandidates = new Set<string>();
|
||||
|
||||
const addCandidate = (candidate: string | undefined) => {
|
||||
if (candidate) {
|
||||
uniqueCandidates.add(candidate);
|
||||
}
|
||||
};
|
||||
|
||||
addresses.forEach((address) => {
|
||||
if (!address) {
|
||||
return;
|
||||
}
|
||||
|
||||
addCandidate(address);
|
||||
|
||||
const normalizedAddress = normalizeBoardAddress(address);
|
||||
addCandidate(normalizedAddress);
|
||||
BOARD_ALIAS_SUFFIXES.forEach((suffix) => addCandidate(`${normalizedAddress}${suffix}`));
|
||||
});
|
||||
|
||||
return Array.from(uniqueCandidates);
|
||||
};
|
||||
|
||||
interface BoardOfflineAlertProps {
|
||||
className: string;
|
||||
hidden?: boolean;
|
||||
@@ -39,23 +13,10 @@ interface BoardOfflineAlertProps {
|
||||
const BoardOfflineAlert = ({ className, hidden = false, communityAddress }: BoardOfflineAlertProps) => {
|
||||
const resolvedCommunityAddress = useResolvedCommunityAddress();
|
||||
const directoryEntry = useDirectoryByAddress(resolvedCommunityAddress || communityAddress);
|
||||
const addressCandidates = useMemo(
|
||||
() => getBoardAddressCandidates([resolvedCommunityAddress, directoryEntry?.address, communityAddress]),
|
||||
[directoryEntry?.address, resolvedCommunityAddress, communityAddress],
|
||||
);
|
||||
|
||||
// Probe common aliases first so loading/offline state stays consistent across route and post payload address formats.
|
||||
const community = useCommunitiesStore((state) => {
|
||||
for (const candidate of addressCandidates) {
|
||||
const matchedCommunity = state.communities[candidate];
|
||||
if (matchedCommunity) {
|
||||
return matchedCommunity;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
const { isOffline, isOnlineStatusLoading, offlineTitle } = useIsCommunityOffline(community);
|
||||
const canonicalCommunityAddress = resolvedCommunityAddress || directoryEntry?.address || communityAddress;
|
||||
const communityIdentifier = useCommunityIdentifier(canonicalCommunityAddress);
|
||||
const community = useCommunity(communityIdentifier ? { community: communityIdentifier } : undefined);
|
||||
const { isOffline, isOnlineStatusLoading, offlineTitle } = useIsCommunityOffline(community, canonicalCommunityAddress);
|
||||
|
||||
if (hidden || (!isOffline && !isOnlineStatusLoading)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user