mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* feat(frontend): mobile-friendly config editor with find bar and unsaved-changes guard * refactor: remove retry-clone flow and share destructive-confirm dialog Backend drops POST /:id/retry-clone and the supporting retryCloneRepo service and claimRepoForRetry query; failed clones now delete the repo row rather than lingering in error state. Frontend extracts ConfirmDestructiveDialog shared by Delete/Discard/UnsavedChanges dialogs, memoizes CodeEditor rows, fixes scroll jump while typing away from the active match, and aligns the responsive breakpoint to 768px.
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { useState, useEffect } from 'react'
|
|
|
|
const isTextInputFocused = () => {
|
|
const el = document.activeElement
|
|
if (!el) return false
|
|
const tag = el.tagName
|
|
return tag === 'TEXTAREA' || tag === 'INPUT' || (el as HTMLElement).isContentEditable
|
|
}
|
|
|
|
interface UseVisualViewportOptions {
|
|
enabled?: boolean
|
|
}
|
|
|
|
export function useVisualViewport({ enabled = true }: UseVisualViewportOptions = {}) {
|
|
const [keyboardHeight, setKeyboardHeight] = useState(0)
|
|
|
|
useEffect(() => {
|
|
if (!enabled) {
|
|
setKeyboardHeight(0)
|
|
return
|
|
}
|
|
const viewport = window.visualViewport
|
|
if (!viewport) return
|
|
|
|
const update = () => {
|
|
if (!isTextInputFocused()) {
|
|
setKeyboardHeight(0)
|
|
return
|
|
}
|
|
const layoutHeight = window.innerHeight
|
|
const visualHeight = viewport.height + viewport.offsetTop
|
|
const offset = Math.max(0, layoutHeight - visualHeight)
|
|
setKeyboardHeight(offset)
|
|
}
|
|
|
|
viewport.addEventListener('resize', update)
|
|
viewport.addEventListener('scroll', update)
|
|
window.addEventListener('focusin', update)
|
|
window.addEventListener('focusout', update)
|
|
window.addEventListener('pageshow', update)
|
|
document.addEventListener('visibilitychange', update)
|
|
update()
|
|
|
|
return () => {
|
|
viewport.removeEventListener('resize', update)
|
|
viewport.removeEventListener('scroll', update)
|
|
window.removeEventListener('focusin', update)
|
|
window.removeEventListener('focusout', update)
|
|
window.removeEventListener('pageshow', update)
|
|
document.removeEventListener('visibilitychange', update)
|
|
}
|
|
}, [enabled])
|
|
|
|
return { keyboardHeight }
|
|
}
|