actions.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Action } from '../../../actions';
  2. import { ActionKeyPressed } from '../../../hooks/vim';
  3. import { Song } from '../../../types';
  4. export enum CmusUIActionType {
  5. ArtistsSet = '@@ui/cmus/ARTISTS_SET',
  6. ArtistAlbumsLoaded = '@@ui/cmus/ARTIST_ALBUMS_LOADED',
  7. ArtistSongsLoaded = '@@ui/cmus/ARTIST_SONGS_LOADED',
  8. CommandSet = '@@ui/cmus/COMMAND_SET',
  9. ClientActivated = '@@ui/cmus/CLIENT_ACTIVATED',
  10. }
  11. export type ArtistsSet = Action<CmusUIActionType.ArtistsSet, string[]>;
  12. export const artistsSet = (artists: string[]): ArtistsSet => ({
  13. type: CmusUIActionType.ArtistsSet,
  14. payload: artists,
  15. });
  16. export type ArtistAlbumsLoaded = Action<
  17. CmusUIActionType.ArtistAlbumsLoaded,
  18. {
  19. artist: string;
  20. albums: string[];
  21. }
  22. >;
  23. export const artistAlbumsLoaded = (artist: string, albums: string[]): ArtistAlbumsLoaded => ({
  24. type: CmusUIActionType.ArtistAlbumsLoaded,
  25. payload: { artist, albums },
  26. });
  27. export type ArtistSongsLoaded = Action<
  28. CmusUIActionType.ArtistSongsLoaded,
  29. {
  30. artist: string;
  31. songs: Song[];
  32. }
  33. >;
  34. export const artistSongsLoaded = (artist: string, songs: Song[]): ArtistSongsLoaded => ({
  35. type: CmusUIActionType.ArtistSongsLoaded,
  36. payload: { artist, songs },
  37. });
  38. export type CommandSet = Action<CmusUIActionType.CommandSet, string | null>;
  39. export const commandSet = (command: string | null): CommandSet => ({
  40. type: CmusUIActionType.CommandSet,
  41. payload: command,
  42. });
  43. export type ClientActivated = Action<CmusUIActionType.ClientActivated, string | null>;
  44. export const clientActivated = (name: string | null): ClientActivated => ({
  45. type: CmusUIActionType.ClientActivated,
  46. payload: name,
  47. });
  48. export type CmusUIAction =
  49. | ArtistsSet
  50. | ArtistAlbumsLoaded
  51. | ArtistSongsLoaded
  52. | CommandSet
  53. | ClientActivated
  54. | ActionKeyPressed;