mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 09:04:27 +00:00
Reuse modal for instance editing
This commit is contained in:
@@ -1,13 +1,47 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
import Header from '@/components/Header'
|
import Header from '@/components/Header'
|
||||||
import InstanceList from '@/components/InstanceList'
|
import InstanceList from '@/components/InstanceList'
|
||||||
|
import InstanceModal from '@/components/InstanceModal'
|
||||||
|
import { CreateInstanceOptions, Instance } from '@/types/instance'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const [isModalOpen, setIsModalOpen] = useState(false)
|
||||||
|
const [editingInstance, setEditingInstance] = useState<Instance | undefined>(undefined)
|
||||||
|
|
||||||
|
const handleCreateInstance = () => {
|
||||||
|
setEditingInstance(undefined)
|
||||||
|
setIsModalOpen(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEditInstance = (instance: Instance) => {
|
||||||
|
setEditingInstance(instance)
|
||||||
|
setIsModalOpen(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveInstance = (name: string, options: CreateInstanceOptions) => {
|
||||||
|
if (editingInstance) {
|
||||||
|
// TODO: Implement API call to update instance
|
||||||
|
console.log('Updating instance:', { name, options })
|
||||||
|
} else {
|
||||||
|
// TODO: Implement API call to create instance
|
||||||
|
console.log('Creating instance:', { name, options })
|
||||||
|
}
|
||||||
|
// For now, just log the data - you'll implement the API call later
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50">
|
<div className="min-h-screen bg-gray-50">
|
||||||
<Header />
|
<Header onCreateInstance={handleCreateInstance} />
|
||||||
<main className="container mx-auto max-w-4xl px-4 py-8">
|
<main className="container mx-auto max-w-4xl px-4 py-8">
|
||||||
<InstanceList />
|
<InstanceList editInstance={handleEditInstance} />
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<InstanceModal
|
||||||
|
open={isModalOpen}
|
||||||
|
onOpenChange={setIsModalOpen}
|
||||||
|
onSave={handleSaveInstance}
|
||||||
|
instance={editingInstance}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,24 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import InstanceModal from '@/components/InstanceModal'
|
|
||||||
import { CreateInstanceOptions } from '@/types/instance'
|
|
||||||
|
|
||||||
function Header() {
|
interface HeaderProps {
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false)
|
onCreateInstance: () => void
|
||||||
|
}
|
||||||
const handleCreateInstance = () => {
|
|
||||||
setIsModalOpen(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSaveInstance = (name: string, options: CreateInstanceOptions) => {
|
|
||||||
// TODO: Implement API call to create instance
|
|
||||||
console.log('Creating instance:', { name, options })
|
|
||||||
// For now, just log the data - you'll implement the API call later
|
|
||||||
}
|
|
||||||
|
|
||||||
|
function Header({ onCreateInstance }: HeaderProps) {
|
||||||
return (
|
return (
|
||||||
<>
|
<header className="bg-white border-b border-gray-200">
|
||||||
<header className="bg-white border-b border-gray-200">
|
<div className="container mx-auto max-w-4xl px-4 py-4">
|
||||||
<div className="container mx-auto max-w-4xl px-4 py-4">
|
<div className="flex items-center justify-between">
|
||||||
<div className="flex items-center justify-between">
|
<h1 className="text-2xl font-bold text-gray-900">
|
||||||
<h1 className="text-2xl font-bold text-gray-900">
|
LlamaCtl Dashboard
|
||||||
LlamaCtl Dashboard
|
</h1>
|
||||||
</h1>
|
|
||||||
|
<Button onClick={onCreateInstance}>
|
||||||
<Button onClick={handleCreateInstance}>
|
Create Instance
|
||||||
Create Instance
|
</Button>
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</div>
|
||||||
|
</header>
|
||||||
<InstanceModal
|
|
||||||
open={isModalOpen}
|
|
||||||
onOpenChange={setIsModalOpen}
|
|
||||||
onSave={handleSaveInstance}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ interface InstanceCardProps {
|
|||||||
startInstance: (name: string) => void
|
startInstance: (name: string) => void
|
||||||
stopInstance: (name: string) => void
|
stopInstance: (name: string) => void
|
||||||
deleteInstance: (name: string) => void
|
deleteInstance: (name: string) => void
|
||||||
|
editInstance: (instance: Instance) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
function InstanceCard({ instance, startInstance, stopInstance, deleteInstance }: InstanceCardProps) {
|
function InstanceCard({ instance, startInstance, stopInstance, deleteInstance, editInstance }: InstanceCardProps) {
|
||||||
|
|
||||||
const handleStart = () => {
|
const handleStart = () => {
|
||||||
startInstance(instance.name)
|
startInstance(instance.name)
|
||||||
@@ -28,8 +29,7 @@ function InstanceCard({ instance, startInstance, stopInstance, deleteInstance }:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleEdit = () => {
|
const handleEdit = () => {
|
||||||
// Logic for editing the instance (e.g., open a modal)
|
editInstance(instance)
|
||||||
console.log(`Edit instance: ${instance.name}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleLogs = () => {
|
const handleLogs = () => {
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import { useInstances } from '@/hooks/useInstances'
|
import { useInstances } from '@/hooks/useInstances'
|
||||||
import InstanceCard from '@/components/InstanceCard'
|
import InstanceCard from '@/components/InstanceCard'
|
||||||
|
import { Instance } from '@/types/instance'
|
||||||
|
|
||||||
function InstanceList() {
|
interface InstanceListProps {
|
||||||
|
editInstance: (instance: Instance) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function InstanceList({ editInstance }: InstanceListProps) {
|
||||||
const { instances, loading, error, startInstance, stopInstance, deleteInstance } = useInstances()
|
const { instances, loading, error, startInstance, stopInstance, deleteInstance } = useInstances()
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -49,6 +54,7 @@ function InstanceList() {
|
|||||||
startInstance={startInstance}
|
startInstance={startInstance}
|
||||||
stopInstance={stopInstance}
|
stopInstance={stopInstance}
|
||||||
deleteInstance={deleteInstance}
|
deleteInstance={deleteInstance}
|
||||||
|
editInstance={editInstance}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user