fix: mclogs notification showing repeatedly (#942)
This commit is contained in:
parent
7a6a7cbc0b
commit
97852aea41
2 changed files with 43 additions and 24 deletions
5
.changeset/mclogs_upload_notification_shows_once.md
Normal file
5
.changeset/mclogs_upload_notification_shows_once.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
# The "Uploaded to mclo.gs" notification no longer repeats when switching back to the Logs tab
|
||||
|
|
@ -33,35 +33,49 @@ impl Component for UploadToMclogs {
|
|||
|
||||
pub fn use_mclogs_feedback(upload: UseUploadLog) {
|
||||
let dispatch = use_dispatch();
|
||||
let mut handled = use_state(|| None::<String>);
|
||||
|
||||
use_side_effect(move || match &*upload.read().state() {
|
||||
let mut handled = use_state(|| match &*upload.peek().state() {
|
||||
MutationStateData::Settled {
|
||||
res: Ok(result), ..
|
||||
} => {
|
||||
if handled.peek().as_deref() == Some(result.url.as_str()) {
|
||||
return;
|
||||
}
|
||||
settlement_instant, ..
|
||||
} => Some(*settlement_instant),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
handled.set(Some(result.url.clone()));
|
||||
let _ = Clipboard::set(result.url.clone());
|
||||
use_side_effect(move || {
|
||||
let reader = upload.read();
|
||||
let state = reader.state();
|
||||
let MutationStateData::Settled {
|
||||
res,
|
||||
settlement_instant,
|
||||
} = &*state
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
dispatch
|
||||
.notify("Uploaded to mclo.gs")
|
||||
.body(format!("{} (copied to clipboard)", result.url))
|
||||
.info()
|
||||
.icon(IconType::LinkExternal01)
|
||||
.send();
|
||||
if *handled.peek() == Some(*settlement_instant) {
|
||||
return;
|
||||
}
|
||||
MutationStateData::Settled { res: Err(err), .. } => {
|
||||
let msg = err.to_string();
|
||||
if handled.peek().as_deref() == Some(msg.as_str()) {
|
||||
return;
|
||||
}
|
||||
handled.set(Some(*settlement_instant));
|
||||
|
||||
handled.set(Some(msg.clone()));
|
||||
dispatch.notify("Upload failed").body(msg).error().send();
|
||||
match res {
|
||||
Ok(result) => {
|
||||
if let Err(err) = Clipboard::set(result.url.clone()) {
|
||||
tracing::warn!("clipboard copy failed: {err:?}");
|
||||
}
|
||||
|
||||
dispatch
|
||||
.notify("Uploaded to mclo.gs")
|
||||
.body(format!("{} (copied to clipboard)", result.url))
|
||||
.info()
|
||||
.icon(IconType::LinkExternal01)
|
||||
.send();
|
||||
}
|
||||
Err(err) => {
|
||||
dispatch
|
||||
.notify("Upload failed")
|
||||
.body(err.to_string())
|
||||
.error()
|
||||
.send();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue