dialog-session-delete-failed.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { TextAttributes } from "@opentui/core"
  2. import { useTheme } from "../context/theme"
  3. import { useDialog } from "../ui/dialog"
  4. import { createStore } from "solid-js/store"
  5. import { For } from "solid-js"
  6. import { useBindings } from "../keymap"
  7. export function DialogSessionDeleteFailed(props: {
  8. session: string
  9. workspace: string
  10. onDelete?: () => boolean | void | Promise<boolean | void>
  11. onRestore?: () => boolean | void | Promise<boolean | void>
  12. onDone?: () => void
  13. }) {
  14. const dialog = useDialog()
  15. const { theme } = useTheme()
  16. const [store, setStore] = createStore({
  17. active: "delete" as "delete" | "restore",
  18. })
  19. const options = [
  20. {
  21. id: "delete" as const,
  22. title: "Delete workspace",
  23. description: "Delete the workspace and all sessions attached to it.",
  24. run: props.onDelete,
  25. },
  26. {
  27. id: "restore" as const,
  28. title: "Restore to new workspace",
  29. description: "Try to restore this session into a new workspace.",
  30. run: props.onRestore,
  31. },
  32. ]
  33. async function confirm() {
  34. const result = await options.find((item) => item.id === store.active)?.run?.()
  35. if (result === false) return
  36. props.onDone?.()
  37. if (!props.onDone) dialog.clear()
  38. }
  39. useBindings(() => ({
  40. bindings: [
  41. { key: "return", desc: "Confirm recovery option", group: "Dialog", cmd: () => void confirm() },
  42. { key: "left", desc: "Delete broken session", group: "Dialog", cmd: () => setStore("active", "delete") },
  43. { key: "up", desc: "Delete broken session", group: "Dialog", cmd: () => setStore("active", "delete") },
  44. { key: "right", desc: "Restore broken session", group: "Dialog", cmd: () => setStore("active", "restore") },
  45. { key: "down", desc: "Restore broken session", group: "Dialog", cmd: () => setStore("active", "restore") },
  46. ],
  47. }))
  48. return (
  49. <box paddingLeft={2} paddingRight={2} gap={1}>
  50. <box flexDirection="row" justifyContent="space-between">
  51. <text attributes={TextAttributes.BOLD} fg={theme.text}>
  52. Failed to Delete Session
  53. </text>
  54. <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
  55. esc
  56. </text>
  57. </box>
  58. <text fg={theme.textMuted} wrapMode="word">
  59. {`The session "${props.session}" could not be deleted because the workspace "${props.workspace}" is not available.`}
  60. </text>
  61. <text fg={theme.textMuted} wrapMode="word">
  62. Choose how you want to recover this broken workspace session.
  63. </text>
  64. <box flexDirection="column" paddingBottom={1} gap={1}>
  65. <For each={options}>
  66. {(item) => (
  67. <box
  68. flexDirection="column"
  69. paddingLeft={1}
  70. paddingRight={1}
  71. paddingTop={1}
  72. paddingBottom={1}
  73. backgroundColor={item.id === store.active ? theme.primary : undefined}
  74. onMouseUp={() => {
  75. setStore("active", item.id)
  76. void confirm()
  77. }}
  78. >
  79. <text
  80. attributes={TextAttributes.BOLD}
  81. fg={item.id === store.active ? theme.selectedListItemText : theme.text}
  82. >
  83. {item.title}
  84. </text>
  85. <text fg={item.id === store.active ? theme.selectedListItemText : theme.textMuted} wrapMode="word">
  86. {item.description}
  87. </text>
  88. </box>
  89. )}
  90. </For>
  91. </box>
  92. </box>
  93. )
  94. }