Passed
Push — dev ( f9c292...1db7a6 )
by
unknown
04:06 queued 11s
created

resources/assets/js/store/User/userSelector.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 34
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 29
c 0
b 0
f 0
dl 0
loc 34
rs 10
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
import { createSelector } from "reselect";
2
import { RootState } from "../store";
3
import { User } from "../../models/types";
4
import { hasKey } from "../../helpers/queries";
5
6
const getUsersById = (state: RootState): { [id: number]: User } =>
7
  state.users.usersById;
8
9
export const getUsers = createSelector(getUsersById, (usersById): User[] =>
10
  Object.values(usersById),
11
);
12
13
export const getUserById = (
14
  state: RootState,
15
  { userId }: { userId: number },
16
): User | null => {
17
  const usersById = getUsersById(state);
18
  return hasKey(usersById, userId) ? usersById[userId] : null;
19
};
20
21
export const getUserIsUpdating = (
22
  state: RootState,
23
  { userId }: { userId: number },
24
): boolean => {
25
  const updatingById = state.users.userIsUpdating;
26
  return (
27
    state.users.allUsersUpdating ||
28
    (hasKey(updatingById, userId) && updatingById[userId])
29
  );
30
};
31
32
export const getAllUsersUpdating = (state: RootState): boolean =>
33
  state.users.allUsersUpdating;
34