checkpoint
This commit is contained in:
@@ -13,6 +13,7 @@ type ShortcutOptions = {
|
||||
onTabChange: (tab: TabId) => void
|
||||
onAction?: (action: string) => void
|
||||
inputFocused?: boolean
|
||||
navigationEnabled?: boolean
|
||||
}
|
||||
|
||||
export function useAppKeyboard(options: ShortcutOptions) {
|
||||
@@ -35,11 +36,25 @@ export function useAppKeyboard(options: ShortcutOptions) {
|
||||
return
|
||||
}
|
||||
|
||||
if (key.name === "escape") {
|
||||
options.onAction?.("escape")
|
||||
return
|
||||
}
|
||||
|
||||
// Skip global shortcuts if input is focused (let input handle keys)
|
||||
if (options.inputFocused) {
|
||||
return
|
||||
}
|
||||
|
||||
if (options.navigationEnabled === false) {
|
||||
return
|
||||
}
|
||||
|
||||
if (key.name === "enter") {
|
||||
options.onAction?.("enter")
|
||||
return
|
||||
}
|
||||
|
||||
// Tab navigation with left/right arrows OR [ and ]
|
||||
if (key.name === "right" || key.name === "]") {
|
||||
options.onTabChange(getNextTab(options.activeTab))
|
||||
@@ -89,8 +104,6 @@ export function useAppKeyboard(options: ShortcutOptions) {
|
||||
options.onAction("save")
|
||||
} else if (key.ctrl && key.name === "f") {
|
||||
options.onAction("find")
|
||||
} else if (key.name === "escape") {
|
||||
options.onAction("escape")
|
||||
} else if (key.name === "?" || (key.shift && key.name === "/")) {
|
||||
options.onAction("help")
|
||||
}
|
||||
|
||||
34
src/hooks/useCachedData.ts
Normal file
34
src/hooks/useCachedData.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { createSignal, onCleanup } from "solid-js"
|
||||
|
||||
type CacheOptions<T> = {
|
||||
fetcher: () => Promise<T>
|
||||
intervalMs?: number
|
||||
}
|
||||
|
||||
export const useCachedData = <T,>(options: CacheOptions<T>) => {
|
||||
const [data, setData] = createSignal<T | null>(null)
|
||||
const [loading, setLoading] = createSignal(false)
|
||||
const [error, setError] = createSignal<string | null>(null)
|
||||
|
||||
const refresh = async () => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const value = await options.fetcher()
|
||||
setData(() => value)
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Failed to load data")
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
refresh()
|
||||
|
||||
if (options.intervalMs) {
|
||||
const interval = setInterval(refresh, options.intervalMs)
|
||||
onCleanup(() => clearInterval(interval))
|
||||
}
|
||||
|
||||
return { data, loading, error, refresh }
|
||||
}
|
||||
Reference in New Issue
Block a user