diff --git a/.gitignore b/.gitignore index aed20c54..2c95b307 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ coverage/ data/ workspace/ /config/ +temp/ diff --git a/frontend/public/opencode-logo-dark.svg b/frontend/public/opencode-logo-dark.svg new file mode 100644 index 00000000..b79c7332 --- /dev/null +++ b/frontend/public/opencode-logo-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/opencode-wordmark-dark.svg b/frontend/public/opencode-wordmark-dark.svg new file mode 100644 index 00000000..987d3931 --- /dev/null +++ b/frontend/public/opencode-wordmark-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/opencode-wordmark-light.svg b/frontend/public/opencode-wordmark-light.svg new file mode 100644 index 00000000..7a134f46 --- /dev/null +++ b/frontend/public/opencode-wordmark-light.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 99d84a76..e1224832 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -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() { } /> + ) } diff --git a/frontend/src/api/types.ts b/frontend/src/api/types.ts index e4a14f3e..8ec93415 100644 --- a/frontend/src/api/types.ts +++ b/frontend/src/api/types.ts @@ -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 } diff --git a/frontend/src/components/layout/Header.tsx b/frontend/src/components/layout/Header.tsx index f2a25bf8..13430f73 100644 --- a/frontend/src/components/layout/Header.tsx +++ b/frontend/src/components/layout/Header.tsx @@ -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 (
@@ -19,9 +21,19 @@ export function Header({ title, backTo, action }: HeaderProps) {
{backTo && } -

- {title} -

+
+ {title === "OpenCode" ? ( + OpenCode + ) : ( +

+ {title} +

+ )} +
{action &&
{action}
} diff --git a/frontend/src/hooks/useSSE.ts b/frontend/src/hooks/useSSE.ts index 98477205..37c76262 100644 --- a/frontend/src/hooks/useSSE.ts +++ b/frontend/src/hooks/useSSE.ts @@ -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 } diff --git a/frontend/src/hooks/useTheme.ts b/frontend/src/hooks/useTheme.ts index 1f7128c0..f152d73a 100644 --- a/frontend/src/hooks/useTheme.ts +++ b/frontend/src/hooks/useTheme.ts @@ -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 } diff --git a/frontend/src/lib/toast.ts b/frontend/src/lib/toast.ts new file mode 100644 index 00000000..4ffb5ca3 --- /dev/null +++ b/frontend/src/lib/toast.ts @@ -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 \ No newline at end of file