Skip to main content

mecomp_tui/state/
action.rs

1//! This module contains the actions that the user can perform through the UI.
2//! these actions are sent from the UI to the state stores, which then update the state accordingly.
3#![allow(clippy::module_name_repetitions)]
4
5use std::time::Duration;
6
7use mecomp_core::{state::SeekType, udp::StateChange};
8use mecomp_prost::{DynamicPlaylistChangeSet, RecordId, Ulid};
9use mecomp_storage::db::schemas::dynamic::query::Query;
10
11use crate::ui::{components::content_view::ActiveView, widgets::popups::PopupType};
12
13use super::component::ActiveComponent;
14
15#[derive(Debug, Clone, PartialEq)]
16pub enum Action {
17    /// General actions
18    General(GeneralAction),
19    /// Actions that effect the audio state store.
20    Audio(AudioAction),
21    /// Actions that effect the search state store.
22    Search(String),
23    /// Actions that effect the library state store.
24    Library(LibraryAction),
25    /// Actions that effect the current view.
26    ActiveView(ViewAction),
27    /// Actions regarding popups
28    Popup(PopupAction),
29    /// Actions that change the active component
30    ActiveComponent(ComponentAction),
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub enum GeneralAction {
35    /// Exit the application.
36    Exit,
37}
38
39#[derive(Debug, Clone, PartialEq)]
40pub enum AudioAction {
41    /// Playback Commands
42    Playback(PlaybackAction),
43    /// Queue Commands
44    Queue(QueueAction),
45    /// State Changes
46    StateChange(StateChange),
47}
48
49#[derive(Debug, Clone, PartialEq)]
50pub enum PlaybackAction {
51    /// Toggle play/pause
52    Toggle,
53    /// Skip to the next song.
54    Next,
55    /// Skip to the previous song.
56    Previous,
57    /// Seek to a specific position in the current song.
58    Seek(SeekType, Duration),
59    /// Change the volume.
60    Volume(VolumeAction),
61    /// Toggle the mute state.
62    ToggleMute,
63}
64
65#[derive(Debug, Clone, PartialEq)]
66pub enum VolumeAction {
67    /// Increase the volume by a given amount (0 is mute, 100 is max)
68    Increase(f32),
69    /// Decrease the volume by a given amount (0 is mute, 100 is max)
70    Decrease(f32),
71}
72
73#[derive(Debug, Clone, PartialEq, Eq)]
74pub enum QueueAction {
75    /// Add a list of things to the queue (by id)
76    Add(Vec<RecordId>),
77    /// Remove something from the queue (by index)
78    Remove(u64),
79    /// Set the current queue position
80    SetPosition(u64),
81    /// Shuffle the queue
82    Shuffle,
83    /// Clear the queue
84    Clear,
85    /// Set the repeat mode
86    SetRepeatMode(mecomp_prost::RepeatMode),
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
90pub enum LibraryAction {
91    /// Rescan the library
92    Rescan,
93    /// Tell the Library Store to get the latest library data
94    Update,
95    /// Analyze the library
96    Analyze,
97    /// Recluster the collection
98    Recluster,
99    /// Create a new playlist with the given name
100    CreatePlaylist(String),
101    /// Delete a playlist by id
102    RemovePlaylist(Ulid),
103    /// Rename a playlist by id
104    RenamePlaylist(Ulid, String),
105    /// Remove a song from a playlist (`PlaylistId`, Vec<`SongId`>)
106    RemoveSongsFromPlaylist(Ulid, Vec<RecordId>),
107    /// Add a list of things to a playlist (`PlaylistId`, Vec<`SongId`>)
108    AddThingsToPlaylist(RecordId, Vec<RecordId>),
109    /// Create a new playlist with the given name (if it doesn't exist) and add the songs to it
110    /// (`PlaylistName`, Vec<`SongId`>)
111    CreatePlaylistAndAddThings(String, Vec<RecordId>),
112    /// Create a new dynamic playlist with the given name and query
113    CreateDynamicPlaylist(String, Query),
114    /// Delete a dynamic playlist by id
115    RemoveDynamicPlaylist(Ulid),
116    /// Update the query of a dynamic playlist
117    UpdateDynamicPlaylist(Ulid, DynamicPlaylistChangeSet),
118}
119
120#[derive(Debug, Clone, PartialEq, Eq)]
121pub enum ViewAction {
122    /// Set the active view
123    Set(ActiveView),
124    /// Return to a previous view
125    /// Used for undo/redo based navigation
126    Back,
127    /// Go to the next view (if possible)
128    /// Used for undo/redo based navigation
129    ///
130    /// Essentially, if a user goes back, they can use this action to go back forward.
131    Next,
132}
133
134#[derive(Debug, Clone, PartialEq, Eq)]
135pub enum PopupAction {
136    /// Open a popup
137    Open(PopupType),
138    /// Close the current popup
139    Close,
140}
141
142#[derive(Debug, Clone, Copy, PartialEq, Eq)]
143pub enum ComponentAction {
144    /// Move to the next component
145    Next,
146    /// Move to the previous component
147    Previous,
148    /// Set the active component
149    Set(ActiveComponent),
150}