mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-28 18:39:12 +00:00
performance: memo
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import Icon from '@chakra-ui/icon';
|
import Icon from '@chakra-ui/icon';
|
||||||
import { FiChevronDown, FiChevronUp, FiMoreVertical } from 'react-icons/fi';
|
import { FiChevronDown, FiChevronUp, FiMoreVertical } from 'react-icons/fi';
|
||||||
import { memo, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Draggable } from 'react-beautiful-dnd';
|
import { Draggable } from 'react-beautiful-dnd';
|
||||||
import EventTimes from '../../../common/components/eventTimes/EventTimes';
|
import EventTimes from '../../../common/components/eventTimes/EventTimes';
|
||||||
import EventTimesVertical from '../../../common/components/eventTimes/EventTimesVertical';
|
import EventTimesVertical from '../../../common/components/eventTimes/EventTimesVertical';
|
||||||
@@ -11,16 +11,6 @@ import DeleteIconBtn from '../../../common/components/buttons/DeleteIconBtn';
|
|||||||
import { millisToMinutes } from '../../../common/dateConfig';
|
import { millisToMinutes } from '../../../common/dateConfig';
|
||||||
import style from './EventBlock.module.css';
|
import style from './EventBlock.module.css';
|
||||||
|
|
||||||
const areEqual = (prevProps, nextProps) => {
|
|
||||||
return (
|
|
||||||
prevProps.data.revision === nextProps.data.revision &&
|
|
||||||
prevProps.selected === nextProps.selected &&
|
|
||||||
prevProps.next === nextProps.next &&
|
|
||||||
prevProps.index === nextProps.index &&
|
|
||||||
prevProps.delay === nextProps.delay
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const ExpandedBlock = (props) => {
|
const ExpandedBlock = (props) => {
|
||||||
const { provided, data, next, delay, delayValue, actionHandler } = props;
|
const { provided, data, next, delay, delayValue, actionHandler } = props;
|
||||||
|
|
||||||
@@ -153,7 +143,7 @@ const CollapsedBlock = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const EventBlock = (props) => {
|
export default function EventBlock(props) {
|
||||||
const { data, selected, delay, index, actionHandler } = props;
|
const { data, selected, delay, index, actionHandler } = props;
|
||||||
|
|
||||||
const [expanded, setExpanded] = useState(true);
|
const [expanded, setExpanded] = useState(true);
|
||||||
@@ -200,6 +190,4 @@ const EventBlock = (props) => {
|
|||||||
)}
|
)}
|
||||||
</Draggable>
|
</Draggable>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default memo(EventBlock, areEqual);
|
|
||||||
|
|||||||
@@ -2,8 +2,19 @@ import DelayBlock from './DelayBlock';
|
|||||||
import BlockBlock from './BlockBlock';
|
import BlockBlock from './BlockBlock';
|
||||||
import EventBlock from './EventBlock';
|
import EventBlock from './EventBlock';
|
||||||
import { showErrorToast } from '../../../common/helpers/toastManager';
|
import { showErrorToast } from '../../../common/helpers/toastManager';
|
||||||
|
import { memo } from 'react';
|
||||||
|
|
||||||
export default function EventListItem(props) {
|
const areEqual = (prevProps, nextProps) => {
|
||||||
|
return (
|
||||||
|
prevProps.data.revision === nextProps.data.revision &&
|
||||||
|
prevProps.selected === nextProps.selected &&
|
||||||
|
prevProps.next === nextProps.next &&
|
||||||
|
prevProps.index === nextProps.index &&
|
||||||
|
prevProps.delay === nextProps.delay
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const EventListItem = (props) => {
|
||||||
const {
|
const {
|
||||||
type,
|
type,
|
||||||
index,
|
index,
|
||||||
@@ -83,4 +94,6 @@ export default function EventListItem(props) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default memo(EventListItem, areEqual);
|
||||||
|
|||||||
@@ -203,8 +203,7 @@ export default function EventListWrapper() {
|
|||||||
}, [isError]);
|
}, [isError]);
|
||||||
|
|
||||||
// Events API
|
// Events API
|
||||||
const eventsHandler = useCallback(
|
const eventsHandler = useCallback(async (action, payload) => {
|
||||||
async (action, payload) => {
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'add':
|
case 'add':
|
||||||
try {
|
try {
|
||||||
@@ -290,17 +289,7 @@ export default function EventListWrapper() {
|
|||||||
showErrorToast('Unrecognised request', action);
|
showErrorToast('Unrecognised request', action);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
}, []);
|
||||||
[
|
|
||||||
addEvent,
|
|
||||||
applyDelay,
|
|
||||||
data,
|
|
||||||
deleteEvent,
|
|
||||||
patchEvent,
|
|
||||||
reorderEvent,
|
|
||||||
updateEvent,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user