mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
pass threadNumber to reply modal store
This commit is contained in:
+2
-1
@@ -113,7 +113,7 @@ const GlobalLayout = () => {
|
|||||||
}
|
}
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
const { activeCid, parentNumber, threadCid, subplebbitAddress, closeModal, showReplyModal, scrollY } = useReplyModalStore();
|
const { activeCid, parentNumber, threadNumber, threadCid, subplebbitAddress, closeModal, showReplyModal, scrollY } = useReplyModalStore();
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isInSettingsView = location.pathname.endsWith('/settings');
|
const isInSettingsView = location.pathname.endsWith('/settings');
|
||||||
@@ -126,6 +126,7 @@ const GlobalLayout = () => {
|
|||||||
closeModal={closeModal}
|
closeModal={closeModal}
|
||||||
parentCid={activeCid}
|
parentCid={activeCid}
|
||||||
parentNumber={parentNumber}
|
parentNumber={parentNumber}
|
||||||
|
threadNumber={threadNumber}
|
||||||
postCid={threadCid}
|
postCid={threadCid}
|
||||||
scrollY={scrollY}
|
scrollY={scrollY}
|
||||||
showReplyModal={showReplyModal}
|
showReplyModal={showReplyModal}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const useShowOmittedReplies = create<ShowOmittedRepliesState>((set) => ({
|
|||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const PostInfo = ({ post, postReplyCount = 0, roles, isHidden }: PostProps) => {
|
const PostInfo = ({ post, postReplyCount = 0, roles, isHidden, threadNumber }: PostProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { author, cid, deleted, locked, pinned, parentCid, postCid, reason, removed, state, subplebbitAddress, timestamp } = post || {};
|
const { author, cid, deleted, locked, pinned, parentCid, postCid, reason, removed, state, subplebbitAddress, timestamp } = post || {};
|
||||||
const title = post?.title?.trim();
|
const title = post?.title?.trim();
|
||||||
@@ -94,7 +94,7 @@ const PostInfo = ({ post, postReplyCount = 0, roles, isHidden }: PostProps) => {
|
|||||||
? isReply
|
? isReply
|
||||||
? alert(t('this_reply_was_removed'))
|
? alert(t('this_reply_was_removed'))
|
||||||
: alert(t('this_thread_was_removed'))
|
: alert(t('this_thread_was_removed'))
|
||||||
: openReplyModal && openReplyModal(cid, post?.number, postCid, subplebbitAddress);
|
: openReplyModal && openReplyModal(cid, post?.number, postCid, threadNumber, subplebbitAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -325,7 +325,7 @@ const PostMedia = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Reply = ({ postReplyCount, reply, roles }: PostProps) => {
|
const Reply = ({ postReplyCount, reply, roles, threadNumber }: PostProps) => {
|
||||||
let post = reply;
|
let post = reply;
|
||||||
// handle pending mod or author edit
|
// handle pending mod or author edit
|
||||||
const { editedComment } = useEditedComment({ comment: reply });
|
const { editedComment } = useEditedComment({ comment: reply });
|
||||||
@@ -353,7 +353,7 @@ const Reply = ({ postReplyCount, reply, roles }: PostProps) => {
|
|||||||
<div className={styles.replyDesktop}>
|
<div className={styles.replyDesktop}>
|
||||||
<div className={styles.sideArrows}>{'>>'}</div>
|
<div className={styles.sideArrows}>{'>>'}</div>
|
||||||
<div className={`${styles.reply} ${isRouteLinkToReply && styles.highlight}`} data-cid={cid} data-author-address={author?.shortAddress} data-post-cid={postCid}>
|
<div className={`${styles.reply} ${isRouteLinkToReply && styles.highlight}`} data-cid={cid} data-author-address={author?.shortAddress} data-post-cid={postCid}>
|
||||||
<PostInfo post={post} postReplyCount={postReplyCount} roles={roles} isHidden={hidden} />
|
<PostInfo post={post} postReplyCount={postReplyCount} roles={roles} isHidden={hidden} threadNumber={threadNumber} />
|
||||||
{link && !hidden && !(deleted || removed) && isValidURL(link) && (
|
{link && !hidden && !(deleted || removed) && isValidURL(link) && (
|
||||||
<PostMedia
|
<PostMedia
|
||||||
commentMediaInfo={commentMediaInfo}
|
commentMediaInfo={commentMediaInfo}
|
||||||
@@ -469,7 +469,7 @@ const PostDesktop = ({ post, roles, showAllReplies, showReplies = true }: PostPr
|
|||||||
isInSubscriptionsView={isInSubscriptionsView}
|
isInSubscriptionsView={isInSubscriptionsView}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<PostInfo isHidden={hidden} post={post} postReplyCount={replyCount} roles={roles} />
|
<PostInfo isHidden={hidden} post={post} postReplyCount={replyCount} roles={roles} threadNumber={post?.number} />
|
||||||
{!isHidden && !content && !(deleted || removed) && <div className={styles.spacer} />}
|
{!isHidden && !content && !(deleted || removed) && <div className={styles.spacer} />}
|
||||||
{!isHidden && <CommentContent comment={post} />}
|
{!isHidden && <CommentContent comment={post} />}
|
||||||
</div>
|
</div>
|
||||||
@@ -506,7 +506,7 @@ const PostDesktop = ({ post, roles, showAllReplies, showReplies = true }: PostPr
|
|||||||
data={filteredReplies}
|
data={filteredReplies}
|
||||||
itemContent={(index, reply) => (
|
itemContent={(index, reply) => (
|
||||||
<div className={styles.replyContainer}>
|
<div className={styles.replyContainer}>
|
||||||
<Reply reply={reply} roles={roles} postReplyCount={replyCount} />
|
<Reply reply={reply} roles={roles} postReplyCount={replyCount} threadNumber={post?.number} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
useWindowScroll={true}
|
useWindowScroll={true}
|
||||||
@@ -525,7 +525,7 @@ const PostDesktop = ({ post, roles, showAllReplies, showReplies = true }: PostPr
|
|||||||
replyCount <= 25 &&
|
replyCount <= 25 &&
|
||||||
filteredReplies.map((reply, index) => (
|
filteredReplies.map((reply, index) => (
|
||||||
<div key={index} className={styles.replyContainer}>
|
<div key={index} className={styles.replyContainer}>
|
||||||
<Reply reply={reply} roles={roles} postReplyCount={replyCount} />
|
<Reply reply={reply} roles={roles} postReplyCount={replyCount} threadNumber={post?.number} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{/* Non-virtualized rendering for board view (last 5 replies or show omitted) */}
|
{/* Non-virtualized rendering for board view (last 5 replies or show omitted) */}
|
||||||
@@ -537,7 +537,7 @@ const PostDesktop = ({ post, roles, showAllReplies, showReplies = true }: PostPr
|
|||||||
showReplies &&
|
showReplies &&
|
||||||
(showOmittedReplies[cid] ? filteredReplies : filteredReplies.slice(-5)).map((reply, index) => (
|
(showOmittedReplies[cid] ? filteredReplies : filteredReplies.slice(-5)).map((reply, index) => (
|
||||||
<div key={index} className={styles.replyContainer}>
|
<div key={index} className={styles.replyContainer}>
|
||||||
<Reply reply={reply} roles={roles} postReplyCount={replyCount} />
|
<Reply reply={reply} roles={roles} postReplyCount={replyCount} threadNumber={post?.number} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import { selectPostMenuProps } from '../../lib/utils/post-menu-props';
|
|||||||
// Store scroll position for replies virtuoso across navigations
|
// Store scroll position for replies virtuoso across navigations
|
||||||
const lastVirtuosoStates: { [key: string]: StateSnapshot } = {};
|
const lastVirtuosoStates: { [key: string]: StateSnapshot } = {};
|
||||||
|
|
||||||
const PostInfoAndMedia = ({ post, postReplyCount = 0, roles }: PostProps) => {
|
const PostInfoAndMedia = ({ post, postReplyCount = 0, roles, threadNumber }: PostProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const defaultSubplebbits = useDefaultSubplebbits();
|
const defaultSubplebbits = useDefaultSubplebbits();
|
||||||
const { author, cid, deleted, link, linkHeight, linkWidth, locked, parentCid, pinned, postCid, reason, removed, state, subplebbitAddress, timestamp, thumbnailUrl } =
|
const { author, cid, deleted, link, linkHeight, linkWidth, locked, parentCid, pinned, postCid, reason, removed, state, subplebbitAddress, timestamp, thumbnailUrl } =
|
||||||
@@ -78,7 +78,7 @@ const PostInfoAndMedia = ({ post, postReplyCount = 0, roles }: PostProps) => {
|
|||||||
? isReply
|
? isReply
|
||||||
? alert(t('this_reply_was_removed'))
|
? alert(t('this_reply_was_removed'))
|
||||||
: alert(t('this_thread_was_removed'))
|
: alert(t('this_thread_was_removed'))
|
||||||
: openReplyModal && openReplyModal(cid, post?.number, postCid, subplebbitAddress);
|
: openReplyModal && openReplyModal(cid, post?.number, postCid, threadNumber, subplebbitAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -249,7 +249,7 @@ const ReplyBacklinks = ({ post }: PostProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Reply = ({ postReplyCount, reply, roles }: PostProps) => {
|
const Reply = ({ postReplyCount, reply, roles, threadNumber }: PostProps) => {
|
||||||
let post = reply;
|
let post = reply;
|
||||||
// handle pending mod or author edit
|
// handle pending mod or author edit
|
||||||
const { editedComment } = useEditedComment({ comment: reply });
|
const { editedComment } = useEditedComment({ comment: reply });
|
||||||
@@ -273,7 +273,7 @@ const Reply = ({ postReplyCount, reply, roles }: PostProps) => {
|
|||||||
data-author-address={author?.shortAddress}
|
data-author-address={author?.shortAddress}
|
||||||
data-post-cid={postCid}
|
data-post-cid={postCid}
|
||||||
>
|
>
|
||||||
<PostInfoAndMedia post={post} postReplyCount={postReplyCount} roles={roles} />
|
<PostInfoAndMedia post={post} postReplyCount={postReplyCount} roles={roles} threadNumber={threadNumber} />
|
||||||
{!hidden && (!(removed || deleted) || ((removed || deleted) && reason)) && <CommentContent comment={post} />}
|
{!hidden && (!(removed || deleted) || ((removed || deleted) && reason)) && <CommentContent comment={post} />}
|
||||||
<ReplyBacklinks post={reply} />
|
<ReplyBacklinks post={reply} />
|
||||||
</div>
|
</div>
|
||||||
@@ -359,7 +359,7 @@ const PostMobile = ({ post, roles, showAllReplies, showReplies = true }: PostPro
|
|||||||
data-post-cid={postCid}
|
data-post-cid={postCid}
|
||||||
>
|
>
|
||||||
{shouldShowSnow() && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}
|
{shouldShowSnow() && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}
|
||||||
<PostInfoAndMedia post={post} postReplyCount={replyCount} roles={roles} />
|
<PostInfoAndMedia post={post} postReplyCount={replyCount} roles={roles} threadNumber={post?.number} />
|
||||||
<CommentContent comment={post} />
|
<CommentContent comment={post} />
|
||||||
</div>
|
</div>
|
||||||
{!isInPostView && !isInPendingPostView && showReplies && (
|
{!isInPostView && !isInPendingPostView && showReplies && (
|
||||||
@@ -382,7 +382,7 @@ const PostMobile = ({ post, roles, showAllReplies, showReplies = true }: PostPro
|
|||||||
data={filteredReplies}
|
data={filteredReplies}
|
||||||
itemContent={(index, reply) => (
|
itemContent={(index, reply) => (
|
||||||
<div className={styles.replyContainer}>
|
<div className={styles.replyContainer}>
|
||||||
<Reply postReplyCount={replyCount} reply={reply} roles={roles} />
|
<Reply postReplyCount={replyCount} reply={reply} roles={roles} threadNumber={post?.number} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
useWindowScroll={true}
|
useWindowScroll={true}
|
||||||
@@ -401,7 +401,7 @@ const PostMobile = ({ post, roles, showAllReplies, showReplies = true }: PostPro
|
|||||||
replyCount <= 25 &&
|
replyCount <= 25 &&
|
||||||
filteredReplies.map((reply, index) => (
|
filteredReplies.map((reply, index) => (
|
||||||
<div key={index} className={styles.replyContainer}>
|
<div key={index} className={styles.replyContainer}>
|
||||||
<Reply postReplyCount={replyCount} reply={reply} roles={roles} />
|
<Reply postReplyCount={replyCount} reply={reply} roles={roles} threadNumber={post?.number} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{/* Non-virtualized rendering for board view (last 5 replies) */}
|
{/* Non-virtualized rendering for board view (last 5 replies) */}
|
||||||
@@ -412,7 +412,7 @@ const PostMobile = ({ post, roles, showAllReplies, showReplies = true }: PostPro
|
|||||||
showReplies &&
|
showReplies &&
|
||||||
filteredReplies.slice(-5).map((reply, index) => (
|
filteredReplies.slice(-5).map((reply, index) => (
|
||||||
<div key={index} className={styles.replyContainer}>
|
<div key={index} className={styles.replyContainer}>
|
||||||
<Reply postReplyCount={replyCount} reply={reply} roles={roles} />
|
<Reply postReplyCount={replyCount} reply={reply} roles={roles} threadNumber={post?.number} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ interface ReplyModalProps {
|
|||||||
showReplyModal: boolean;
|
showReplyModal: boolean;
|
||||||
parentCid: string;
|
parentCid: string;
|
||||||
parentNumber: number | null;
|
parentNumber: number | null;
|
||||||
postNumber: number | null;
|
threadNumber: number | null;
|
||||||
postCid: string;
|
postCid: string;
|
||||||
scrollY: number;
|
scrollY: number;
|
||||||
subplebbitAddress: string;
|
subplebbitAddress: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, postNumber, postCid, scrollY, subplebbitAddress }: ReplyModalProps) => {
|
const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threadNumber, postCid, scrollY, subplebbitAddress }: ReplyModalProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { setPublishReplyOptions, publishReply, resetPublishReplyOptions, replyIndex } = usePublishReply({
|
const { setPublishReplyOptions, publishReply, resetPublishReplyOptions, replyIndex } = usePublishReply({
|
||||||
cid: parentCid,
|
cid: parentCid,
|
||||||
@@ -260,7 +260,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, postN
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className={`replyModalHandle ${styles.title}`} {...(!isMobile ? bind() : {})}>
|
<div className={`replyModalHandle ${styles.title}`} {...(!isMobile ? bind() : {})}>
|
||||||
{t('reply_to_no', { no: postNumber ?? '?' })}
|
{t('reply_to_no', { no: threadNumber ?? '?' })}
|
||||||
<button
|
<button
|
||||||
className={styles.closeIcon}
|
className={styles.closeIcon}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
|||||||
@@ -5,17 +5,19 @@ interface ReplyModalState {
|
|||||||
showReplyModal: boolean;
|
showReplyModal: boolean;
|
||||||
activeCid: string | null;
|
activeCid: string | null;
|
||||||
parentNumber: number | null;
|
parentNumber: number | null;
|
||||||
|
threadNumber: number | null;
|
||||||
threadCid: string | null;
|
threadCid: string | null;
|
||||||
subplebbitAddress: string | null;
|
subplebbitAddress: string | null;
|
||||||
scrollY: number;
|
scrollY: number;
|
||||||
closeModal: () => void;
|
closeModal: () => void;
|
||||||
openReplyModal: (parentCid: string, parentNumber: number | undefined, postCid: string, subplebbitAddress: string) => void;
|
openReplyModal: (parentCid: string, parentNumber: number | undefined, postCid: string, threadNumber: number | undefined, subplebbitAddress: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||||
showReplyModal: false,
|
showReplyModal: false,
|
||||||
activeCid: null,
|
activeCid: null,
|
||||||
parentNumber: null,
|
parentNumber: null,
|
||||||
|
threadNumber: null,
|
||||||
threadCid: null,
|
threadCid: null,
|
||||||
subplebbitAddress: null,
|
subplebbitAddress: null,
|
||||||
scrollY: 0,
|
scrollY: 0,
|
||||||
@@ -27,10 +29,11 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
|||||||
showReplyModal: false,
|
showReplyModal: false,
|
||||||
activeCid: null,
|
activeCid: null,
|
||||||
parentNumber: null,
|
parentNumber: null,
|
||||||
|
threadNumber: null,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
openReplyModal: (parentCid, parentNumber, postCid, subplebbitAddress) => {
|
openReplyModal: (parentCid, parentNumber, postCid, threadNumber, subplebbitAddress) => {
|
||||||
// Don't update if already open with different parent
|
// Don't update if already open with different parent
|
||||||
if (get().activeCid && get().activeCid !== parentCid) {
|
if (get().activeCid && get().activeCid !== parentCid) {
|
||||||
window.alert('Multiple quotes are not possible on 5chan for the time being, because of a protocol limitation. Please reply to one post at a time.');
|
window.alert('Multiple quotes are not possible on 5chan for the time being, because of a protocol limitation. Please reply to one post at a time.');
|
||||||
@@ -50,6 +53,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
|||||||
set({
|
set({
|
||||||
activeCid: parentCid,
|
activeCid: parentCid,
|
||||||
parentNumber: parentNumber ?? null,
|
parentNumber: parentNumber ?? null,
|
||||||
|
threadNumber: threadNumber ?? null,
|
||||||
threadCid: postCid,
|
threadCid: postCid,
|
||||||
showReplyModal: true,
|
showReplyModal: true,
|
||||||
subplebbitAddress,
|
subplebbitAddress,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface PostProps {
|
|||||||
roles?: Role[];
|
roles?: Role[];
|
||||||
showAllReplies?: boolean;
|
showAllReplies?: boolean;
|
||||||
showReplies?: boolean;
|
showReplies?: boolean;
|
||||||
|
threadNumber?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Post = ({ post, showAllReplies = false, showReplies = true }: PostProps) => {
|
export const Post = ({ post, showAllReplies = false, showReplies = true }: PostProps) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user