mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
section 4: Phase 4: Permission mode toggle in the composer and default
This commit is contained in:
1 parent
f85531f2d3
commit
dd4db97c0b
14 files changed
+379
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { Shield, ShieldCheck } from 'lucide-react'
|
||||
import { useSessionPermissionMode, useSetSessionPermissionMode } from '@/hooks/useSessionPermissionMode'
|
||||
|
||||
interface PermissionModeToggleProps {
|
||||
sessionID: string
|
||||
directory: string
|
||||
}
|
||||
|
||||
export function PermissionModeToggle({ sessionID, directory }: PermissionModeToggleProps) {
|
||||
const { data, isError } = useSessionPermissionMode(sessionID)
|
||||
const setMode = useSetSessionPermissionMode(sessionID)
|
||||
|
||||
const loaded = data !== undefined
|
||||
const isAuto = data?.mode === 'auto'
|
||||
const inherited = data?.inherited ?? false
|
||||
const disabled = !loaded || inherited || setMode.isPending
|
||||
|
||||
const label = !loaded
|
||||
? isError
|
||||
? 'Permissions: unavailable'
|
||||
: 'Permissions: loading'
|
||||
: inherited
|
||||
? 'Inherited from parent session'
|
||||
: isAuto
|
||||
? 'Permissions: accept everything'
|
||||
: 'Permissions: ask every time'
|
||||
|
||||
const handleClick = () => {
|
||||
if (disabled) return
|
||||
setMode.mutate({ directory, mode: isAuto ? 'ask' : 'auto' })
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClick}
|
||||
disabled={disabled}
|
||||
title={label}
|
||||
aria-label={label}
|
||||
className={`p-2 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 shadow-md border disabled:opacity-50 disabled:cursor-not-allowed disabled:active:scale-100 disabled:hover:scale-100 ${
|
||||
isAuto
|
||||
? 'bg-highlight hover:bg-highlight/90 text-highlight-foreground border-highlight'
|
||||
: 'bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border'
|
||||
}`}
|
||||
>
|
||||
{isAuto ? <ShieldCheck className="w-5 h-5" /> : <Shield className="w-5 h-5" />}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user