import { type } from '@tauri-apps/plugin-os'; import type { ProxyHeader } from '@yaakapp-internal/proxy-lib'; import { HeaderSize, IconButton, Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow, TruncatedWideTableCell, } from '@yaakapp-internal/ui'; import classNames from 'classnames'; import { useAtomValue } from 'jotai'; import { useRpcQueryWithEvent } from '../hooks/useRpcQueryWithEvent'; import { ActionButton } from './ActionButton'; import { filteredExchangesAtom, Sidebar } from './Sidebar'; export function ProxyLayout() { const osType = type(); const exchanges = useAtomValue(filteredExchangesAtom); const { data: proxyState } = useRpcQueryWithEvent('get_proxy_state', {}, 'proxy_state_changed'); const isRunning = proxyState?.state === 'running'; return (
Yaak Proxy
{isRunning ? 'Running on :9090' : 'Stopped'}
{exchanges.length === 0 ? (

No traffic yet

) : ( Method URL Status Type {exchanges.map((ex) => ( {ex.method} {ex.url} {getContentType(ex.resHeaders)} ))}
)}
); } function StatusBadge({ status, error }: { status: number | null; error: string | null }) { if (error) return Error; if (status == null) return ; const color = status >= 500 ? 'text-danger' : status >= 400 ? 'text-warning' : status >= 300 ? 'text-notice' : 'text-success'; return {status}; } function getContentType(headers: ProxyHeader[]): string { const ct = headers.find((h) => h.name.toLowerCase() === 'content-type')?.value; if (ct == null) return '—'; // Strip parameters (e.g. "; charset=utf-8") return ct.split(';')[0]?.trim() ?? ct; }