|
|
|
@ -1,24 +1,19 @@
|
|
|
|
|
use leptos::*;
|
|
|
|
|
use wasm_bindgen_futures::JsFuture;
|
|
|
|
|
use web_sys::{File, Window, Request};
|
|
|
|
|
use web_sys::{File, Request, Window};
|
|
|
|
|
|
|
|
|
|
use crate::error::{ReadFileError, FetchFileError};
|
|
|
|
|
use crate::error::{FetchFileError, ReadFileError};
|
|
|
|
|
|
|
|
|
|
pub fn window() -> Window {
|
|
|
|
|
web_sys::window().unwrap()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn read_file(
|
|
|
|
|
file: ReadSignal<Option<File>>,
|
|
|
|
|
) -> Result<String, ReadFileError> {
|
|
|
|
|
pub async fn read_file(file: ReadSignal<Option<File>>) -> Result<String, ReadFileError> {
|
|
|
|
|
let file = match file() {
|
|
|
|
|
Some(file) => file,
|
|
|
|
|
None => return Err(ReadFileError::NoFile),
|
|
|
|
|
};
|
|
|
|
|
match JsFuture::from(file.text())
|
|
|
|
|
.await?
|
|
|
|
|
.as_string()
|
|
|
|
|
{
|
|
|
|
|
match JsFuture::from(file.text()).await?.as_string() {
|
|
|
|
|
Some(contents) => Ok(contents),
|
|
|
|
|
None => Err(ReadFileError::ParseToString),
|
|
|
|
|
}
|
|
|
|
@ -31,4 +26,4 @@ pub async fn fetch_file(url: &str) -> Result<String, FetchFileError> {
|
|
|
|
|
Some(string) => Ok(string),
|
|
|
|
|
None => Err(FetchFileError::ReadToString),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|