still trying to figure out video db stuff
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-25 11:11:31 -05:00
parent a019dc235d
commit 5cb53cbe72
5 changed files with 63 additions and 95 deletions

View file

@ -245,7 +245,7 @@ pub async fn update_video_in_db(
.to_str()
.map(std::string::ToString::to_string)
.unwrap_or_default();
query!(
let result = query!(
r#"UPDATE videos SET title = $2, file_path = $3, start_time = $4, end_time = $5, loop = $6 WHERE id = $1"#,
video.id,
video.title,
@ -255,10 +255,15 @@ pub async fn update_video_in_db(
video.looping,
)
.execute(&mut db.detach())
.await
.into_diagnostic()?;
.await.into_diagnostic();
Ok(())
match result {
Ok(_) => Ok(()),
Err(e) => {
error! {?e};
Err(e)
}
}
}
pub async fn get_video_from_db(

View file

@ -141,6 +141,7 @@ enum Message {
Present(presenter::Message),
Library(library::Message),
SongEditor(song_editor::Message),
VideoEditor(video_editor::Message),
File(PathBuf),
OpenWindow,
CloseWindow(Option<window::Id>),
@ -173,7 +174,6 @@ enum Message {
Save(Option<PathBuf>),
SaveAs,
OpenSettings,
VideoEditor(video_editor::Message),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

View file

@ -392,22 +392,29 @@ impl<'a> Library {
return Action::None;
}
match self
if self
.song_library
.update_item(song.clone(), index)
.is_err()
{
Ok(()) => {
error!("Couldn't update song in model");
return Action::None;
};
return Action::Task(
Task::future(self.db.acquire()).and_then(
move |conn| {
song_db_update(&song, conn)
Task::perform(
update_song_in_db(
song.to_owned(),
conn,
),
|_| Message::SongChanged,
)
},
),
);
}
Err(_) => todo!(),
}
}
Message::SongChanged => {
// self.song_library.update_item(song, index);
debug!("song changed");
@ -423,6 +430,15 @@ impl<'a> Library {
return Action::None;
}
if self
.image_library
.update_item(image.clone(), index)
.is_err()
{
error!("Couldn't update image in model");
return Action::None;
};
match self
.image_library
.update_item(image.clone(), index)
@ -457,22 +473,29 @@ impl<'a> Library {
return Action::None;
}
match self
if self
.video_library
.update_item(video.clone(), index)
.is_err()
{
Ok(()) => {
error!("Couldn't update video in model");
return Action::None;
};
return Action::Task(
Task::future(self.db.acquire()).and_then(
move |conn| {
video_db_update(&video, conn)
Task::perform(
update_video_in_db(
video.to_owned(),
conn,
),
|_| Message::VideoChanged,
)
},
),
);
}
Err(_) => todo!(),
}
}
Message::VideoChanged => debug!("vid shoulda changed"),
Message::UpdatePresentation(presentation) => {
let Some((kind, index)) = self.editing_item else {
@ -967,54 +990,6 @@ async fn add_videos() -> Option<Vec<Video>> {
)
}
fn video_db_update(
video: &Video,
conn: PoolConnection<Sqlite>,
) -> Task<Message> {
let video_title = video.title.clone();
warn!("Should have updated video: {:?}", video_title);
Task::perform(
update_video_in_db(video.to_owned(), conn).map(move |r| {
match r {
Ok(()) => {
warn!(
"Should have updated video: {:?}",
video_title
);
}
Err(e) => {
error!(?e);
}
}
}),
|()| Message::VideoChanged,
)
}
fn song_db_update(
song: &Song,
conn: PoolConnection<Sqlite>,
) -> Task<Message> {
let song_title = song.title.clone();
warn!("Should have updated song: {:?}", song_title);
Task::perform(
update_song_in_db(song.to_owned(), conn).map(
move |r| match r {
Ok(()) => {
warn!(
"Should have updated song: {:?}",
song_title
);
}
Err(e) => {
error!(?e);
}
},
),
|()| Message::SongChanged,
)
}
async fn add_db() -> Result<SqlitePool> {
let mut data = dirs::data_local_dir().unwrap();
data.push("lumina");

View file

@ -9,7 +9,6 @@ use cosmic::{
widget::{
button, combo_box, container, horizontal_space, icon,
progress_bar, scrollable, text, text_editor, text_input,
vertical_space,
},
Element, Task,
};

View file

@ -1,32 +1,20 @@
use std::{io, path::PathBuf, sync::Arc};
use std::{io, path::PathBuf};
use cosmic::{
dialog::file_chooser::{open::Dialog, FileFilter},
iced::{alignment::Vertical, Length},
iced_wgpu::graphics::text::cosmic_text::fontdb,
iced_widget::{column, row},
theme,
widget::{
button, combo_box, container, horizontal_space, icon,
progress_bar, scrollable, text, text_editor, text_input,
vertical_space, Space,
button, container, horizontal_space, icon, progress_bar,
text, text_input, Space,
},
Element, Task,
};
use dirs::font_dir;
use iced_video_player::{Video, VideoPlayer};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use tracing::{debug, error};
use tracing::{debug, error, warn};
use url::Url;
use crate::{
core::{service_items::ServiceTrait, slide::Slide, songs::Song},
ui::{
presenter::slide_view, slide_editor::SlideEditor, text_svg,
},
Background, BackgroundKind,
};
#[derive(Debug)]
pub struct VideoEditor {
pub video: Option<Video>,
@ -98,6 +86,7 @@ impl VideoEditor {
};
}
Message::Update(video) => {
warn!(?video);
return Action::UpdateVideo(video);
}
Message::PickVideo => {
@ -115,7 +104,7 @@ impl VideoEditor {
});
return Action::Task(task);
}
_ => (),
Message::None => (),
}
Action::None
}