Skip to content

Commit 14b41c3

Browse files
Copilotgfauredev
andcommitted
fix: avoid clippy cast_precision_loss in HoldDeleteButton progress calc
Agent-Logs-Url: https://github.com/gfauredev/LogOut/sessions/ec2dd9cd-a427-4c82-b793-79c65466f9bb Co-authored-by: gfauredev <19304085+gfauredev@users.noreply.github.com>
1 parent a843651 commit 14b41c3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/components/hold_delete.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use dioxus_i18n::t;
66
/// Number of 100 ms ticks that must elapse while the button is held before the
77
/// delete action fires (30 × 100 ms = 3 s).
88
const HOLD_STEPS: u32 = 30;
9+
/// `HOLD_STEPS` as `f32` for progress computations; no precision loss for this
10+
/// small value.
11+
const HOLD_STEPS_F32: f32 = 30.0;
912
/// Duration of each tick in milliseconds.
1013
const HOLD_TICK_MS: u32 = 100;
1114
/// SVG viewBox half-side (the SVG is `RING_SIZE × RING_SIZE`).
@@ -52,15 +55,18 @@ pub fn HoldDeleteButton(on_delete: EventHandler<()>, title: String) -> Element {
5255
let hint = hint_msg.clone();
5356
let mut toast = consume_context::<ToastSignal>().0;
5457
spawn(async move {
55-
for step in 1..=HOLD_STEPS {
58+
let increment = 1.0_f32 / HOLD_STEPS_F32;
59+
let mut cur_progress = 0.0_f32;
60+
for _ in 0..HOLD_STEPS {
5661
sleep_ms(HOLD_TICK_MS).await;
5762
if *gen.peek() != next {
5863
// Released early – show the hint toast.
5964
toast.write().push_back(hint);
6065
progress.set(0.0);
6166
return;
6267
}
63-
progress.set(step as f32 / HOLD_STEPS as f32);
68+
cur_progress += increment;
69+
progress.set(cur_progress);
6470
}
6571
// Full 3 s elapsed – fire the delete action.
6672
if *gen.peek() == next {

0 commit comments

Comments
 (0)