mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(publish): use active account at publish time instead of baking stale author data at typing time
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { Comment, useAccount, usePublishComment } from '@bitsocialhq/pkc-react-hooks';
|
import { Comment, usePublishComment } from '@bitsocialhq/pkc-react-hooks';
|
||||||
import usePublishPostStore from '../stores/use-publish-post-store';
|
import usePublishPostStore from '../stores/use-publish-post-store';
|
||||||
|
|
||||||
const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) => {
|
const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) => {
|
||||||
const account = useAccount();
|
|
||||||
|
|
||||||
const { author, title, content, link, spoiler, publishCommentOptions } = usePublishPostStore((state) => ({
|
const { author, title, content, link, spoiler, publishCommentOptions } = usePublishPostStore((state) => ({
|
||||||
author: state.author,
|
author: state.author,
|
||||||
title: state.title || undefined,
|
title: state.title || undefined,
|
||||||
@@ -26,13 +24,13 @@ const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) =
|
|||||||
spoiler,
|
spoiler,
|
||||||
};
|
};
|
||||||
|
|
||||||
baseOptions.author = {
|
const displayName = author?.displayName;
|
||||||
...account?.author,
|
if (displayName) {
|
||||||
displayName: author?.displayName || account?.author?.displayName,
|
baseOptions.author = { displayName };
|
||||||
};
|
}
|
||||||
|
|
||||||
return baseOptions;
|
return baseOptions;
|
||||||
}, [author, content, link, spoiler, subplebbitAddress, title, account]);
|
}, [author, content, link, spoiler, subplebbitAddress, title]);
|
||||||
|
|
||||||
const setPublishPostOptions = useCallback(
|
const setPublishPostOptions = useCallback(
|
||||||
(options: Partial<Comment>) => {
|
(options: Partial<Comment>) => {
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { Comment, useAccount, usePublishComment } from '@bitsocialhq/pkc-react-hooks';
|
import { Comment, usePublishComment } from '@bitsocialhq/pkc-react-hooks';
|
||||||
import usePublishReplyStore from '../stores/use-publish-reply-store';
|
import usePublishReplyStore from '../stores/use-publish-reply-store';
|
||||||
import usePostNumberStore from '../stores/use-post-number-store';
|
import usePostNumberStore from '../stores/use-post-number-store';
|
||||||
import { getQuotedCidsFromContent, mergeQuotedCids } from '../lib/utils/reply-quote-utils';
|
import { getQuotedCidsFromContent, mergeQuotedCids } from '../lib/utils/reply-quote-utils';
|
||||||
|
|
||||||
const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; subplebbitAddress: string; postCid?: string }) => {
|
const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; subplebbitAddress: string; postCid?: string }) => {
|
||||||
const parentCid = cid;
|
const parentCid = cid;
|
||||||
const account = useAccount();
|
|
||||||
|
|
||||||
const { author, content, link, spoiler, publishCommentOptions } = usePublishReplyStore((state) => ({
|
const { author, content, link, spoiler, publishCommentOptions } = usePublishReplyStore((state) => ({
|
||||||
author: state.author[parentCid],
|
author: state.author[parentCid],
|
||||||
@@ -29,13 +28,13 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
|
|||||||
spoiler,
|
spoiler,
|
||||||
};
|
};
|
||||||
|
|
||||||
baseOptions.author = {
|
const displayName = author?.displayName;
|
||||||
...account?.author,
|
if (displayName) {
|
||||||
displayName: author?.displayName || account?.author?.displayName,
|
baseOptions.author = { displayName };
|
||||||
};
|
}
|
||||||
|
|
||||||
return baseOptions;
|
return baseOptions;
|
||||||
}, [author, content, link, parentCid, postCid, spoiler, subplebbitAddress, account]);
|
}, [author, content, link, parentCid, postCid, spoiler, subplebbitAddress]);
|
||||||
|
|
||||||
const setPublishReplyOptions = useCallback(
|
const setPublishReplyOptions = useCallback(
|
||||||
(options: Partial<Comment>) => {
|
(options: Partial<Comment>) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user