mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
perf: eliminate redundant derived state in board and post views
This commit is contained in:
@@ -269,15 +269,7 @@ const Board = () => {
|
||||
document.title = boardTitle + ' - plebchan';
|
||||
}, [title, shortAddress, subplebbitAddress]);
|
||||
|
||||
// probably not necessary to show the error to the user if the feed loaded successfully
|
||||
const [shouldShowErrorToUser, setShouldShowErrorToUser] = useState(false);
|
||||
useEffect(() => {
|
||||
if (error?.message && feed.length === 0) {
|
||||
setShouldShowErrorToUser(true);
|
||||
} else if (feed.length > 0) {
|
||||
setShouldShowErrorToUser(false);
|
||||
}
|
||||
}, [error, feed]);
|
||||
const shouldShowErrorToUser = error?.message && feed.length === 0;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -462,7 +462,7 @@ const Catalog = () => {
|
||||
}, [clearMatchedFilters, subplebbitAddress]);
|
||||
|
||||
// Apply filter colors to posts when feed changes
|
||||
useEffect(() => {
|
||||
const coloredFeed = useMemo(() => {
|
||||
if (combinedFeed.length > 0 && filterItems.length > 0) {
|
||||
// Clear existing matched filters
|
||||
clearMatchedFilters();
|
||||
@@ -482,6 +482,7 @@ const Catalog = () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
return combinedFeed;
|
||||
}, [combinedFeed, filterItems, clearMatchedFilters]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -85,14 +85,7 @@ const PostPage = () => {
|
||||
}, [title, shortAddress, subplebbitAddress, post?.title, post?.content, isInAllView, t]);
|
||||
|
||||
// probably not necessary to show the error to the user if the post loaded successfully
|
||||
const [shouldShowErrorToUser, setShouldShowErrorToUser] = useState(false);
|
||||
useEffect(() => {
|
||||
if (post?.error && ((post?.replyCount > 0 && post?.replies?.length === 0) || (post?.state === 'failed' && post?.error))) {
|
||||
setShouldShowErrorToUser(true);
|
||||
} else if (post?.replyCount > 0 && post?.replies?.length > 0) {
|
||||
setShouldShowErrorToUser(false);
|
||||
}
|
||||
}, [post]);
|
||||
const shouldShowErrorToUser = post?.error && ((post?.replyCount > 0 && post?.replies?.length === 0) || (post?.state === 'failed' && post?.error));
|
||||
|
||||
return (
|
||||
<div className={styles.content}>
|
||||
|
||||
Reference in New Issue
Block a user