Skip to content
This repository has been archived by the owner on Mar 23, 2022. It is now read-only.

Commit

Permalink
Fixed UI lag on section expansion #344
Browse files Browse the repository at this point in the history
Signed-off-by: RaenonX <[email protected]>
  • Loading branch information
RaenonX committed Jan 11, 2022
1 parent 730f78b commit 03031ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/components/elements/posts/output/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const CollapsibleSectionedContent = <E, >({sections, getTitle, renderSect
const [open, setOpen] = React.useState(Object.fromEntries(sections.map((section) => [getTitle(section), false])));
const [allOpen, setAllOpen] = React.useState(false);

const [content] = React.useState(sections.map((section) => renderSection(section)));

const onClickAllOpen = () => {
const newAllOpen = !allOpen;

Expand All @@ -38,7 +40,7 @@ export const CollapsibleSectionedContent = <E, >({sections, getTitle, renderSect
</Button>
</Col>
</Row>
{sections.map((section) => {
{sections.map((section, idx) => {
const title = getTitle(section);

return (
Expand All @@ -57,7 +59,7 @@ export const CollapsibleSectionedContent = <E, >({sections, getTitle, renderSect
<Collapse in={open[title]} className="mb-2">
{/* Needs a ref-able element for showing/hiding the element */}
<div>
{renderSection(section)}
{content[idx]}
</div>
</Collapse>
</React.Fragment>
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/posts/misc/output/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const MiscSectionOutput = ({sections}: Props) => {
<CollapsibleSectionedContent
sections={sections}
getTitle={(section) => section.title}
renderSection={(section) => <Markdown>{section.content}</Markdown>}
renderSection={({content}) => <Markdown>{content}</Markdown>}
/>
</>
);
Expand Down

0 comments on commit 03031ef

Please sign in to comment.