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:
@@ -10,6 +10,8 @@ const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise
|
||||
|
||||
const testState = vi.hoisted(() => ({
|
||||
accountComment: undefined as { communityAddress?: string } | undefined,
|
||||
community: { address: 'music-posting.eth' } as { address?: string; name?: string; publicKey?: string } | undefined,
|
||||
communityIdentifier: { name: 'music-posting.eth' } as { name?: string; publicKey?: string } | undefined,
|
||||
directories: [{ address: 'music-posting.eth', title: '/mu/ - Music' }] as Array<{ address: string; title?: string }>,
|
||||
directoriesMetadata: { title: '/all/ - Directories' } as { title?: string } | undefined,
|
||||
isMobile: false,
|
||||
@@ -52,6 +54,7 @@ vi.mock('react-router-dom', async () => {
|
||||
vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
|
||||
useAccount: () => undefined,
|
||||
useAccountComment: () => testState.accountComment,
|
||||
useCommunity: () => testState.community,
|
||||
}));
|
||||
|
||||
vi.mock('@bitsocialnet/bitsocial-react-hooks/dist/stores/accounts', () => ({
|
||||
@@ -82,6 +85,10 @@ vi.mock('../../../hooks/use-directories', () => ({
|
||||
useDirectoriesMetadata: () => testState.directoriesMetadata,
|
||||
}));
|
||||
|
||||
vi.mock('../../../hooks/use-community-identifiers', () => ({
|
||||
useCommunityIdentifier: () => testState.communityIdentifier,
|
||||
}));
|
||||
|
||||
vi.mock('../../../hooks/use-resolved-community-address', () => ({
|
||||
useResolvedCommunityAddress: () => testState.resolvedAddress,
|
||||
}));
|
||||
@@ -122,6 +129,8 @@ describe('BoardHeader', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
testState.accountComment = undefined;
|
||||
testState.community = { address: 'music-posting.eth' };
|
||||
testState.communityIdentifier = { name: 'music-posting.eth' };
|
||||
testState.directories = [{ address: 'music-posting.eth', title: '/mu/ - Music' }];
|
||||
testState.directoriesMetadata = { title: '/all/ - Directories' };
|
||||
testState.isMobile = false;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useLocation, useParams, useNavigate } from 'react-router-dom';
|
||||
import { useCommunity } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import useAccountsStore from '@bitsocialnet/bitsocial-react-hooks/dist/stores/accounts';
|
||||
import useCommunitiesStore from '@bitsocialnet/bitsocial-react-hooks/dist/stores/communities';
|
||||
import getShortAddress from '../../lib/get-short-address';
|
||||
import { useCommunityIdentifier } from '../../hooks/use-community-identifiers';
|
||||
import { useStableCommunity } from '../../hooks/use-stable-community';
|
||||
import { isAllView, isSubscriptionsView, isModView } from '../../lib/utils/view-utils';
|
||||
import { isArchiveRoute } from '../../lib/utils/route-utils';
|
||||
@@ -27,9 +28,9 @@ const ImageBanner = () => {
|
||||
// Separate component for offline indicator to isolate rerenders from updatingState
|
||||
// Only this component will rerender when updatingState changes, not the whole BoardHeader
|
||||
const OfflineIndicator = ({ communityAddress }: { communityAddress: string | undefined }) => {
|
||||
// Subscribe to full community including transient state for offline detection
|
||||
const community = useCommunitiesStore((state) => (communityAddress ? state.communities[communityAddress] : undefined));
|
||||
const { isOffline, isOnlineStatusLoading, offlineIconClass, offlineTitle } = useIsCommunityOffline(community);
|
||||
const communityIdentifier = useCommunityIdentifier(communityAddress);
|
||||
const community = useCommunity(communityIdentifier ? { community: communityIdentifier } : undefined);
|
||||
const { isOffline, isOnlineStatusLoading, offlineIconClass, offlineTitle } = useIsCommunityOffline(community, communityAddress);
|
||||
|
||||
if (!isOffline && !isOnlineStatusLoading) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user