Merge pull request #5 from chriswritescode-dev/feat-upgrade-toasts

Feat upgrade toasts for opencode updates 
Logo
This commit is contained in:
Chris Scott authored and GitHub committed 2025-11-29 10:01:55 -05:00
commit 09541d55a8
10 files changed
+172 -4

No files matched your search

+1
View File
@@ -15,4 +15,5 @@ coverage/
data/
workspace/
/config/
temp/
+1
View File
@@ -0,0 +1 @@
<svg width='240' height='300' viewBox='0 0 240 300' fill='none' xmlns='http://www.w3.org/2000/svg'><g clip-path='url(#clip0_1401_86283)'><mask id='mask0_1401_86283' style='mask-type:luminance' maskUnits='userSpaceOnUse' x='0' y='0' width='240' height='300'><path d='M240 0H0V300H240V0Z' fill='white'/></mask><g mask='url(#mask0_1401_86283)'><path d='M180 240H60V120H180V240Z' fill='#4B4646'/><path d='M180 60H60V240H180V60ZM240 300H0V0H240V300Z' fill='#F1ECEC'/></g></g><defs><clipPath id='clip0_1401_86283'><rect width='240' height='300' fill='white'/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 577 B

@@ -0,0 +1 @@
<svg width='641' height='115' viewBox='0 0 641 115' fill='none' xmlns='http://www.w3.org/2000/svg'><g clip-path='url(#clip0_1401_86292)'><mask id='mask0_1401_86292' style='mask-type:luminance' maskUnits='userSpaceOnUse' x='0' y='0' width='641' height='115'><path d='M640.714 0H0V115H640.714V0Z' fill='white'/></mask><g mask='url(#mask0_1401_86292)'><path d='M49.2868 82.1433H16.4297V49.2861H49.2868V82.1433Z' fill='#4B4646'/><path d='M49.2857 32.8573H16.4286V82.143H49.2857V32.8573ZM65.7143 98.5716H0V16.4287H65.7143V98.5716Z' fill='#B7B1B1'/><path d='M131.427 82.1433H98.5703V49.2861H131.427V82.1433Z' fill='#4B4646'/><path d='M98.5692 82.143H131.426V32.8573H98.5692V82.143ZM147.855 98.5716H98.5692V115H82.1406V16.4287H147.855V98.5716Z' fill='#B7B1B1'/><path d='M229.997 65.7139V82.1424H180.711V65.7139H229.997Z' fill='#4B4646'/><path d='M230.003 65.7144H180.718V82.143H230.003V98.5716H164.289V16.4287H230.003V65.7144ZM180.718 49.2859H213.575V32.8573H180.718V49.2859Z' fill='#B7B1B1'/><path d='M295.717 98.5718H262.859V49.2861H295.717V98.5718Z' fill='#4B4646'/><path d='M295.715 32.8573H262.858V98.5716H246.43V16.4287H295.715V32.8573ZM312.144 98.5716H295.715V32.8573H312.144V98.5716Z' fill='#B7B1B1'/><path d='M394.286 82.1433H345V49.2861H394.286V82.1433Z' fill='#4B4646'/><path d='M394.285 32.8573H344.999V82.143H394.285V98.5716H328.57V16.4287H394.285V32.8573Z' fill='#F1ECEC'/><path d='M459.998 82.1433H427.141V49.2861H459.998V82.1433Z' fill='#4B4646'/><path d='M459.997 32.8573H427.14V82.143H459.997V32.8573ZM476.425 98.5716H410.711V16.4287H476.425V98.5716Z' fill='#F1ECEC'/><path d='M542.146 82.1433H509.289V49.2861H542.146V82.1433Z' fill='#4B4646'/><path d='M542.145 32.8571H509.288V82.1429H542.145V32.8571ZM558.574 98.5714H492.859V16.4286H542.145V0H558.574V98.5714Z' fill='#F1ECEC'/><path d='M640.715 65.7139V82.1424H591.43V65.7139H640.715Z' fill='#4B4646'/><path d='M591.429 32.8573V49.2859H624.286V32.8573H591.429ZM640.714 65.7144H591.429V82.143H640.714V98.5716H575V16.4287H640.714V65.7144Z' fill='#F1ECEC'/></g></g><defs><clipPath id='clip0_1401_86292'><rect width='640.714' height='115' fill='white'/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -0,0 +1 @@
<svg width='640' height='115' viewBox='0 0 640 115' fill='none' xmlns='http://www.w3.org/2000/svg'><g clip-path='url(#clip0_1401_86330)'><mask id='mask0_1401_86330' style='mask-type:luminance' maskUnits='userSpaceOnUse' x='0' y='0' width='640' height='115'><path d='M640 0H0V115H640V0Z' fill='white'/></mask><g mask='url(#mask0_1401_86330)'><path d='M49.2346 82.1433H16.4141V49.2861H49.2346V82.1433Z' fill='#CFCECD'/><path d='M49.2308 32.8573H16.4103V82.143H49.2308V32.8573ZM65.641 98.5716H0V16.4287H65.641V98.5716Z' fill='#656363'/><path d='M131.281 82.1433H98.4609V49.2861H131.281V82.1433Z' fill='#CFCECD'/><path d='M98.4649 82.143H131.285V32.8573H98.4649V82.143ZM147.696 98.5716H98.4649V115H82.0547V16.4287H147.696V98.5716Z' fill='#656363'/><path d='M229.746 65.7139V82.1424H180.516V65.7139H229.746Z' fill='#CFCECD'/><path d='M229.743 65.7144H180.512V82.143H229.743V98.5716H164.102V16.4287H229.743V65.7144ZM180.512 49.2859H213.332V32.8573H180.512V49.2859Z' fill='#656363'/><path d='M295.383 98.5718H262.562V49.2861H295.383V98.5718Z' fill='#CFCECD'/><path d='M295.387 32.8573H262.567V98.5716H246.156V16.4287H295.387V32.8573ZM311.797 98.5716H295.387V32.8573H311.797V98.5716Z' fill='#656363'/><path d='M393.848 82.1433H344.617V49.2861H393.848V82.1433Z' fill='#CFCECD'/><path d='M393.844 32.8573H344.613V82.143H393.844V98.5716H328.203V16.4287H393.844V32.8573Z' fill='#211E1E'/><path d='M459.485 82.1433H426.664V49.2861H459.485V82.1433Z' fill='#CFCECD'/><path d='M459.489 32.8573H426.668V82.143H459.489V32.8573ZM475.899 98.5716H410.258V16.4287H475.899V98.5716Z' fill='#211E1E'/><path d='M541.539 82.1433H508.719V49.2861H541.539V82.1433Z' fill='#CFCECD'/><path d='M541.535 32.8571H508.715V82.1428H541.535V32.8571ZM557.946 98.5714H492.305V16.4286H541.535V0H557.946V98.5714Z' fill='#211E1E'/><path d='M639.996 65.7139V82.1424H590.766V65.7139H639.996Z' fill='#CFCECD'/><path d='M590.77 32.8573V49.2859H623.59V32.8573H590.77ZM640 65.7144H590.77V82.143H640V98.5716H574.359V16.4287H640V65.7144Z' fill='#211E1E'/></g></g><defs><clipPath id='clip0_1401_86330'><rect width='640' height='115' fill='white'/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

