mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(posts): render per-post IDs on initial board load
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { useDirectoryByAddress } from './use-directories';
|
||||
import { useSubplebbitField } from './use-stable-subplebbit';
|
||||
|
||||
/**
|
||||
* Prefer authoritative live board metadata when available, but fall back to the
|
||||
* bundled directory entry so known boards can render IDs immediately on first load.
|
||||
*/
|
||||
export const useBoardPseudonymityMode = (subplebbitAddress: string | undefined): string | undefined => {
|
||||
const directory = useDirectoryByAddress(subplebbitAddress);
|
||||
const livePseudonymityMode = useSubplebbitField(subplebbitAddress, (sub) => sub?.features?.pseudonymityMode);
|
||||
|
||||
return livePseudonymityMode ?? directory?.features?.pseudonymityMode;
|
||||
};
|
||||
@@ -50,6 +50,7 @@ const CACHE_MAX_AGE_MS = 60 * 60 * 1000; // 1 hour
|
||||
let cacheCommunities: DirectoryCommunity[] | null = null;
|
||||
let cacheMetadata: DirectoriesMetadata | null = null;
|
||||
let inFlightGitHubFetch: Promise<DirectoriesData> | null = null;
|
||||
const DIRECTORY_ALIAS_SUFFIXES = ['.bso', '.eth'] as const;
|
||||
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null;
|
||||
|
||||
@@ -134,6 +135,30 @@ const adaptV2Directories = (value: Record<string, unknown>): DirectoryCommunity[
|
||||
return dedupeCommunities(communities);
|
||||
};
|
||||
|
||||
const getDirectoryAddressLookupKey = (address: string): string => {
|
||||
for (const suffix of DIRECTORY_ALIAS_SUFFIXES) {
|
||||
if (address.endsWith(suffix)) {
|
||||
return address.slice(0, -suffix.length);
|
||||
}
|
||||
}
|
||||
|
||||
return address;
|
||||
};
|
||||
|
||||
const findDirectoryByAddress = (directories: DirectoryCommunity[], address: string | undefined): DirectoryCommunity | undefined => {
|
||||
if (!address) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const exactMatch = directories.find((community) => community.address === address);
|
||||
if (exactMatch) {
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
const addressLookupKey = getDirectoryAddressLookupKey(address);
|
||||
return directories.find((community) => getDirectoryAddressLookupKey(community.address) === addressLookupKey);
|
||||
};
|
||||
|
||||
const adaptV1Communities = (value: Record<string, unknown>): DirectoryCommunity[] => {
|
||||
if (!Array.isArray(value.communities)) {
|
||||
return [];
|
||||
@@ -376,7 +401,7 @@ export const useDirectoryAddresses = () => {
|
||||
|
||||
export const useDirectoryByAddress = (address: string | undefined) => {
|
||||
const directories = useDirectories();
|
||||
return useMemo(() => (address ? directories.find((c) => c.address === address) : undefined), [directories, address]);
|
||||
return useMemo(() => findDirectoryByAddress(directories, address), [directories, address]);
|
||||
};
|
||||
|
||||
export const useDirectoriesMetadata = () => {
|
||||
|
||||
Reference in New Issue
Block a user