fix(quotes): keep same-thread board previews local

This commit is contained in:
Tommaso Casaburi
2026-04-16 15:33:12 +07:00
parent f6ce2ba018
commit e366dac25c
16 changed files with 293 additions and 64 deletions
@@ -4,7 +4,7 @@ import useCreateBoardModalStore from '../use-create-board-modal-store';
import useDirectoryModalStore from '../use-directory-modal-store';
import useDisclaimerModalStore, { DISCLAIMER_ACCEPTED_KEY } from '../use-disclaimer-modal-store';
import useFeedResetStore from '../use-feed-reset-store';
import usePostNumberStore from '../use-post-number-store';
import usePostNumberStore, { getCidForPostNumber, getScopedNumberToCidMap } from '../use-post-number-store';
import useReplyModalStore from '../use-reply-modal-store';
import useSelectedTextStore from '../use-selected-text-store';
import useSortingStore from '../use-sorting-store';
@@ -235,6 +235,26 @@ describe('interaction stores', () => {
expect(usePostNumberStore.getState().numberToCid).toBe(numberToCidRef);
});
it('merges alias-scoped post number maps when the exact board scope is only partially populated', () => {
const numberToCid = {
'music.eth': {
1: 'op-cid',
2: 'reply-cid',
},
'music.bso': {
30: 'late-reply-cid',
},
};
expect(getScopedNumberToCidMap(numberToCid, 'music.bso')).toEqual({
1: 'op-cid',
2: 'reply-cid',
30: 'late-reply-cid',
});
expect(getCidForPostNumber(numberToCid, 'music.bso', 1)).toBe('op-cid');
expect(getCidForPostNumber(numberToCid, 'music.bso', 30)).toBe('late-reply-cid');
});
it('opens reply modals with quoted selection and mobile scroll state', () => {
Object.defineProperty(window, 'innerWidth', {
configurable: true,
+33
View File
@@ -1,5 +1,6 @@
import { create } from 'zustand';
import type { Comment } from '@bitsocialnet/bitsocial-react-hooks';
import { normalizeBoardAddress } from '../hooks/use-directories';
interface PostNumberState {
// Post numbers are only unique within a board, so scope by canonical community address.
@@ -8,6 +9,38 @@ interface PostNumberState {
registerComments: (comments: Comment[]) => void;
}
export const getScopedNumberToCidMap = (numberToCid: Record<string, Record<number, string>>, communityAddress?: string) => {
if (!communityAddress) {
return undefined;
}
const normalizedCommunityAddress = normalizeBoardAddress(communityAddress);
const exactMatch = numberToCid[communityAddress];
const matchingEntries = Object.entries(numberToCid).filter(([address]) => normalizeBoardAddress(address) === normalizedCommunityAddress);
if (matchingEntries.length === 0) {
return exactMatch;
}
if (!exactMatch && matchingEntries.length === 1) {
return matchingEntries[0][1];
}
if (!exactMatch) {
return matchingEntries.reduce<Record<number, string>>((mergedMap, [, scopedMap]) => ({ ...mergedMap, ...scopedMap }), {});
}
if (matchingEntries.length === 1) {
return exactMatch;
}
const aliasEntries = matchingEntries.filter(([address]) => address !== communityAddress);
return aliasEntries.reduce<Record<number, string>>((mergedMap, [, scopedMap]) => ({ ...mergedMap, ...scopedMap }), { ...exactMatch });
};
export const getCidForPostNumber = (numberToCid: Record<string, Record<number, string>>, communityAddress: string | undefined, postNumber: number) =>
getScopedNumberToCidMap(numberToCid, communityAddress)?.[postNumber];
const usePostNumberStore = create<PostNumberState>((set) => ({
numberToCid: {},
cidToNumber: {},