Merge pull request #182 from UniversityRadioYork/markspolakovs-reduce-item-render

Reduce Item renders
This commit is contained in:
Marks Polakovs 2020-11-10 23:06:18 +00:00 committed by GitHub
commit ae37c73b3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,14 +25,15 @@ export const Item = memo(function Item({
const isReal = "timeslotitemid" in x;
const isGhost = "ghostid" in x;
const playerState = useSelector((state: RootState) =>
column > -1 ? state.mixer.players[column] : undefined
const loadedItem = useSelector(
(state: RootState) =>
column > -1 ? state.mixer.players[column]?.loadedItem : null,
(a, b) =>
(a === null && b === null) ||
(a !== null && b !== null && itemId(a) === itemId(b))
);
const isLoaded =
playerState &&
playerState.loadedItem !== null &&
itemId(playerState.loadedItem) === id;
const isLoaded = loadedItem !== null ? itemId(loadedItem) === id : false;
const showDebug = useSelector(
(state: RootState) => state.settings.showDebugInfo
@ -59,14 +60,7 @@ export const Item = memo(function Item({
"item " +
("played" in x ? (x.played ? "played " : "") : "") +
x.type +
`${
column >= 0 &&
playerState &&
playerState.loadedItem !== null &&
itemId(playerState.loadedItem) === id
? " active"
: ""
}`
`${column >= 0 && isLoaded ? " active" : ""}`
}
onClick={triggerClick}
{...provided.draggableProps}