diff --git a/.envrc b/.envrc index 0707511..4ff4e1f 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,4 @@ +DATABASE_URL="sqlite:///home/chris/.local/share/lumina/library-db.sqlite3" use flake . --impure # eval $(guix shell -D --search-paths) diff --git a/.sqlx/query-7ace613c138f874198ea8e5f72697d4c604fe7b755fdcb6773692c813b5e1d4b.json b/.sqlx/query-7ace613c138f874198ea8e5f72697d4c604fe7b755fdcb6773692c813b5e1d4b.json deleted file mode 100644 index 5757ece..0000000 --- a/.sqlx/query-7ace613c138f874198ea8e5f72697d4c604fe7b755fdcb6773692c813b5e1d4b.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT id as \"id: i32\", title, file_path as \"path\", html from presentations", - "describe": { - "columns": [ - { - "name": "id: i32", - "ordinal": 0, - "type_info": "Integer" - }, - { - "name": "title", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "path", - "ordinal": 2, - "type_info": "Text" - }, - { - "name": "html", - "ordinal": 3, - "type_info": "Bool" - } - ], - "parameters": { - "Right": 0 - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "7ace613c138f874198ea8e5f72697d4c604fe7b755fdcb6773692c813b5e1d4b" -} diff --git a/.sqlx/query-8cc171f2be70148e4178fa23d34887be69527e6fda128b11a6279cd8cf410918.json b/.sqlx/query-8cc171f2be70148e4178fa23d34887be69527e6fda128b11a6279cd8cf410918.json deleted file mode 100644 index a8dbdd4..0000000 --- a/.sqlx/query-8cc171f2be70148e4178fa23d34887be69527e6fda128b11a6279cd8cf410918.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT title as \"title!\", file_path as \"path!\", id as \"id: i32\" from images", - "describe": { - "columns": [ - { - "name": "title!", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "path!", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "id: i32", - "ordinal": 2, - "type_info": "Integer" - } - ], - "parameters": { - "Right": 0 - }, - "nullable": [ - false, - false, - false - ] - }, - "hash": "8cc171f2be70148e4178fa23d34887be69527e6fda128b11a6279cd8cf410918" -} diff --git a/.sqlx/query-aa01b675a8e40d152144b3b6a11ec9c68244defd5ea85764979535e1b2267496.json b/.sqlx/query-aa01b675a8e40d152144b3b6a11ec9c68244defd5ea85764979535e1b2267496.json deleted file mode 100644 index 0831b5b..0000000 --- a/.sqlx/query-aa01b675a8e40d152144b3b6a11ec9c68244defd5ea85764979535e1b2267496.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT title as \"title!\", file_path as \"path!\", id as \"id: i32\" from images where id = ?", - "describe": { - "columns": [ - { - "name": "title!", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "path!", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "id: i32", - "ordinal": 2, - "type_info": "Integer" - } - ], - "parameters": { - "Right": 1 - }, - "nullable": [ - false, - false, - false - ] - }, - "hash": "aa01b675a8e40d152144b3b6a11ec9c68244defd5ea85764979535e1b2267496" -} diff --git a/.sqlx/query-d4b324ece51b3a314367f570bb7f28a36ef703387d3f9eace9f51f102b1ed6da.json b/.sqlx/query-d4b324ece51b3a314367f570bb7f28a36ef703387d3f9eace9f51f102b1ed6da.json deleted file mode 100644 index 7c6ead1..0000000 --- a/.sqlx/query-d4b324ece51b3a314367f570bb7f28a36ef703387d3f9eace9f51f102b1ed6da.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT title as \"title!\", file_path as \"path!\", start_time as \"start_time!: f32\", end_time as \"end_time!: f32\", loop as \"looping!\", id as \"id: i32\" from videos where id = ?", - "describe": { - "columns": [ - { - "name": "title!", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "path!", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "start_time!: f32", - "ordinal": 2, - "type_info": "Null" - }, - { - "name": "end_time!: f32", - "ordinal": 3, - "type_info": "Null" - }, - { - "name": "looping!", - "ordinal": 4, - "type_info": "Bool" - }, - { - "name": "id: i32", - "ordinal": 5, - "type_info": "Integer" - } - ], - "parameters": { - "Right": 1 - }, - "nullable": [ - false, - false, - true, - true, - false, - false - ] - }, - "hash": "d4b324ece51b3a314367f570bb7f28a36ef703387d3f9eace9f51f102b1ed6da" -} diff --git a/.sqlx/query-f6c1c41a68b04f939301d6bb897cf79915ef389eedb009daef3be737709266f8.json b/.sqlx/query-f6c1c41a68b04f939301d6bb897cf79915ef389eedb009daef3be737709266f8.json deleted file mode 100644 index 7eefc00..0000000 --- a/.sqlx/query-f6c1c41a68b04f939301d6bb897cf79915ef389eedb009daef3be737709266f8.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT title as \"title!\", file_path as \"path!\", start_time as \"start_time!: f32\", end_time as \"end_time!: f32\", loop as \"looping!\", id as \"id: i32\" from videos", - "describe": { - "columns": [ - { - "name": "title!", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "path!", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "start_time!: f32", - "ordinal": 2, - "type_info": "Float" - }, - { - "name": "end_time!: f32", - "ordinal": 3, - "type_info": "Float" - }, - { - "name": "looping!", - "ordinal": 4, - "type_info": "Bool" - }, - { - "name": "id: i32", - "ordinal": 5, - "type_info": "Integer" - } - ], - "parameters": { - "Right": 0 - }, - "nullable": [ - false, - false, - true, - true, - false, - false - ] - }, - "hash": "f6c1c41a68b04f939301d6bb897cf79915ef389eedb009daef3be737709266f8" -} diff --git a/flake.nix b/flake.nix index e59b481..fe3523d 100644 --- a/flake.nix +++ b/flake.nix @@ -83,6 +83,7 @@ pkgs.libxkbcommon ] }"; + DATABASE_URL = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3"; }; defaultPackage = naersk'.buildPackage { src = ./.; diff --git a/src/core/songs.rs b/src/core/songs.rs index 9e370be..fdba55f 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -374,6 +374,24 @@ pub async fn get_song_from_db( } impl Model { + pub async fn update_song( + &mut self, + item: Song, + index: i32, + db: &mut SqliteConnection, + ) -> Result<()> { + self.update_item(item, index)?; + + query!( + r#"UPDATE songs SET title = {} WHERE id = {}"#, + item.title, + item.id + ) + .fetch_one(db) + .await?; + + Ok(()) + } pub async fn new_song_model(db: &mut SqliteConnection) -> Self { let mut model = Self { items: vec![], diff --git a/src/main.rs b/src/main.rs index cbf73a8..8cbf15d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -418,17 +418,114 @@ impl cosmic::Application for App { Message::SongEditor(message) => { debug!(?message); match message { - song_editor::Message::UpdateSong(ref song) => { - debug!(?song); - if let Some(library) = self.library.as_mut() { - match library.update_song(song.clone()) { - Ok(_) => { - debug!("upated song") + song_editor::Message::ChangeFont(ref font) => { + if let Some(mut song) = + self.song_editor.song.clone() + { + song.font = Some(font.to_string()); + self.song_editor.song = + Some(song.clone()); + if let Some(library) = &mut self.library { + match library.update_song(song) { + Ok(_) => (), + Err(e) => error!(?e), } - Err(e) => error!(?e), - } + }; }; } + song_editor::Message::ChangeFontSize( + font_size, + ) => { + if let Some(mut song) = + self.song_editor.song.clone() + { + song.font_size = Some(font_size as i32); + self.song_editor.song = + Some(song.clone()); + if let Some(library) = &mut self.library { + match library.update_song(song) { + Ok(_) => (), + Err(e) => error!(?e), + } + }; + }; + } + song_editor::Message::ChangeTitle(ref title) => { + if let Some(mut song) = + self.song_editor.song.clone() + { + song.title = title.to_string(); + self.song_editor.song = + Some(song.clone()); + if let Some(library) = &mut self.library { + match library.update_song(song) { + Ok(_) => (), + Err(e) => error!(?e), + } + }; + }; + } + song_editor::Message::ChangeVerseOrder( + ref vo, + ) => { + if let Some(mut song) = + self.song_editor.song.clone() + { + let verse_order = vo + .split(" ") + .into_iter() + .map(|s| s.to_owned()) + .collect(); + song.verse_order = Some(verse_order); + self.song_editor.song = + Some(song.clone()); + if let Some(library) = &mut self.library { + match library.update_song(song) { + Ok(_) => (), + Err(e) => error!(?e), + } + }; + }; + } + song_editor::Message::ChangeLyrics( + ref action, + ) => { + self.song_editor + .lyrics + .perform(action.clone()); + let lyrics = self.song_editor.lyrics.text(); + if let Some(mut song) = + self.song_editor.song.clone() + { + song.lyrics = Some(lyrics.to_string()); + self.song_editor.song = + Some(song.clone()); + if let Some(library) = &mut self.library { + match library.update_song(song) { + Ok(_) => (), + Err(e) => error!(?e), + } + }; + }; + } + song_editor::Message::ChangeAuthor( + ref author, + ) => { + if let Some(mut song) = + self.song_editor.song.clone() + { + song.author = Some(author.to_string()); + self.song_editor.song = + Some(song.clone()); + if let Some(library) = &mut self.library { + match library.update_song(song) { + Ok(_) => (), + Err(e) => error!(?e), + } + }; + }; + } + song_editor::Message::Edit(_) => todo!(), _ => (), }; self.song_editor.update(message).map(|m| { diff --git a/src/ui/library.rs b/src/ui/library.rs index b70acbd..da376c9 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -79,6 +79,7 @@ impl Library { Message::RemoveItem => Task::none(), Message::OpenItem(item) => { debug!(?item); + self.editing_item = item; Task::none() } Message::HoverLibrary(library_kind) => { diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index b87a8c1..4ce64ab 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -26,7 +26,7 @@ use super::presenter::slide_view; #[derive(Debug)] pub struct SongEditor { - song: Option, + pub song: Option, title: String, fonts: combo_box::State, font_sizes: Vec, @@ -35,7 +35,7 @@ pub struct SongEditor { audio: PathBuf, font_size: usize, verse_order: String, - lyrics: text_editor::Content, + pub lyrics: text_editor::Content, editing: bool, background: Option, video: Option