mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add global toast system with installation event notifications
- Add SSE event types for installation updates - Implement global toast system using Sonner - Add restart functionality directly in toast actions - Update .gitignore to exclude temp directory
This commit is contained in:
1 parent
ae929a7c96
commit
37b00e27ea
5 files changed
+148
No files matched your search
@@ -15,4 +15,5 @@ coverage/
|
||||
data/
|
||||
workspace/
|
||||
/config/
|
||||
temp/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
||||
import { Toaster } from 'sonner'
|
||||
import { Repos } from './pages/Repos'
|
||||
import { RepoDetail } from './pages/RepoDetail'
|
||||
import { SessionDetail } from './pages/SessionDetail'
|
||||
@@ -29,6 +30,12 @@ function AppContent() {
|
||||
<Route path="/session/:sessionId" element={<SessionDetail />} />
|
||||
</Routes>
|
||||
<SettingsDialog open={isOpen} onOpenChange={close} />
|
||||
<Toaster
|
||||
position="bottom-right"
|
||||
expand={false}
|
||||
richColors
|
||||
closeButton
|
||||
/>
|
||||
</BrowserRouter>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -102,6 +102,20 @@ export interface SSEPermissionRepliedEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSEInstallationUpdatedEvent {
|
||||
type: 'installation.updated'
|
||||
properties: {
|
||||
version: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSEInstallationUpdateAvailableEvent {
|
||||
type: 'installation.update-available'
|
||||
properties: {
|
||||
version: string
|
||||
}
|
||||
}
|
||||
|
||||
export type SSEEvent =
|
||||
| SSEMessagePartUpdatedEvent
|
||||
| SSEMessageUpdatedEvent
|
||||
@@ -113,6 +127,8 @@ export type SSEEvent =
|
||||
| SSETodoUpdatedEvent
|
||||
| SSEPermissionUpdatedEvent
|
||||
| SSEPermissionRepliedEvent
|
||||
| SSEInstallationUpdatedEvent
|
||||
| SSEInstallationUpdateAvailableEvent
|
||||
|
||||
export type ContentPart =
|
||||
| { type: 'text', content: string }
|
||||
|
||||
@@ -3,10 +3,73 @@ import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useOpenCodeClient } from './useOpenCode'
|
||||
import type { SSEEvent, MessageListResponse } from '@/api/types'
|
||||
import { permissionEvents } from './usePermissionRequests'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
|
||||
const MAX_RECONNECT_DELAY = 30000
|
||||
const INITIAL_RECONNECT_DELAY = 1000
|
||||
|
||||
const handleRestartServer = async () => {
|
||||
showToast.loading('Restarting OpenCode server...', {
|
||||
id: 'restart-server',
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await settingsApi.restartOpenCodeServer()
|
||||
if (result.success) {
|
||||
showToast.success(result.message || 'OpenCode server restarted successfully', {
|
||||
id: 'restart-server',
|
||||
duration: 3000,
|
||||
})
|
||||
setTimeout(() => {
|
||||
window.location.reload()
|
||||
}, 2000)
|
||||
} else {
|
||||
showToast.error(result.message || 'Failed to restart OpenCode server', {
|
||||
id: 'restart-server',
|
||||
duration: 5000,
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
showToast.error(error instanceof Error ? error.message : 'Failed to restart OpenCode server', {
|
||||
id: 'restart-server',
|
||||
duration: 5000,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Debug function to emulate toasts - remove in production
|
||||
if (typeof window !== 'undefined') {
|
||||
(window as any).testToasts = {
|
||||
updateAvailable: () => {
|
||||
showToast.info(`OpenCode v1.2.3 is available`, {
|
||||
description: 'A new version is ready to install.',
|
||||
action: {
|
||||
label: 'Restart to Update',
|
||||
onClick: handleRestartServer
|
||||
},
|
||||
duration: 10000,
|
||||
})
|
||||
},
|
||||
updated: () => {
|
||||
showToast.success(`OpenCode updated to v1.2.3`, {
|
||||
description: 'The server has been successfully upgraded.',
|
||||
duration: 5000,
|
||||
})
|
||||
},
|
||||
restartTest: () => {
|
||||
handleRestartServer()
|
||||
},
|
||||
basic: () => {
|
||||
showToast.info('This is a basic info toast')
|
||||
showToast.success('This is a success toast')
|
||||
showToast.warning('This is a warning toast')
|
||||
showToast.error('This is an error toast')
|
||||
}
|
||||
}
|
||||
console.log('🍞 Toast test functions available: window.testToasts.updateAvailable(), window.testToasts.updated(), window.testToasts.restartTest(), window.testToasts.basic()')
|
||||
}
|
||||
|
||||
export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) => {
|
||||
const client = useOpenCodeClient(opcodeUrl, directory)
|
||||
const queryClient = useQueryClient()
|
||||
@@ -228,6 +291,28 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string)
|
||||
}
|
||||
break
|
||||
|
||||
case 'installation.updated':
|
||||
if ('version' in event.properties) {
|
||||
showToast.success(`OpenCode updated to v${event.properties.version}`, {
|
||||
description: 'The server has been successfully upgraded.',
|
||||
duration: 5000,
|
||||
})
|
||||
}
|
||||
break
|
||||
|
||||
case 'installation.update-available':
|
||||
if ('version' in event.properties) {
|
||||
showToast.info(`OpenCode v${event.properties.version} is available`, {
|
||||
description: 'A new version is ready to install.',
|
||||
action: {
|
||||
label: 'Restart to Update',
|
||||
onClick: handleRestartServer
|
||||
},
|
||||
duration: 10000,
|
||||
})
|
||||
}
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { toast } from 'sonner'
|
||||
|
||||
interface ToastOptions {
|
||||
duration?: number
|
||||
description?: string
|
||||
action?: {
|
||||
label: string
|
||||
onClick: () => void
|
||||
}
|
||||
id?: string | number
|
||||
}
|
||||
|
||||
export const showToast = {
|
||||
success: (message: string, options?: ToastOptions) => {
|
||||
return toast.success(message, options)
|
||||
},
|
||||
|
||||
error: (message: string, options?: ToastOptions) => {
|
||||
return toast.error(message, options)
|
||||
},
|
||||
|
||||
info: (message: string, options?: ToastOptions) => {
|
||||
return toast.info(message, options)
|
||||
},
|
||||
|
||||
warning: (message: string, options?: ToastOptions) => {
|
||||
return toast.warning(message, options)
|
||||
},
|
||||
|
||||
loading: (message: string, options?: ToastOptions) => {
|
||||
return toast.loading(message, options)
|
||||
},
|
||||
|
||||
dismiss: (id?: string | number) => {
|
||||
toast.dismiss(id)
|
||||
}
|
||||
}
|
||||
|
||||
export type ShowToast = typeof showToast
|
||||
Reference in new issue
Block a user