mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix performance, styling
This commit is contained in:
@@ -197,8 +197,8 @@ const PostMessage = ({ post }: PostProps) => {
|
|||||||
<span className={styles.editedInfo}>
|
<span className={styles.editedInfo}>
|
||||||
{showOriginal && <Markdown content={original?.content} />}
|
{showOriginal && <Markdown content={original?.content} />}
|
||||||
<br />
|
<br />
|
||||||
{t('comment_edited_at_timestamp', { timestamp: getFormattedDate(edit?.timestamp), interpolation: { escapeValue: false } })}
|
{t('comment_edited_at_timestamp', { timestamp: getFormattedDate(edit?.timestamp), interpolation: { escapeValue: false } })}{' '}
|
||||||
{reason && <> {t('reason_reason', { reason: reason, interpolation: { escapeValue: false } })}</>}
|
{reason && <>{t('reason_reason', { reason: reason, interpolation: { escapeValue: false } })} </>}
|
||||||
{showOriginal ? (
|
{showOriginal ? (
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey={'click_here_to_hide_original'}
|
i18nKey={'click_here_to_hide_original'}
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ const PostMessageMobile = ({ post }: PostProps) => {
|
|||||||
<span className={styles.editedInfo}>
|
<span className={styles.editedInfo}>
|
||||||
{showOriginal && <Markdown content={original?.content} />}
|
{showOriginal && <Markdown content={original?.content} />}
|
||||||
<br />
|
<br />
|
||||||
{t('comment_edited_at_timestamp', { timestamp: getFormattedDate(edit?.timestamp), interpolation: { escapeValue: false } })}
|
{t('comment_edited_at_timestamp', { timestamp: getFormattedDate(edit?.timestamp), interpolation: { escapeValue: false } })}{' '}
|
||||||
{reason && <> {t('reason_reason', { reason: reason, interpolation: { escapeValue: false } })}</>}
|
{reason && <>{t('reason_reason', { reason: reason, interpolation: { escapeValue: false } })} </>}
|
||||||
{showOriginal ? (
|
{showOriginal ? (
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey={'click_here_to_hide_original'}
|
i18nKey={'click_here_to_hide_original'}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useCallback } from 'react';
|
import { useState } from 'react';
|
||||||
import useIsMobile from './use-is-mobile';
|
import useIsMobile from './use-is-mobile';
|
||||||
import useSelectedTextStore from '../stores/use-selected-text-store';
|
import useSelectedTextStore from '../stores/use-selected-text-store';
|
||||||
|
|
||||||
@@ -7,33 +7,35 @@ const useReplyModal = () => {
|
|||||||
const [activeCid, setActiveCid] = useState<string | null>(null);
|
const [activeCid, setActiveCid] = useState<string | null>(null);
|
||||||
const { resetSelectedText, setSelectedText } = useSelectedTextStore();
|
const { resetSelectedText, setSelectedText } = useSelectedTextStore();
|
||||||
|
|
||||||
// on mobile, the position is absolute instead of fixed, so we need to calculate the top position
|
// on mobile, the css position is absolute instead of fixed, so we need to calculate the top position
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
const [scrollY, setScrollY] = useState<number>(0);
|
const [scrollY, setScrollY] = useState<number>(0);
|
||||||
|
|
||||||
const closeModal = useCallback(() => {
|
const closeModal = () => {
|
||||||
resetSelectedText();
|
resetSelectedText();
|
||||||
setActiveCid(null);
|
setActiveCid(null);
|
||||||
setShowReplyModal(false);
|
setShowReplyModal(false);
|
||||||
}, [resetSelectedText]);
|
};
|
||||||
|
|
||||||
const openReplyModal = useCallback(
|
const getSelectedText = () => {
|
||||||
(cid: string) => {
|
let text = document.getSelection()?.toString();
|
||||||
let text = document.getSelection()?.toString();
|
text && setSelectedText(`>${text}\n`);
|
||||||
text && setSelectedText(`>${text}\n`);
|
};
|
||||||
if (isMobile) {
|
|
||||||
const currentScrollY = window.scrollY;
|
const openReplyModal = (cid: string) => {
|
||||||
setScrollY(currentScrollY);
|
getSelectedText();
|
||||||
}
|
|
||||||
if (activeCid && activeCid !== cid) {
|
if (isMobile) {
|
||||||
return;
|
const currentScrollY = window.scrollY;
|
||||||
} else if (!activeCid) {
|
setScrollY(currentScrollY);
|
||||||
setActiveCid(cid);
|
}
|
||||||
setShowReplyModal(true);
|
|
||||||
}
|
if (activeCid && activeCid !== cid) {
|
||||||
},
|
return;
|
||||||
[activeCid, isMobile, setSelectedText],
|
}
|
||||||
);
|
setActiveCid(cid);
|
||||||
|
setShowReplyModal(true);
|
||||||
|
};
|
||||||
|
|
||||||
return { activeCid, closeModal, openReplyModal, scrollY, showReplyModal };
|
return { activeCid, closeModal, openReplyModal, scrollY, showReplyModal };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user