Skip to content

Commit

Permalink
Use memo
Browse files Browse the repository at this point in the history
  • Loading branch information
juniusfree committed Apr 8, 2024
1 parent 9dc592a commit d825fe1
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button, Grid, Stack, Typography, useTheme } from "@mui/material";
import { COMPONENT_CATEGORIES } from "components/AddFormEntity/constants";
import SafeImage from "components/SafeImage";
import Modal from "components/Shared/Modal";
import { useMemo } from "react";
import { CategoryTitle, ColumnContainer, OptionButton, OptionButtonLabel, OptionsColumnContainer } from "./styles";

const chooseIcon = (icon, category) => {
Expand Down Expand Up @@ -49,20 +50,24 @@ const OptionsColumn = ({ colOptions, options, onClick, onClose, showBorder }) =>
};

const ComponentOptionsModal = ({ open, onClose, onClick, options }) => {
const groupedOptionsByCategory = options.reduce((acc, option) => {
if (!acc[option.category]) {
acc[option.category] = [];
}
acc[option.category].push(option);
return acc;
}, {});
const { groupedOptionsByCategory, hasCustomComponent } = useMemo(
() => ({
groupedOptionsByCategory: options.reduce((acc, option) => {
if (!acc[option.category]) {
acc[option.category] = [];
}
acc[option.category].push(option);
return acc;
}, {}),
hasCustomComponent: options.some((option) => option.category === COMPONENT_CATEGORIES.CUSTOM),
}),
[options]
);

const leftColOptions = [COMPONENT_CATEGORIES.ACTION, COMPONENT_CATEGORIES.TWITTER];
const midColOptions = [COMPONENT_CATEGORIES.DISCORD, COMPONENT_CATEGORIES.YOUTUBE, COMPONENT_CATEGORIES.CRYPTO];
const rightColOptions = [COMPONENT_CATEGORIES.CUSTOM];

const hasCustomComponent = options.some((option) => option.category === COMPONENT_CATEGORIES.CUSTOM);

return (
<Modal open={open} onClose={onClose} maxWidth={hasCustomComponent ? 1200 : 800}>
<ColumnContainer>
Expand Down

0 comments on commit d825fe1

Please sign in to comment.