+7
View File
@@ -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>
)
}
+16
View File
@@ -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 }
+15 -3
View File
@@ -2,6 +2,7 @@ import { Settings } from "lucide-react";
import { Button } from "@/components/ui/button";
import { BackButton } from "@/components/ui/back-button";
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
import { useTheme } from "@/hooks/useTheme";
import type { ReactNode } from "react";
interface HeaderProps {
@@ -12,6 +13,7 @@ interface HeaderProps {
export function Header({ title, backTo, action }: HeaderProps) {
const { open: openSettings } = useSettingsDialog();
const theme = useTheme();
return (
<header className="sticky top-0 z-10 bg-gradient-to-b from-background via-background to-background border-b border-border backdrop-blur-sm">
@@ -19,9 +21,19 @@ export function Header({ title, backTo, action }: HeaderProps) {
<div className="flex items-center justify-between h-16">
<div className="flex items-center gap-4">
{backTo && <BackButton to={backTo} />}
<h1 className="text-xl font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate">
{title}
</h1>
<div className="flex items-center gap-2">
{title === "OpenCode" ? (
<img
src={theme === 'light' ? "/opencode-wordmark-light.svg" : "/opencode-wordmark-dark.svg"}
alt="OpenCode"
className="h-6 w-auto sm:h-8"
/>
) : (
<h1 className="text-xl font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate">
{title}
</h1>
)}
</div>
</div>
<div className="flex items-center gap-2">
{action && <div>{action}</div>}
+85
View File
@@ -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
}
+6 -1
View File
@@ -1,8 +1,9 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useSettings } from './useSettings'
export function useTheme() {
const { preferences } = useSettings()
const [currentTheme, setCurrentTheme] = useState<'light' | 'dark'>('dark')
useEffect(() => {
const theme = preferences?.theme || 'dark'
@@ -11,8 +12,10 @@ export function useTheme() {
const applyTheme = (isDark: boolean) => {
if (isDark) {
root.classList.add('dark')
setCurrentTheme('dark')
} else {
root.classList.remove('dark')
setCurrentTheme('light')
}
}
@@ -27,4 +30,6 @@ export function useTheme() {
applyTheme(theme === 'dark')
}
}, [preferences?.theme])
return currentTheme
}
+39
View File
@@ -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