-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: confirm before deleting (#581)
Implement #579
- Loading branch information
Showing
8 changed files
with
101 additions
and
26 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
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,7 @@ | ||
import mitt from "mitt"; | ||
|
||
const emitter = mitt(); | ||
|
||
export function useEventBus() { | ||
return emitter; | ||
} |
41 changes: 41 additions & 0 deletions
41
app/renderer/ui/delete-confirm-view/useDeleteConfirmView.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,41 @@ | ||
import { useEventBus } from "./event-bus.ts"; | ||
|
||
const REJECT_EVENT = "reject_delete_confirm_view"; | ||
|
||
const RESOLVE_EVENT = "resolve_delete_confirm_view"; | ||
|
||
export function useCreateDeleteConfirmView() { | ||
const eventBus = useEventBus(); | ||
|
||
function onReject() { | ||
eventBus.emit(REJECT_EVENT); | ||
} | ||
|
||
function onResolve() { | ||
eventBus.emit(RESOLVE_EVENT); | ||
} | ||
|
||
return { onReject, onResolve }; | ||
} | ||
|
||
export function useDeleteConfirmView() { | ||
const uiState = uiStateService.useState(); | ||
const eventBus = useEventBus(); | ||
function confirm() { | ||
uiState.deleteConfirmShown = true; | ||
return new Promise((resolve) => { | ||
eventBus.on(RESOLVE_EVENT, () => { | ||
resolve(true); | ||
uiState.deleteConfirmShown = false; | ||
}); | ||
eventBus.on(REJECT_EVENT, () => { | ||
resolve(false); | ||
uiState.deleteConfirmShown = false; | ||
}); | ||
}).finally(() => { | ||
eventBus.off(RESOLVE_EVENT); | ||
eventBus.off(REJECT_EVENT); | ||
}); | ||
} | ||
return { confirm }; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.