Skip to content

Commit

Permalink
some work towards memoizing selectors... much more to do here.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndepaola committed Dec 29, 2024
1 parent 0096aaf commit 9d83f45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions frontend/src/features/bulkManagement/bulkManagementRibbon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
clearQueries,
deleteSlots,
selectAllSelectedProjectMembersHaveTheSameQuery,
selectAllSlotsForFace,
selectAllSlotsForActiveFace,
selectIsProjectEmpty,
selectProjectMember,
selectSelectedSlots,
Expand Down Expand Up @@ -109,8 +109,7 @@ function SelectSimilar({
function SelectAll({ inDropdown }: { inDropdown: boolean }) {
const dispatch = useAppDispatch();

const face = useAppSelector(selectActiveFace);
const slots = useAppSelector((state) => selectAllSlotsForFace(state, face));
const slots = useAppSelector(selectAllSlotsForActiveFace);
const onClick = () =>
dispatch(bulkSetMemberSelection({ selectedStatus: true, slots: slots }));

Expand Down
14 changes: 8 additions & 6 deletions frontend/src/features/project/projectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Slots,
} from "@/common/types";
import { selectCardSizesByIdentifier } from "@/features/search/cardDocumentsSlice";
import { selectActiveFace } from "@/features/viewSettings/viewSettingsSlice";

//# region slice configuration

Expand Down Expand Up @@ -309,11 +310,12 @@ export const selectProjectMemberIdentifiers = createSelector(
)
);

export const selectAllSlotsForFace = (
state: RootState,
face: Faces
): Array<[Faces, number]> =>
state.project.members.map((_, index) => [face, index]);
export const selectAllSlotsForActiveFace = createSelector(
(state: RootState) => selectProjectSize(state),
(state: RootState) => selectActiveFace(state),
(projectSize, face): Array<[Faces, number]> =>
Array.from({ length: projectSize }, (_, index) => [face, index])
);

export const selectSelectedSlots = createSelector(
(state: RootState) => state.project.members,
Expand Down Expand Up @@ -440,7 +442,7 @@ export const selectAllSelectedProjectMembersHaveTheSameQuery = createSelector(
);

export const selectIsProjectEmpty = (state: RootState) =>
state.project.members.length == 0;
selectProjectSize(state) == 0;

export const selectProjectCardback = (state: RootState): string | undefined =>
state.project.cardback ?? undefined;
Expand Down

0 comments on commit 9d83f45

Please sign in to comment.