actions.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. QueueInfoLoaded = '@@ui/cmus/QUEUE_INFO_LOADED',
  11. Searched = '@@ui/cmus/SEARCHED',
  12. }
  13. export type ArtistsSet = Action<CmusUIActionType.ArtistsSet, string[]>;
  14. export const artistsSet = (artists: string[]): ArtistsSet => ({
  15. type: CmusUIActionType.ArtistsSet,
  16. payload: artists,
  17. });
  18. export type ArtistAlbumsLoaded = Action<
  19. CmusUIActionType.ArtistAlbumsLoaded,
  20. {
  21. artist: string;
  22. albums: string[];
  23. }
  24. >;
  25. export const artistAlbumsLoaded = (artist: string, albums: string[]): ArtistAlbumsLoaded => ({
  26. type: CmusUIActionType.ArtistAlbumsLoaded,
  27. payload: { artist, albums },
  28. });
  29. export type ArtistSongsLoaded = Action<
  30. CmusUIActionType.ArtistSongsLoaded,
  31. {
  32. artist: string;
  33. songs: Song[];
  34. }
  35. >;
  36. export const artistSongsLoaded = (artist: string, songs: Song[]): ArtistSongsLoaded => ({
  37. type: CmusUIActionType.ArtistSongsLoaded,
  38. payload: { artist, songs },
  39. });
  40. export type CommandSet = Action<CmusUIActionType.CommandSet, string | null>;
  41. export const commandSet = (command: string | null): CommandSet => ({
  42. type: CmusUIActionType.CommandSet,
  43. payload: command,
  44. });
  45. export type ClientActivated = Action<CmusUIActionType.ClientActivated, string | null>;
  46. export const clientActivated = (name: string | null): ClientActivated => ({
  47. type: CmusUIActionType.ClientActivated,
  48. payload: name,
  49. });
  50. export type QueueInfoLoaded = Action<CmusUIActionType.QueueInfoLoaded, Song[]>;
  51. export const queueInfoLoaded = (songs: Song[]): QueueInfoLoaded => ({
  52. type: CmusUIActionType.QueueInfoLoaded,
  53. payload: songs,
  54. });
  55. export type Searched = Action<CmusUIActionType.Searched, string | null>;
  56. export const searched = (term: string | null): Searched => ({
  57. type: CmusUIActionType.Searched,
  58. payload: term,
  59. });
  60. export type CmusUIAction =
  61. | ArtistsSet
  62. | ArtistAlbumsLoaded
  63. | ArtistSongsLoaded
  64. | CommandSet
  65. | ClientActivated
  66. | QueueInfoLoaded
  67. | Searched
  68. | ActionKeyPressed;