Skip to content

Commit dcd251a

Browse files
Merge pull request xiaoluoboding#71 from libondev/main
fix: fix the problem of rate calculation error when clicking actions …
2 parents b93387f + 1f1af25 commit dcd251a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/Toast.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const swiping = ref(false)
176176
const swipeOut = ref(false)
177177
const offsetBeforeRemove = ref(0)
178178
const initialHeight = ref(0)
179-
const dragStartTime = ref<Date | null>(null)
179+
let dragStartTime: number = 0
180180
const toastRef = ref<HTMLLIElement | null>(null)
181181
const isFront = computed(() => props.index === 0)
182182
const isVisible = computed(() => props.index + 1 <= props.visibleToasts)
@@ -290,7 +290,7 @@ const handleCloseToast = () => {
290290
291291
const onPointerDown = (event: PointerEvent) => {
292292
if (disabled.value || !dismissible.value) return
293-
dragStartTime.value = new Date()
293+
dragStartTime = Date.now()
294294
offsetBeforeRemove.value = offset.value
295295
// Ensure we maintain correct pointer capture even when going outside of the toast (e.g. when swiping)
296296
;(event.target as HTMLElement).setPointerCapture(event.pointerId)
@@ -309,7 +309,7 @@ const onPointerUp = (event: PointerEvent) => {
309309
.replace('px', '') || 0
310310
)
311311
312-
const timeTaken = new Date().getTime() - dragStartTime!.value!.getTime()
312+
const timeTaken = (Date.now() - dragStartTime) || 50
313313
const velocity = Math.abs(swipeAmount) / timeTaken
314314
315315
// Remove only if treshold is met
@@ -362,16 +362,16 @@ watchEffect((onInvalidate) => {
362362
const pauseTimer = () => {
363363
if (lastCloseTimerStartTimeRef.value < closeTimerStartTimeRef.value) {
364364
// Get the elapsed time since the timer started
365-
const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.value
365+
const elapsedTime = Date.now() - closeTimerStartTimeRef.value
366366
367367
remainingTime.value = remainingTime.value - elapsedTime
368368
}
369369
370-
lastCloseTimerStartTimeRef.value = new Date().getTime()
370+
lastCloseTimerStartTimeRef.value = Date.now()
371371
}
372372
373373
const startTimer = () => {
374-
closeTimerStartTimeRef.value = new Date().getTime()
374+
closeTimerStartTimeRef.value = Date.now()
375375
// Let the toast know it has started
376376
timeoutId = setTimeout(() => {
377377
props.toast.onAutoClose?.(props.toast)

0 commit comments

Comments
 (0)