mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Add global permission request system with centralized context and dialog
This commit is contained in:
1 parent
6ce3548dfe
commit
e3a3cbde84
12 files changed
+371
-45
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Settings } from "lucide-react";
|
||||
import { Settings, Bell } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { BackButton } from "@/components/ui/back-button";
|
||||
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
|
||||
@@ -9,9 +9,11 @@ interface HeaderProps {
|
||||
title: string;
|
||||
backTo?: string;
|
||||
action?: ReactNode;
|
||||
pendingPermissions?: number;
|
||||
onPendingPermissionsClick?: () => void;
|
||||
}
|
||||
|
||||
export function Header({ title, backTo, action }: HeaderProps) {
|
||||
export function Header({ title, backTo, action, pendingPermissions, onPendingPermissionsClick }: HeaderProps) {
|
||||
const { open: openSettings } = useSettingsDialog();
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -37,6 +39,22 @@ export function Header({ title, backTo, action }: HeaderProps) {
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{action && <div>{action}</div>}
|
||||
{pendingPermissions !== undefined && pendingPermissions > 0 && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onPendingPermissionsClick}
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-accent transition-all duration-200 relative"
|
||||
title={`${pendingPermissions} pending permission${pendingPermissions > 1 ? 's' : ''}`}
|
||||
>
|
||||
<Bell className="w-10 h-10" />
|
||||
{pendingPermissions > 0 && (
|
||||
<span className="absolute -top-1 -right-1 bg-destructive text-destructive-foreground text-xs font-bold rounded-full w-5 h-5 flex items-center justify-center">
|
||||
{pendingPermissions > 9 ? '9+' : pendingPermissions}
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
|
||||
@@ -496,10 +496,19 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
|
||||
|
||||
|
||||
return (
|
||||
return (
|
||||
<div className="relative backdrop-blur-md bg-background opacity-95 border border-border dark:border-white/30 rounded-xl p-2 md:p-3 mb-4 md:mb-1 w-full">
|
||||
|
||||
|
||||
{showStopButton && (
|
||||
<button
|
||||
onClick={handleStop}
|
||||
disabled={disabled}
|
||||
className="fixed bottom-19 right-0 md:hidden z-50 p-3 rounded-xl transition-all duration-200 active:scale-95 hover:scale-105 bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border border-red-500/60 shadow-lg shadow-red-500/30"
|
||||
title="Stop"
|
||||
>
|
||||
<Square className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={prompt}
|
||||
@@ -523,7 +532,7 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
<div className="flex gap-1.5 md:gap-2 items-center">
|
||||
<button
|
||||
onClick={handleModeToggle}
|
||||
className={`px-3 md:px-3.5 py-1 md:py-2 rounded-lg text-sm font-medium border w-14 flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md ${
|
||||
className={`px-3 md:px-3.5 py-1 h-[36px] rounded-lg text-sm font-medium border w-14 flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md ${
|
||||
isBashMode
|
||||
? 'bg-purple-500/20 border-purple-400 text-purple-700 dark:text-purple-300 shadow-purple-500/20 hover:shadow-purple-500/30'
|
||||
: `${modeBg} ${modeColor} ${modeShadow}`
|
||||
@@ -532,14 +541,14 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
{isBashMode ? 'BASH' : currentMode.toUpperCase()}
|
||||
</button>
|
||||
{hasActiveStream ? (
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground max-w-[120px] md:max-w-[180px] dark:border-white/30">
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
|
||||
<SessionStatusIndicator sessionID={sessionID} />
|
||||
</div>
|
||||
) : (
|
||||
!hideSecondaryButtons && (
|
||||
<button
|
||||
onClick={onShowModelsDialog}
|
||||
className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer max-w-[150px] md:max-w-[220px] truncate dark:border-white/30"
|
||||
className="px-2.5 py-1.5 md:px-3 h-[36px] rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer max-w-[150px] md:max-w-[220px] truncate dark:border-white/30"
|
||||
>
|
||||
{displayModelName || 'Select model'}
|
||||
</button>
|
||||
@@ -559,10 +568,10 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
<button
|
||||
onClick={handleStop}
|
||||
disabled={disabled}
|
||||
className="p-1.5 px-4 md:p-2 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border border-red-500/60 hover:border-red-400 shadow-md shadow-red-500/30 hover:shadow-red-500/40 ring-1 ring-red-500/20 hover:ring-red-500/30"
|
||||
className="hidden md:block p-1.5 px-5 md:p-2 md:px-6 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border border-red-500/60 hover:border-red-400 shadow-md shadow-red-500/30 hover:shadow-red-500/40 ring-1 ring-red-500/20 hover:ring-red-500/30"
|
||||
title="Stop"
|
||||
>
|
||||
<Square className="w-4 h-4" />
|
||||
<Square className="w-4 h-4 md:w-5 md:h-5" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
|
||||
@@ -18,6 +18,8 @@ interface PermissionRequestDialogProps {
|
||||
sessionTitle?: string
|
||||
onRespond: (permissionID: string, sessionID: string, response: PermissionResponse) => Promise<void>
|
||||
onDismiss: (permissionID: string, sessionID?: string) => void
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
}
|
||||
|
||||
function getPermissionTypeLabel(type: string): string {
|
||||
@@ -113,11 +115,14 @@ export function PermissionRequestDialog({
|
||||
sessionTitle,
|
||||
onRespond,
|
||||
onDismiss,
|
||||
open: parentOpen,
|
||||
onOpenChange,
|
||||
}: PermissionRequestDialogProps) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [loadingAction, setLoadingAction] = useState<PermissionResponse | null>(null)
|
||||
|
||||
if (!permission) return null
|
||||
if (parentOpen === false) return null
|
||||
|
||||
const handleResponse = async (response: PermissionResponse) => {
|
||||
setIsLoading(true)
|
||||
@@ -139,8 +144,8 @@ export function PermissionRequestDialog({
|
||||
const displaySessionName = sessionTitle || `Session ${permission.sessionID.slice(0, 8)}...`
|
||||
|
||||
return (
|
||||
<Dialog open={true} onOpenChange={() => {}}>
|
||||
<DialogContent hideCloseButton className="max-w-[calc(100vw-2rem)] sm:max-w-md">
|
||||
<Dialog open={parentOpen ?? true} onOpenChange={onOpenChange ?? (() => {})}>
|
||||
<DialogContent className="max-w-[calc(100vw-2rem)] sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
Permission Request
|
||||
|
||||
@@ -61,7 +61,7 @@ export const FloatingActionButton = memo(function FloatingActionButton({
|
||||
onClick={onClick}
|
||||
disabled={loading}
|
||||
className={cn(
|
||||
'fixed z-50 flex items-center gap-2 px-4 py-2 rounded-full backdrop-blur-md transition-all duration-200',
|
||||
'fixed z-50 flex items-center gap-2 px-4 py-2 rounded-xl backdrop-blur-md transition-all duration-200',
|
||||
'min-w-[48px] min-h-[48px]',
|
||||
'active:scale-95 hover:scale-105',
|
||||
'transition-transform',
|
||||
|
||||
Reference in new issue
Block a user