feat: Added stuff
Some checks failed
build / checks-matrix (push) Has been cancelled
build / codecov (push) Has been cancelled
docs / docs (push) Has been cancelled
build / checks-build (push) Has been cancelled

This commit is contained in:
uttarayan21
2025-11-19 17:01:14 +05:30
parent 29674df85e
commit f41625e0ed
10 changed files with 271 additions and 151 deletions

View File

@@ -4,14 +4,14 @@ use shared_string::SharedString;
mod blur_hash;
use blur_hash::BlurHash;
// mod preview;
// use preview::Preview;
use iced::{Alignment, Element, Length, Task, widget::*};
use std::collections::{BTreeMap, BTreeSet};
#[derive(Debug, Clone)]
pub struct Loading {
to: Screen,
from: Screen,
}
pub struct Loading {}
#[derive(Default, Debug, Clone)]
pub struct ItemCache {
@@ -89,8 +89,10 @@ pub struct Item {
pub enum Screen {
#[default]
Home,
Item(Option<uuid::Uuid>),
Search(String),
Settings,
Profile,
User,
}
#[derive(Debug, Clone)]
struct State {
@@ -100,6 +102,7 @@ struct State {
jellyfin_client: api::JellyfinClient,
messages: Vec<String>,
history: Vec<Option<uuid::Uuid>>,
query: Option<String>,
}
impl State {
@@ -111,6 +114,7 @@ impl State {
jellyfin_client,
messages: Vec::new(),
history: Vec::new(),
query: None,
}
}
}
@@ -119,6 +123,8 @@ impl State {
pub enum Message {
OpenSettings,
Refresh,
Search,
SearchQueryChanged(String),
OpenItem(Option<uuid::Uuid>),
LoadedItem(Option<uuid::Uuid>, Vec<Item>),
Error(String),
@@ -191,6 +197,23 @@ fn update(state: &mut State, message: Message) -> Task<Message> {
state.current = None;
Task::done(Message::Refresh)
}
Message::SearchQueryChanged(query) => {
state.query = Some(query);
// Handle search query change
Task::none()
}
Message::Search => {
// Handle search action
let client = state.jellyfin_client.clone();
let query = state.query.clone().unwrap_or_default();
Task::perform(async move { client.search(query).await }, |r| match r {
Err(e) => Message::Error(format!("Search failed: {}", e)),
Ok(items) => {
let items = items.into_iter().map(Item::from).collect();
Message::LoadedItem(None, items)
}
})
}
}
}
@@ -231,20 +254,15 @@ fn header(state: &State) -> Element<'_, Message> {
.align_y(Alignment::Center)
.style(container::rounded_box)
.into(),
container(
row([
button("Settings").on_press(Message::OpenSettings).into(),
button("Refresh").on_press(Message::Refresh).into(),
])
.spacing(10),
)
.padding(10)
.width(Length::Fill)
.height(Length::Fill)
.align_x(Alignment::End)
.align_y(Alignment::Center)
.style(container::rounded_box)
.into(),
search(state),
container(row([button("Refresh").on_press(Message::Refresh).into()]).spacing(10))
.padding(10)
.width(Length::Fill)
.height(Length::Fill)
.align_x(Alignment::End)
.align_y(Alignment::Center)
.style(container::rounded_box)
.into(),
])
.align_y(Alignment::Center)
.width(Length::Fill)
@@ -252,6 +270,22 @@ fn header(state: &State) -> Element<'_, Message> {
.into()
}
fn search(state: &State) -> Element<'_, Message> {
container(
TextInput::new("Search...", state.query.as_deref().unwrap_or_default())
.padding(10)
.size(16)
.width(Length::Fill)
.on_input(Message::SearchQueryChanged)
.on_submit(Message::Search),
)
.padding(10)
.width(Length::Fill)
.height(Length::Shrink)
.style(container::rounded_box)
.into()
}
fn footer(state: &State) -> Element<'_, Message> {
container(
column(