Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | 'use client'; import { useState, useEffect, useCallback } from 'react'; import Link from 'next/link'; import type { TypeScriptResult, TypeScriptError, CommandStatusResponse } from '@/lib/dev-tools/types'; export default function TypeScriptCheckerPage() { const [status, setStatus] = useState<CommandStatusResponse>({ status: 'idle' }); const [isStarting, setIsStarting] = useState(false); const [filterCode, setFilterCode] = useState(''); const fetchStatus = useCallback(async () => { try { const res = await fetch('/api/admin/dev-tools/typescript'); if (res.ok) { const result = await res.json(); // Handle both new wrapped format and legacy format const data = result.data ?? result; setStatus(data); } } catch { // Ignore errors } }, []); // Fetch initial status useEffect(() => { fetchStatus(); }, [fetchStatus]); // Poll for status updates when running useEffect(() => { if (status.status !== 'running') return; const interval = setInterval(fetchStatus, 2000); return () => clearInterval(interval); }, [status.status, fetchStatus]); const runCheck = async () => { setIsStarting(true); try { const res = await fetch('/api/admin/dev-tools/typescript', { method: 'POST'}); if (res.ok) { setStatus({ status: 'running', startedAt: new Date().toISOString() }); } } finally { setIsStarting(false); } }; const stopCheck = async () => { await fetch('/api/admin/dev-tools/typescript', { method: 'DELETE' }); fetchStatus(); }; const tsResult = status.result as TypeScriptResult | undefined; // Group errors by file const errorsByFile = tsResult?.errors.reduce((acc, error) => { if (!acc[error.file]) { acc[error.file] = []; } acc[error.file].push(error); return acc; }, {} as Record<string, TypeScriptError[]>) || {}; // Filter errors by code if filter is set const filteredErrorsByFile = filterCode ? Object.entries(errorsByFile).reduce((acc, [file, errors]) => { const filtered = errors.filter(e => e.code.toLowerCase().includes(filterCode.toLowerCase())); if (filtered.length > 0) { acc[file] = filtered; } return acc; }, {} as Record<string, TypeScriptError[]>) : errorsByFile; // Get unique error codes for filter suggestions const errorCodes = [...new Set(tsResult?.errors.map(e => e.code) || [])].sort(); return ( <div className="max-w-[1170px] mx-auto px-4 sm:px-7.5 xl:px-0"> {/* Breadcrumb */} <nav className="mb-4"> <ol className="flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400"> <li><Link href="/admin/dev-tools" className="hover:text-blue">Developer Tools</Link></li> <li>/</li> <li className="text-dark dark:text-gray-100 font-medium">TypeScript Checker</li> </ol> </nav> <div className="mb-8"> <h1 className="text-2xl font-bold text-dark dark:text-gray-100">TypeScript Checker</h1> <p className="text-gray-600 dark:text-gray-400 mt-1"> Run type checking and view TypeScript errors </p> </div> {/* Controls */} <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 mb-6"> <h2 className="font-semibold text-lg text-dark dark:text-gray-100 mb-4">Run Type Check</h2> <div className="flex gap-2"> {status.status === 'running' ? ( <button onClick={stopCheck} className="px-4 py-2 bg-red-500 text-white rounded-md text-sm font-medium hover:bg-red-600 transition-colors" > Stop Check </button> ) : ( <button onClick={runCheck} disabled={isStarting} className="px-4 py-2 bg-blue text-white rounded-md text-sm font-medium hover:bg-blue/90 transition-colors disabled:opacity-50" > {isStarting ? 'Starting...' : 'Run Type Check'} </button> )} </div> </div> {/* Status */} {status.status !== 'idle' && ( <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 mb-6"> <div className="flex items-center justify-between mb-4"> <h2 className="font-semibold text-lg text-dark dark:text-gray-100">Results</h2> <span className={`px-3 py-1 rounded-full text-sm font-medium ${ status.status === 'running' ? 'bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300' : status.status === 'completed' ? 'bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300' : 'bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300' }`}> {status.status === 'running' ? 'Running...' : status.status === 'completed' ? 'No Errors' : 'Errors Found'} </span> </div> {/* Summary */} {tsResult && ( <div className="grid grid-cols-2 md:grid-cols-3 gap-4 mb-6"> <div className="bg-gray-50 dark:bg-gray-700 rounded-lg p-4"> <div className="text-2xl font-bold text-red-600 dark:text-red-400">{tsResult.errorCount}</div> <div className="text-sm text-gray-600 dark:text-gray-400">Total Errors</div> </div> <div className="bg-gray-50 dark:bg-gray-700 rounded-lg p-4"> <div className="text-2xl font-bold text-dark dark:text-gray-100">{Object.keys(errorsByFile).length}</div> <div className="text-sm text-gray-600 dark:text-gray-400">Files with Errors</div> </div> <div className="bg-gray-50 dark:bg-gray-700 rounded-lg p-4"> <div className="text-2xl font-bold text-blue-600 dark:text-blue-400">{errorCodes.length}</div> <div className="text-sm text-gray-600 dark:text-gray-400">Unique Error Codes</div> </div> </div> )} {/* Filter */} {tsResult && tsResult.errors.length > 0 && ( <div className="mb-6"> <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"> Filter by Error Code </label> <div className="flex gap-2 flex-wrap"> <input type="text" value={filterCode} onChange={(e) => setFilterCode(e.target.value)} placeholder="e.g., TS2345" className="px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-blue focus:border-transparent placeholder:text-gray-400 dark:placeholder:text-gray-500" /> {filterCode && ( <button onClick={() => setFilterCode('')} className="px-3 py-2 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200" > Clear </button> )} </div> <div className="mt-2 flex flex-wrap gap-1"> {errorCodes.slice(0, 10).map(code => ( <button key={code} onClick={() => setFilterCode(code)} className={`px-2 py-1 text-xs rounded ${ filterCode === code ? 'bg-blue text-white' : 'bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-600' }`} > {code} </button> ))} {errorCodes.length > 10 && ( <span className="text-xs text-gray-500 dark:text-gray-400 px-2 py-1"> +{errorCodes.length - 10} more </span> )} </div> </div> )} {/* Errors by File */} {Object.keys(filteredErrorsByFile).length > 0 && ( <div className="mb-6"> <h3 className="font-medium text-dark dark:text-gray-100 mb-3"> Errors by File {filterCode && ` (filtered: ${filterCode})`} </h3> <div className="space-y-4"> {Object.entries(filteredErrorsByFile).map(([file, errors]) => ( <div key={file} className="border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden"> <div className="px-4 py-3 bg-gray-50 dark:bg-gray-700 font-mono text-sm text-dark dark:text-gray-100 truncate"> {file} <span className="ml-2 text-xs text-gray-500 dark:text-gray-400">({errors.length} errors)</span> </div> <div className="divide-y divide-gray-100 dark:divide-gray-700"> {errors.map((error, idx) => ( <div key={idx} className="px-4 py-3"> <div className="flex items-start gap-3"> <span className="font-mono text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap"> {error.line}:{error.column} </span> <span className="px-2 py-0.5 bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 text-xs rounded font-mono"> {error.code} </span> <span className="text-sm text-gray-700 dark:text-gray-300 flex-1">{error.message}</span> </div> </div> ))} </div> </div> ))} </div> </div> )} {/* Raw Output */} {status.output && ( <div> <h3 className="font-medium text-dark dark:text-gray-100 mb-3">Raw Output</h3> <pre className="bg-gray-900 text-gray-100 rounded-lg p-4 overflow-x-auto text-sm max-h-96 overflow-y-auto"> {status.output} </pre> </div> )} </div> )} </div> ); } |