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