fix: media list now showing in sidebar
This commit is contained in:
@@ -59,6 +59,19 @@ pub fn list_media_by_project(conn: &Connection, project_id: &str) -> rusqlite::R
|
||||
rows.collect()
|
||||
}
|
||||
|
||||
pub fn list_media_by_project_limited(
|
||||
conn: &Connection,
|
||||
project_id: &str,
|
||||
limit: i64,
|
||||
offset: i64,
|
||||
) -> rusqlite::Result<Vec<Media>> {
|
||||
let mut stmt = conn.prepare(&format!(
|
||||
"SELECT {MEDIA_COLUMNS} FROM media WHERE project_id = ?1 ORDER BY created_at DESC LIMIT ?2 OFFSET ?3"
|
||||
))?;
|
||||
let rows = stmt.query_map(params![project_id, limit, offset], media_from_row)?;
|
||||
rows.collect()
|
||||
}
|
||||
|
||||
pub fn count_media_by_project(conn: &Connection, project_id: &str) -> rusqlite::Result<i64> {
|
||||
conn.query_row(
|
||||
"SELECT COUNT(*) FROM media WHERE project_id = ?1",
|
||||
|
||||
@@ -7,7 +7,7 @@ use bds_core::db::Database;
|
||||
use bds_core::engine::task::{TaskId, TaskManager, TaskStatus};
|
||||
use bds_core::engine;
|
||||
use bds_core::i18n::{detect_os_locale, UiLocale};
|
||||
use bds_core::model::{Post, Project};
|
||||
use bds_core::model::{Media, Post, Project};
|
||||
|
||||
use crate::i18n::{t, tw};
|
||||
use crate::platform::menu::{self, MenuAction, MenuRegistry};
|
||||
@@ -100,6 +100,7 @@ pub struct BdsApp {
|
||||
|
||||
// Sidebar data
|
||||
sidebar_posts: Vec<Post>,
|
||||
sidebar_media: Vec<Media>,
|
||||
|
||||
// Navigation
|
||||
sidebar_view: SidebarView,
|
||||
@@ -225,6 +226,7 @@ impl BdsApp {
|
||||
post_count: 0,
|
||||
media_count: 0,
|
||||
sidebar_posts: Vec::new(),
|
||||
sidebar_media: Vec::new(),
|
||||
sidebar_view: SidebarView::Posts,
|
||||
sidebar_visible: true,
|
||||
tabs: Vec::new(),
|
||||
@@ -583,6 +585,7 @@ impl BdsApp {
|
||||
&self.task_snapshots,
|
||||
&self.output_entries,
|
||||
&self.sidebar_posts,
|
||||
&self.sidebar_media,
|
||||
active_name,
|
||||
&self.projects,
|
||||
self.active_project.as_ref().map(|p| p.id.as_str()),
|
||||
@@ -854,6 +857,13 @@ impl BdsApp {
|
||||
0,
|
||||
)
|
||||
.unwrap_or_default();
|
||||
self.sidebar_media = bds_core::db::queries::media::list_media_by_project_limited(
|
||||
db.conn(),
|
||||
&project.id,
|
||||
500,
|
||||
0,
|
||||
)
|
||||
.unwrap_or_default();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use iced::widget::text::Shaping;
|
||||
use iced::{Background, Border, Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
use bds_core::model::Post;
|
||||
use bds_core::model::{Media, Post};
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::i18n::t;
|
||||
@@ -56,6 +56,7 @@ fn placeholder_key(view: SidebarView) -> &'static str {
|
||||
pub fn view(
|
||||
sidebar_view: SidebarView,
|
||||
posts: &[Post],
|
||||
media: &[Media],
|
||||
locale: UiLocale,
|
||||
) -> Element<'static, Message> {
|
||||
let header_text = t(locale, sidebar_view.i18n_key());
|
||||
@@ -102,6 +103,38 @@ pub fn view(
|
||||
.into()
|
||||
}
|
||||
}
|
||||
SidebarView::Media => {
|
||||
if media.is_empty() {
|
||||
text(t(locale, placeholder_key(sidebar_view)))
|
||||
.size(12)
|
||||
.shaping(Shaping::Advanced)
|
||||
.color(muted)
|
||||
.into()
|
||||
} else {
|
||||
let items: Vec<Element<'static, Message>> = media
|
||||
.iter()
|
||||
.map(|m| {
|
||||
let display_name = m.title.as_deref()
|
||||
.unwrap_or(&m.original_name);
|
||||
let label = format!("\u{1F5BC} {display_name}");
|
||||
button(text(label).size(12).shaping(Shaping::Advanced))
|
||||
.on_press(Message::OpenTab(Tab {
|
||||
id: m.id.clone(),
|
||||
tab_type: TabType::Media,
|
||||
title: display_name.to_string(),
|
||||
is_transient: true,
|
||||
}))
|
||||
.padding([3, 6])
|
||||
.width(Length::Fill)
|
||||
.style(item_style)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
iced::widget::Column::with_children(items)
|
||||
.spacing(1)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
text(t(locale, placeholder_key(sidebar_view)))
|
||||
.size(12)
|
||||
|
||||
@@ -3,7 +3,7 @@ use iced::widget::text::Shaping;
|
||||
use iced::{Alignment, Background, Color, Element, Length, Padding, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
use bds_core::model::{Post, Project};
|
||||
use bds_core::model::{Media, Post, Project};
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::state::navigation::{OutputEntry, PanelTab, SidebarView, TaskSnapshot};
|
||||
@@ -55,6 +55,7 @@ pub fn view(
|
||||
output_entries: &[OutputEntry],
|
||||
// Sidebar data
|
||||
sidebar_posts: &[Post],
|
||||
sidebar_media: &[Media],
|
||||
// Status bar
|
||||
active_project_name: Option<&str>,
|
||||
projects: &[Project],
|
||||
@@ -91,7 +92,7 @@ pub fn view(
|
||||
let mut main_row = row![activity];
|
||||
|
||||
if sidebar_visible {
|
||||
main_row = main_row.push(sidebar::view(sidebar_view, sidebar_posts, locale));
|
||||
main_row = main_row.push(sidebar::view(sidebar_view, sidebar_posts, sidebar_media, locale));
|
||||
main_row = main_row.push(separator_v());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user