Skip to content

Commit 0156f03

Browse files
committed
chore: cleanup theme stuff
1 parent e0bb96a commit 0156f03

File tree

3 files changed

+132
-195
lines changed

3 files changed

+132
-195
lines changed

packages/app/src/context/command.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createSimpleContext } from "@opencode-ai/ui/context"
33
import { useDialog } from "@opencode-ai/ui/context/dialog"
44
import { Dialog } from "@opencode-ai/ui/dialog"
55
import { List } from "@opencode-ai/ui/list"
6-
import { useTheme } from "@opencode-ai/ui/theme"
76

87
const IS_MAC = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform)
98

@@ -27,6 +26,7 @@ export interface CommandOption {
2726
suggested?: boolean
2827
disabled?: boolean
2928
onSelect?: (source?: "palette" | "keybind" | "slash") => void
29+
onHighlight?: () => (() => void) | void
3030
}
3131

3232
export function parseKeybind(config: string): Keybind[] {
@@ -116,32 +116,26 @@ export function formatKeybind(config: string): string {
116116

117117
function DialogCommand(props: { options: CommandOption[] }) {
118118
const dialog = useDialog()
119-
const theme = useTheme()
119+
let cleanup: (() => void) | void
120120
let committed = false
121121

122122
const handleMove = (option: CommandOption | undefined) => {
123-
if (!option) return
124-
if (option.id.startsWith("theme.set.")) {
125-
const id = option.id.replace("theme.set.", "")
126-
theme.previewTheme(id)
127-
} else if (option.id.startsWith("theme.scheme.") && !option.id.includes("cycle")) {
128-
const scheme = option.id.replace("theme.scheme.", "") as "light" | "dark" | "system"
129-
theme.previewColorScheme(scheme)
130-
}
123+
cleanup?.()
124+
cleanup = option?.onHighlight?.()
131125
}
132126

133127
const handleSelect = (option: CommandOption | undefined) => {
134128
if (option) {
135-
theme.commitPreview()
136129
committed = true
130+
cleanup = undefined
137131
dialog.close()
138132
option.onSelect?.("palette")
139133
}
140134
}
141135

142136
onCleanup(() => {
143137
if (!committed) {
144-
theme.cancelPreview()
138+
cleanup?.()
145139
}
146140
})
147141

packages/app/src/pages/layout.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { Header } from "@/components/header"
4949
import { useDialog } from "@opencode-ai/ui/context/dialog"
5050
import { useTheme, type ColorScheme } from "@opencode-ai/ui/theme"
5151
import { DialogSelectProvider } from "@/components/dialog-select-provider"
52-
import { useCommand } from "@/context/command"
52+
import { useCommand, type CommandOption } from "@/context/command"
5353
import { ConstrainDragXAxis } from "@/utils/solid-dnd"
5454

5555
export default function Layout(props: ParentProps) {
@@ -323,7 +323,7 @@ export default function Layout(props: ParentProps) {
323323
}
324324

325325
command.register(() => {
326-
const commands = [
326+
const commands: CommandOption[] = [
327327
{
328328
id: "sidebar.toggle",
329329
title: "Toggle sidebar",
@@ -387,7 +387,11 @@ export default function Layout(props: ParentProps) {
387387
id: `theme.set.${id}`,
388388
title: `Use theme: ${definition.name ?? id}`,
389389
category: "Theme",
390-
onSelect: () => theme.setTheme(id),
390+
onSelect: () => theme.commitPreview(),
391+
onHighlight: () => {
392+
theme.previewTheme(id)
393+
return () => theme.cancelPreview()
394+
},
391395
})
392396
}
393397

@@ -404,7 +408,11 @@ export default function Layout(props: ParentProps) {
404408
id: `theme.scheme.${scheme}`,
405409
title: `Use color scheme: ${colorSchemeLabel[scheme]}`,
406410
category: "Theme",
407-
onSelect: () => theme.setColorScheme(scheme),
411+
onSelect: () => theme.commitPreview(),
412+
onHighlight: () => {
413+
theme.previewColorScheme(scheme)
414+
return () => theme.cancelPreview()
415+
},
408416
})
409417
}
410418

0 commit comments

Comments
 (0)