-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from PasteBar/200/fix-selection-state-after-d…
…elete Fixing delete history items using del button with confirmation along with other fixes
- Loading branch information
Showing
17 changed files
with
251 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'pastebar-app-ui': patch | ||
--- | ||
|
||
Fix: update history items in quick paste window after delete operation in main window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'pastebar-app-ui': patch | ||
--- | ||
|
||
Fix: refresh native menu on history items delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'pastebar-app-ui': patch | ||
--- | ||
|
||
Press Delete key to delete single or multiple items with confirmation on second press |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/pastebar-app-ui/src/hooks/use-delete-confirmation-items.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react' | ||
import { UniqueIdentifier } from '@dnd-kit/core' | ||
import { Signal } from '@preact/signals-react' | ||
import { useHotkeys } from 'react-hotkeys-hook' | ||
|
||
const useDeleteConfirmationTimer = ({ | ||
onConfirmedDelete, | ||
hoveringHistoryRowId, | ||
onConfirmedReset, | ||
selectedHistoryItems, | ||
timerDuration = 3000, | ||
}: { | ||
onConfirmedDelete: () => Promise<void> | ||
onConfirmedReset?: () => void | ||
selectedHistoryItems: UniqueIdentifier[] | ||
hoveringHistoryRowId: Signal<UniqueIdentifier | null> | null | ||
timerDuration?: number | ||
}) => { | ||
const timerRef = useRef(null) as React.MutableRefObject<NodeJS.Timeout | null> | ||
const [showConfirmation, setShowConfirmation] = useState(false) | ||
const [hoveringHistoryIdDelete, seHoveringHistoryIdDelete] = | ||
useState<UniqueIdentifier | null>(null) | ||
|
||
const resetTimer = useCallback(() => { | ||
if (timerRef.current) { | ||
clearTimeout(timerRef.current) | ||
} | ||
seHoveringHistoryIdDelete(null) | ||
setShowConfirmation(false) | ||
onConfirmedReset?.() | ||
}, []) | ||
|
||
const startTimer = useCallback(() => { | ||
if (timerRef.current) { | ||
clearTimeout(timerRef.current) | ||
} | ||
if (hoveringHistoryRowId?.value && selectedHistoryItems.length === 0) { | ||
seHoveringHistoryIdDelete(hoveringHistoryRowId.value) | ||
} | ||
setShowConfirmation(true) | ||
|
||
timerRef.current = setTimeout(() => { | ||
resetTimer() | ||
}, timerDuration) | ||
}, [timerDuration, resetTimer, selectedHistoryItems]) | ||
|
||
useEffect(() => { | ||
return () => { | ||
if (timerRef.current) { | ||
clearTimeout(timerRef.current) | ||
} | ||
} | ||
}, []) | ||
|
||
useHotkeys( | ||
['delete', 'backspace'], | ||
async e => { | ||
e.preventDefault() | ||
|
||
if (showConfirmation) { | ||
await onConfirmedDelete() | ||
resetTimer() | ||
} else { | ||
startTimer() | ||
} | ||
}, | ||
{ | ||
enableOnFormTags: false, | ||
} | ||
) | ||
|
||
return { | ||
showConfirmation, | ||
hoveringHistoryIdDelete, | ||
resetTimer, | ||
} | ||
} | ||
|
||
export default useDeleteConfirmationTimer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.