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    RecordId,
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    Add(Vec<RecordId>),
82    /// Remove something from the queue (by index)
83    Remove(usize),
84    /// Set the current queue position
85    SetPosition(usize),
86    /// Shuffle the queue
87    Shuffle,
88    /// Clear the queue
89    Clear,
90    /// Set the repeat mode
91    SetRepeatMode(RepeatMode),
92}
93
94#[derive(Debug, Clone, PartialEq, Eq)]
95pub enum LibraryAction {
96    /// Rescan the library
97    Rescan,
98    /// Tell the Library Store to get the latest library data
99    Update,
100    /// Analyze the library
101    Analyze,
102    /// Recluster the collection
103    Recluster,
104    /// Create a new playlist with the given name
105    CreatePlaylist(String),
106    /// Delete a playlist by id
107    RemovePlaylist(RecordId),
108    /// Rename a playlist by id
109    RenamePlaylist(RecordId, String),
110    /// Remove a song from a playlist (`PlaylistId`, Vec<`SongId`>)
111    RemoveSongsFromPlaylist(RecordId, Vec<RecordId>),
112    /// Add a list of things to a playlist (`PlaylistId`, Vec<`SongId`>)
113    AddThingsToPlaylist(RecordId, Vec<RecordId>),
114    /// Create a new playlist with the given name (if it doesn't exist) and add the songs to it
115    /// (`PlaylistName`, Vec<`SongId`>)
116    CreatePlaylistAndAddThings(String, Vec<RecordId>),
117    /// Create a new dynamic playlist with the given name and query
118    CreateDynamicPlaylist(String, Query),
119    /// Delete a dynamic playlist by id
120    RemoveDynamicPlaylist(RecordId),
121    /// Update the query of a dynamic playlist
122    UpdateDynamicPlaylist(RecordId, DynamicPlaylistChangeSet),
123}
124
125#[derive(Debug, Clone, PartialEq, Eq)]
126pub enum ViewAction {
127    /// Set the active view
128    Set(ActiveView),
129    /// Return to a previous view
130    /// Used for undo/redo based navigation
131    Back,
132    /// Go to the next view (if possible)
133    /// Used for undo/redo based navigation
134    ///
135    /// Essentially, if a user goes back, they can use this action to go back forward.
136    Next,
137}
138
139#[derive(Debug, Clone, PartialEq, Eq)]
140pub enum PopupAction {
141    /// Open a popup
142    Open(PopupType),
143    /// Close the current popup
144    Close,
145}
146
147#[derive(Debug, Clone, Copy, PartialEq, Eq)]
148pub enum ComponentAction {
149    /// Move to the next component
150    Next,
151    /// Move to the previous component
152    Previous,
153    /// Set the active component
154    Set(ActiveComponent),
155}