Skip to content

Commit

Permalink
run clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
sectore committed Sep 5, 2024
1 parent e89b3c0 commit 9b586e3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
19 changes: 6 additions & 13 deletions src/app_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,12 @@ pub enum Msg {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Default)]
pub struct AppState {
pub file: Option<FileResult>,
pub exified: bool,
}

impl Default for AppState {
fn default() -> Self {
Self {
file: None,
exified: false,
}
}
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Reducer
Expand All @@ -52,7 +45,9 @@ impl Reducible for AppState {
exified: self.exified,
},
Msg::RemoveExif => {
let state = if let Some(Ok(details)) = &self.file {


if let Some(Ok(details)) = &self.file {
let result = remove_exif(details.clone());

AppState {
Expand All @@ -64,9 +59,7 @@ impl Reducible for AppState {
file: None,
exified: false,
}
};

state
}
}
Msg::Saved(_) => AppState {
file: None,
Expand All @@ -90,7 +83,7 @@ pub struct AppProviderProps {

#[function_component]
pub fn AppProvider(props: &AppProviderProps) -> Html {
let msg = use_reducer(|| AppState::default());
let msg = use_reducer(AppState::default);

html! {
<ContextProvider<AppContext> context={msg}>
Expand Down
30 changes: 15 additions & 15 deletions src/components/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ pub fn Add() -> Html {
Callback::from(move |files: FileList| {
match files.item(0) {
None => {
return ctx.dispatch(Msg::Update(Err(FileError::DragDropFailed(
ctx.dispatch(Msg::Update(Err(FileError::DragDropFailed(
"No file in FileList".to_string(),
))));
))))
}
Some(file) => {
let file = File::from(web_sys::File::from(file));
let file = File::from(file);
let file_name = file.name();
let file_type = file.raw_mime_type();
let ctx = ctx.clone();
let task = gloo::file::callbacks::read_as_bytes(&file, move |res| {
let msg = match res {
Ok(data) => {
let file_details = get_file_details(data, file_name, file_type);
file_details

get_file_details(data, file_name, file_type)
}
Err(e) => Err(FileError::InvalidData(e.to_string())),
};
Expand All @@ -54,17 +54,17 @@ pub fn Add() -> Html {
// store task so it doesn't get dropped
*task_ref.borrow_mut() = Some(task);
}
};
}
})
};

let onchange = {
let files_selected = files_selected.clone();
Callback::from(move |e: Event| {
let input: HtmlInputElement = e.target_unchecked_into();
input.files().and_then(|list| {
input.files().map(|list| {
files_selected.emit(list);
return Some(true);
Some(true)
});
})
};
Expand All @@ -81,11 +81,11 @@ pub fn Add() -> Html {
event
.data_transfer()
.and_then(|data| {
return data.files();
data.files()
})
.and_then(|list| {
.map(|list| {
files_selected.emit(list.clone());
return Some(true);
Some(true)
});
})
};
Expand All @@ -98,8 +98,8 @@ pub fn Add() -> Html {
event.prevent_default();
event.stop_propagation();

let _ = event.data_transfer().and_then(|_| {
return Some(true);
let _ = event.data_transfer().map(|_| {
Some(true)
});

s.set(true);
Expand All @@ -121,8 +121,8 @@ pub fn Add() -> Html {
Callback::from(move |event: DragEvent| {
event.prevent_default();

let _ = event.data_transfer().and_then(|_| {
return Some(true);
let _ = event.data_transfer().map(|_| {
Some(true)
});

s.set(false);
Expand Down
12 changes: 6 additions & 6 deletions src/components/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn Details() -> Html {

let file_error = use_memo(ctx.file.clone(), |file| file.clone().and_then(Result::err));

let is_exified = use_memo(ctx.exified, |ex| ex.clone());
let is_exified = use_memo(ctx.exified, |ex| *ex);

let has_exif = use_memo(ctx.file.clone(), |file|
file.clone().and_then(Result::ok).map(|fd| !fd.exif.is_empty()).unwrap_or(false));
Expand Down Expand Up @@ -59,8 +59,8 @@ pub fn Details() -> Html {
// Map error needed to stay with Result<_, JSValue>
.ok_or(JsValue::from_str("no document"))
.and_then(|d| d.create_element("a"))
.and_then(|elem| {
let name = exified_file_name(&fd);
.map(|elem| {
let name = exified_file_name(fd);
let a: HtmlAnchorElement = HtmlAnchorElement::from(JsValue::from(elem));
a.set_href(&url);
a.set_download(&name);
Expand All @@ -70,7 +70,7 @@ pub fn Details() -> Html {
Url::revoke_object_url(&url).unwrap();
document().body().unwrap().remove_child(&a).unwrap();
// return name
Ok(name)
name
})

);
Expand Down Expand Up @@ -106,10 +106,10 @@ pub fn Details() -> Html {
<div class="flex flex-col w-full items-center">
<img
class="max-w-[10rem] max-h-[10rem] w-auto h-auto border-[1em] border-sky-600 "
src={img_src(&fd)} />
src={img_src(fd)} />
<p class="text-gray-400 text-sm md:text-lg mt-2 truncate text-center">
{ if *is_exified {
exified_file_name(&fd)
exified_file_name(fd)
} else {
fd.name.clone()
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use img_parts::{Bytes, DynImage, ImageEXIF};
use crate::types::{ExifMap, FileDetails, FileError};

pub fn img_from_bytes(data: Vec<u8>) -> Result<DynImage, FileError> {
let image = DynImage::from_bytes(data.clone().into())
.map_err(|e| FileError::InvalidData(e.to_string()))?
.ok_or_else(|| FileError::InvalidData("No image data".to_string()));


image
DynImage::from_bytes(data.clone().into())
.map_err(|e| FileError::InvalidData(e.to_string()))?
.ok_or_else(|| FileError::InvalidData("No image data".to_string()))
}

pub fn exif_to_map(bytes: Bytes) -> Result<ExifMap, FileError> {
Expand Down

0 comments on commit 9b586e3

Please sign in to comment.