fix(hooks): handle pkc rebrand regressions

This commit is contained in:
Tommaso Casaburi
2026-04-11 16:57:00 +07:00
parent dcb3c4427c
commit 19095aefa1
19 changed files with 317 additions and 1186 deletions
@@ -76,10 +76,10 @@ describe('usePublishPost', () => {
expect(latestValue.publishPost).toBe(testState.publishCommentMock);
expect(latestValue.publishPostOptions).toMatchObject({
author: { displayName: 'Alice' },
communityAddress: 'music.eth',
content: undefined,
link: undefined,
spoiler: true,
subplebbitAddress: 'music.eth',
title: 'Hello world',
});
expect(typeof latestValue.publishPostOptions.onChallengeVerification).toBe('function');
@@ -104,13 +104,13 @@ describe('usePublishReply', () => {
expect(typeof latestValue.publishReply).toBe('function');
expect(testState.lastPublishOptions).toMatchObject({
author: { displayName: 'Bob' },
communityAddress: 'music.eth',
content: 'Replying to >>12',
link: undefined,
parentCid: 'parent-cid',
postCid: 'parent-cid',
quotedCids: ['quoted-cid'],
spoiler: true,
subplebbitAddress: 'music.eth',
});
});
+11 -2
View File
@@ -32,7 +32,6 @@ const usePublishPost = ({ communityAddress: requestedCommunityAddress, subplebbi
const createBaseOptions = useCallback(() => {
const baseOptions: Comment = {
communityAddress,
subplebbitAddress: communityAddress,
title,
content,
link,
@@ -58,7 +57,17 @@ const usePublishPost = ({ communityAddress: requestedCommunityAddress, subplebbi
{} as Partial<Comment>,
);
const newOptions = { ...baseOptions, ...sanitizedOptions };
const {
communityAddress: nextCommunityAddress,
subplebbitAddress: legacyCommunityAddress,
...restOptions
} = sanitizedOptions as Partial<Comment> & { subplebbitAddress?: string };
const resolvedCommunityAddress = nextCommunityAddress ?? legacyCommunityAddress ?? baseOptions.communityAddress;
const newOptions = {
...baseOptions,
...restOptions,
...(resolvedCommunityAddress ? { communityAddress: resolvedCommunityAddress } : {}),
};
setPublishPostStore(newOptions);
},
[createBaseOptions, setPublishPostStore],
+11 -2
View File
@@ -50,7 +50,6 @@ const usePublishReply = ({ cid, communityAddress: requestedCommunityAddress, sub
const createBaseOptions = useCallback(() => {
const baseOptions: Comment = {
communityAddress,
subplebbitAddress: communityAddress,
parentCid,
postCid: postCid ?? parentCid,
content,
@@ -77,7 +76,17 @@ const usePublishReply = ({ cid, communityAddress: requestedCommunityAddress, sub
{} as Partial<Comment>,
);
const newOptions = { ...baseOptions, ...sanitizedOptions };
const {
communityAddress: nextCommunityAddress,
subplebbitAddress: legacyCommunityAddress,
...restOptions
} = sanitizedOptions as Partial<Comment> & { subplebbitAddress?: string };
const resolvedCommunityAddress = nextCommunityAddress ?? legacyCommunityAddress ?? baseOptions.communityAddress;
const newOptions = {
...baseOptions,
...restOptions,
...(resolvedCommunityAddress ? { communityAddress: resolvedCommunityAddress } : {}),
};
setPublishReplyStore(newOptions);
},
[createBaseOptions, setPublishReplyStore],