selectors.ts 917 B

1234567891011121314151617181920
  1. import { ActionRemote, ActionStateSetLocal, ActionStateSetRemote } from './actions';
  2. import { GlobalState } from './reducer/types';
  3. export const isMaster = (state: Pick<GlobalState, 'player' | 'myClientName'>): boolean =>
  4. state.player.master === state.myClientName;
  5. export const isActiveClient = (state: Pick<GlobalState, 'player' | 'myClientName'>): boolean =>
  6. isMaster(state) || state.player.activeClients.includes(state.myClientName);
  7. export const isFromOurselves = (
  8. state: Pick<GlobalState, 'myClientName'>,
  9. action: ActionRemote,
  10. ): boolean => state.myClientName === action.fromClient;
  11. export const willBeMaster = (
  12. state: Partial<GlobalState> & Pick<GlobalState, 'myClientName'>,
  13. action: ActionStateSetLocal | ActionStateSetRemote,
  14. ): boolean => state.myClientName === action.payload?.master;
  15. export const getSongId = (state: Pick<GlobalState, 'player'>): number | null => state.player.songId;