actions.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Member, MusicPlayer } from '../types/state';
  2. import { ActionErrorOccurred } from './error';
  3. import { ActionLocal, ActionRemote, ActionTypeLocal, ActionTypeRemote } from './types';
  4. export * from './types';
  5. export type ActionStateSetRemote = ActionRemote<ActionTypeRemote.StateSet, MusicPlayer | null>;
  6. export type ActionClientListUpdated = ActionRemote<ActionTypeRemote.ClientListUpdated, Member[]>;
  7. export type RemoteAction = ActionStateSetRemote | ActionClientListUpdated;
  8. export type LoggedOut = ActionLocal<ActionTypeLocal.LoggedOut, void>;
  9. export const loggedOut = (): LoggedOut => ({ type: ActionTypeLocal.LoggedOut, payload: undefined });
  10. export type ActionNameSet = ActionLocal<ActionTypeLocal.NameSet, string>;
  11. export const nameSet = (name: string): ActionNameSet => ({
  12. type: ActionTypeLocal.NameSet,
  13. payload: name,
  14. });
  15. export type ActionStateSetLocal = ActionLocal<
  16. ActionTypeLocal.StateSet,
  17. Omit<Partial<MusicPlayer>, 'seekTime'>
  18. >;
  19. export const stateSet = (state: Partial<MusicPlayer> = {}): ActionStateSetLocal => ({
  20. type: ActionTypeLocal.StateSet,
  21. payload: state,
  22. });
  23. export type ActionSeeked = ActionLocal<ActionTypeLocal.Seeked, number>;
  24. export const seeked = (time: number): ActionSeeked => ({
  25. type: ActionTypeLocal.Seeked,
  26. payload: time,
  27. });
  28. export type ActionMasterRetaken = ActionLocal<ActionTypeLocal.MasterRetaken, void>;
  29. export const masterRetaken = (): ActionMasterRetaken => ({
  30. type: ActionTypeLocal.MasterRetaken,
  31. payload: undefined,
  32. });
  33. export type ActionPlayPaused = ActionLocal<ActionTypeLocal.PlayPaused, void>;
  34. export const playPaused = (): ActionPlayPaused => ({
  35. type: ActionTypeLocal.PlayPaused,
  36. payload: undefined,
  37. });
  38. export type LocalAction =
  39. | LoggedOut
  40. | ActionErrorOccurred
  41. | ActionNameSet
  42. | ActionStateSetLocal
  43. | ActionSeeked
  44. | ActionPlayPaused
  45. | ActionMasterRetaken;
  46. export type AnyAction = LocalAction | RemoteAction;