Skip to content

Commit

Permalink
chore: Update Dioxus to 0.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gaku-sei committed Aug 30, 2024
1 parent b040585 commit fb81e7d
Show file tree
Hide file tree
Showing 9 changed files with 1,337 additions and 687 deletions.
1,629 changes: 1,139 additions & 490 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ chrono = "0.4.38"
criterion = { version = "0.5.1", features = ["html_reports"] }
dark-light = "1.1.1"
dialoguer = "0.11.0"
dioxus = "0.4.0"
dioxus-desktop = "0.4.0"
dioxus = { version = "^0.5.6", features = ["desktop"] }
dunce = "1.0.5"
eco-cbz = { path = "./eco-cbz" }
eco-convert = { path = "./eco-convert" }
Expand Down
1 change: 0 additions & 1 deletion eco-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ base64.workspace = true
camino.workspace = true
dark-light.workspace = true
dioxus.workspace = true
dioxus-desktop.workspace = true
dunce.workspace = true
eco-cbz = { workspace = true, features = ["metadata"] }
epub.workspace = true
Expand Down
38 changes: 38 additions & 0 deletions eco-view/src/components/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use dioxus::prelude::*;

#[component]
pub fn Commands(
max_page: usize,
nb_loaded_pages: ReadOnlySignal<usize>,
current_page: Signal<usize>,
on_prev_page_request: EventHandler,
on_next_page_request: EventHandler,
) -> Element {
rsx! {
div { class: "flex flex-row items-center justify-center gap-1 h-8 mb-2",
button {
class: "btn btn-outline-primary btn-sm",
onclick: move |_evt| on_prev_page_request.call(()),
"Prev"
}
span { class: "flex flex-row items-center justify-center bg-backgroundSecondary h-8 px-2 rounded-sm",
"{current_page} / {nb_loaded_pages}"
}
button {
class: "btn btn-outline-primary btn-sm",
onclick: move |_evt| on_next_page_request.call(()),
"Next"
}
}
div { class: "w-full flex flex-row items-center justify-center gap-1 h-8 mb-2",
input {
class: "w-11/12",
r#type: "range",
min: "1",
value: "{current_page}",
max: "{max_page}",
oninput: move |evt| { current_page.set(evt.value().parse().unwrap_or(1)) }
}
}
}
}
33 changes: 14 additions & 19 deletions eco-view/src/components/doc_page.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
use dioxus::prelude::*;

use crate::doc::{Doc, SharedDoc};
use crate::FileType;

#[allow(clippy::module_name_repetitions)]
#[derive(Props)]
pub struct DocPageProps<'a> {
doc: SharedDoc,
content: &'a str,
}

pub fn DocPage<'a, 'b: 'a>(cx: Scope<'a, DocPageProps<'b>>) -> Element<'a> {
let content = cx.props.content;
#[component]
pub fn DocPage(content: ReadOnlySignal<String>) -> Element {
let file_type = use_context::<FileType>();

match *cx.props.doc.lock().unwrap() {
Doc::Cbz { .. } => cx.render(rsx!(img {
match file_type {
FileType::Cbz => rsx!(img {
class: "h-px grow",
src: "data:image/png;base64,{content}"
})),
Doc::Epub { .. } => cx.render(rsx!(div {
class: "h-px grow spect-[12/16]",
iframe {
class: "h-full w-full",
src: "data:text/html;charset=utf-8,{content}"
}),
FileType::Epub => rsx!(
div { class: "h-px grow spect-[12/16]",
iframe {
class: "h-full w-full",
src: "data:text/html;charset=utf-8,{content}"
}
}
})),
),
}
}
1 change: 1 addition & 0 deletions eco-view/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod commands;
pub mod doc_page;
6 changes: 3 additions & 3 deletions eco-view/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::errors::{Error, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileType {
Cbz,
EPub,
Epub,
}

impl FromStr for FileType {
Expand All @@ -25,7 +25,7 @@ impl FromStr for FileType {
fn from_str(s: &str) -> Result<Self> {
match s.to_lowercase().as_str() {
"cbz" => Ok(FileType::Cbz),
"epub" => Ok(FileType::EPub),
"epub" => Ok(FileType::Epub),
_ => Err(Error::InvalidFileType(s.to_string())),
}
}
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Doc {
pages: Vec::with_capacity(max_page),
})
}
FileType::EPub => {
FileType::Epub => {
let doc = epub::doc::EpubDoc::new(path)?;
let max_page = doc.get_num_pages();
Ok(Doc::Epub {
Expand Down
Loading

0 comments on commit fb81e7d

Please sign in to comment.