Skip to content

Commit 5b597c8

Browse files
authored
refactor: migrate isDark conditionals to Tailwind CSS dark prefix across workflow components (iflabx#232)
1 parent 5d1a3bb commit 5b597c8

7 files changed

Lines changed: 91 additions & 128 deletions

File tree

components/text-generation/text-generation-layout.tsx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { useMobile } from '@lib/hooks/use-mobile';
1111
import { useTextGenerationExecution } from '@lib/hooks/use-text-generation-execution';
1212
import { useWorkflowHistoryStore } from '@lib/stores/workflow-history-store';
13+
import type { AppExecution } from '@lib/types/database';
1314
import { cn } from '@lib/utils';
1415
import { AlertCircle, RefreshCw, X } from 'lucide-react';
1516

@@ -62,23 +63,24 @@ export function TextGenerationLayout({
6263

6364
// --- Result viewer state ---
6465
const [showResultViewer, setShowResultViewer] = useState(false);
65-
const [viewerResult, setViewerResult] = useState<any>(null);
66-
const [viewerExecution, setViewerExecution] = useState<any>(null);
66+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic result data structure
67+
const [viewerResult, setViewerResult] = useState<Record<string, any> | null>(
68+
null
69+
);
70+
const [viewerExecution, setViewerExecution] = useState<AppExecution | null>(
71+
null
72+
);
6773

6874
// --- Form reset reference ---
6975
const formResetRef = useRef<WorkflowInputFormRef>(null);
7076

7177
// --- Text generation execution callback ---
7278
const handleExecuteTextGeneration = useCallback(
79+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic form data structure
7380
async (formData: Record<string, any>) => {
74-
console.log(
75-
'[Text generation layout] Start executing text generation, input data:',
76-
formData
77-
);
78-
7981
try {
8082
await executeTextGeneration(formData);
81-
} catch (error) {
83+
} catch (error: unknown) {
8284
console.error('[Text generation layout] Execution failed:', error);
8385
}
8486
},
@@ -120,22 +122,19 @@ export function TextGenerationLayout({
120122

121123
// --- Clear error ---
122124
const handleClearError = useCallback(() => {
123-
console.log('[Text generation layout] Clear error');
124125
// Here you can add the logic to clear the error
125126
}, []);
126127

127-
// --- Node status update callback (text generation does not need it, but keep the interface consistent) ---
128-
const handleNodeUpdate = useCallback((event: any) => {
129-
console.log('[Text generation layout] Node update:', event);
130-
}, []);
131-
132128
// --- View result callback ---
133-
const handleViewResult = useCallback((result: any, execution: any) => {
134-
console.log('[Text generation layout] View result:', result, execution);
135-
setViewerResult(result);
136-
setViewerExecution(execution);
137-
setShowResultViewer(true);
138-
}, []);
129+
const handleViewResult = useCallback(
130+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic result data structure
131+
(result: Record<string, any>, execution: AppExecution) => {
132+
setViewerResult(result);
133+
setViewerExecution(execution);
134+
setShowResultViewer(true);
135+
},
136+
[]
137+
);
139138

140139
// --- Close result viewer ---
141140
const handleCloseResultViewer = useCallback(() => {
@@ -211,7 +210,6 @@ export function TextGenerationLayout({
211210
<MobileTabSwitcher
212211
activeTab={mobileActiveTab}
213212
onTabChange={setMobileActiveTab}
214-
hasHistory={showHistory}
215213
/>
216214

217215
{/* Content area */}

components/text-generation/text-generation-result-viewer.tsx

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
DateFormatPresets,
1212
useDateFormatter,
1313
} from '@lib/hooks/use-date-formatter';
14-
import { useTheme } from '@lib/hooks/use-theme';
1514
import { cn } from '@lib/utils';
1615
import 'katex/dist/katex.min.css';
1716
import { Check, Copy, Download, X } from 'lucide-react';
@@ -26,7 +25,9 @@ import React, { useEffect, useState } from 'react';
2625
import { useTranslations } from 'next-intl';
2726

2827
interface TextGenerationResultViewerProps {
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic result data structure from API
2929
result: any;
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic execution data structure from API
3031
execution: any;
3132
onClose: () => void;
3233
}
@@ -42,7 +43,6 @@ export function TextGenerationResultViewer({
4243
execution,
4344
onClose,
4445
}: TextGenerationResultViewerProps) {
45-
const { isDark } = useTheme();
4646
const { formatDate } = useDateFormatter();
4747
const t = useTranslations('components.text-generation.resultViewer');
4848
const [isVisible, setIsVisible] = useState(false);
@@ -56,6 +56,7 @@ export function TextGenerationResultViewer({
5656

5757
// --- Reuse the Markdown component configuration of the assistant message ---
5858
const markdownComponents: Components = {
59+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars -- React markdown component props pattern
5960
code({ node, className, children, ...props }: any) {
6061
const match = /language-(\w+)/.exec(className || '');
6162
const language = match ? match[1] : '';
@@ -70,61 +71,71 @@ export function TextGenerationResultViewer({
7071

7172
return <InlineCode {...props}>{children}</InlineCode>;
7273
},
74+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars -- React markdown component props pattern
7375
table({ children, ...props }: any) {
7476
return <MarkdownTableContainer>{children}</MarkdownTableContainer>;
7577
},
78+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars -- React markdown component props pattern
7679
blockquote({ children, ...props }: any) {
7780
return <MarkdownBlockquote>{children}</MarkdownBlockquote>;
7881
},
82+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
7983
p({ children, ...props }: any) {
8084
return (
8185
<p className="font-serif" {...props}>
8286
{children}
8387
</p>
8488
);
8589
},
90+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
8691
h1({ children, ...props }: any) {
8792
return (
8893
<h1 className="font-serif" {...props}>
8994
{children}
9095
</h1>
9196
);
9297
},
98+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
9399
h2({ children, ...props }: any) {
94100
return (
95101
<h2 className="font-serif" {...props}>
96102
{children}
97103
</h2>
98104
);
99105
},
106+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
100107
h3({ children, ...props }: any) {
101108
return (
102109
<h3 className="font-serif" {...props}>
103110
{children}
104111
</h3>
105112
);
106113
},
114+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
107115
h4({ children, ...props }: any) {
108116
return (
109117
<h4 className="font-serif" {...props}>
110118
{children}
111119
</h4>
112120
);
113121
},
122+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
114123
ul({ children, ...props }: any) {
115124
return (
116125
<ul className="font-serif" {...props}>
117126
{children}
118127
</ul>
119128
);
120129
},
130+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
121131
ol({ children, ...props }: any) {
122132
return (
123133
<ol className="font-serif" {...props}>
124134
{children}
125135
</ol>
126136
);
127137
},
138+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- React markdown component props pattern
128139
li({ children, ...props }: any) {
129140
return (
130141
<li className="font-serif" {...props}>
@@ -135,6 +146,7 @@ export function TextGenerationResultViewer({
135146
};
136147

137148
// --- Format content ---
149+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic API response structure
138150
const formatContent = (data: any): string => {
139151
// If the result contains the generated text content
140152
if (typeof data === 'string') {
@@ -159,6 +171,7 @@ export function TextGenerationResultViewer({
159171
};
160172

161173
// --- Extract text content from an object ---
174+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic API response object structure
162175
const extractTextFromObject = (obj: any): string => {
163176
// First look for the generated_text field (the main output of text generation)
164177
if (obj.generated_text && typeof obj.generated_text === 'string') {
@@ -251,32 +264,30 @@ export function TextGenerationResultViewer({
251264
<div
252265
className={cn(
253266
'max-h-full w-full max-w-4xl overflow-hidden rounded-2xl shadow-2xl transition-all duration-300',
254-
isDark
255-
? 'border border-stone-700 bg-stone-900'
256-
: 'border border-stone-200 bg-white',
267+
'border border-stone-200 bg-white dark:border-stone-700 dark:bg-stone-900',
257268
isVisible ? 'animate-scale-in' : 'scale-95 opacity-0'
258269
)}
259270
>
260271
{/* Header */}
261272
<div
262273
className={cn(
263274
'flex items-center justify-between border-b p-6',
264-
isDark ? 'border-stone-700' : 'border-stone-200'
275+
'border-stone-200 dark:border-stone-700'
265276
)}
266277
>
267278
<div>
268279
<h2
269280
className={cn(
270281
'font-serif text-xl font-bold',
271-
isDark ? 'text-stone-100' : 'text-stone-900'
282+
'text-stone-900 dark:text-stone-100'
272283
)}
273284
>
274285
{t('title')}
275286
</h2>
276287
<p
277288
className={cn(
278289
'mt-1 font-serif text-sm',
279-
isDark ? 'text-stone-400' : 'text-stone-600'
290+
'text-stone-600 dark:text-stone-400'
280291
)}
281292
>
282293
{execution?.title || t('defaultTitle')}
@@ -297,9 +308,7 @@ export function TextGenerationResultViewer({
297308
onClick={handleCopy}
298309
className={cn(
299310
'flex items-center justify-center rounded-lg p-2 transition-colors',
300-
isDark ? 'text-stone-400' : 'text-stone-500',
301-
isDark ? 'hover:text-stone-300' : 'hover:text-stone-700',
302-
isDark ? 'hover:bg-stone-600/40' : 'hover:bg-stone-300/40',
311+
'text-stone-500 hover:bg-stone-300/40 hover:text-stone-700 dark:text-stone-400 dark:hover:bg-stone-600/40 dark:hover:text-stone-300',
303312
'focus:outline-none'
304313
)}
305314
style={{ transform: 'translateZ(0)' }}
@@ -328,9 +337,7 @@ export function TextGenerationResultViewer({
328337
onClick={handleDownload}
329338
className={cn(
330339
'rounded-lg p-2 transition-colors',
331-
isDark
332-
? 'text-stone-400 hover:bg-stone-700 hover:text-stone-300'
333-
: 'text-stone-600 hover:bg-stone-100 hover:text-stone-700'
340+
'text-stone-600 hover:bg-stone-100 hover:text-stone-700 dark:text-stone-400 dark:hover:bg-stone-700 dark:hover:text-stone-300'
334341
)}
335342
aria-label={t('actions.download')}
336343
>
@@ -343,9 +350,7 @@ export function TextGenerationResultViewer({
343350
onClick={onClose}
344351
className={cn(
345352
'rounded-lg p-2 transition-colors',
346-
isDark
347-
? 'text-stone-400 hover:bg-stone-700 hover:text-stone-300'
348-
: 'text-stone-600 hover:bg-stone-100 hover:text-stone-700'
353+
'text-stone-600 hover:bg-stone-100 hover:text-stone-700 dark:text-stone-400 dark:hover:bg-stone-700 dark:hover:text-stone-300'
349354
)}
350355
>
351356
<X className="h-4 w-4" />
@@ -361,15 +366,13 @@ export function TextGenerationResultViewer({
361366
<div
362367
className={cn(
363368
'rounded-lg border p-4',
364-
isDark
365-
? 'border-stone-700 bg-stone-800/50'
366-
: 'border-stone-200 bg-stone-50'
369+
'border-stone-200 bg-stone-50 dark:border-stone-700 dark:bg-stone-800/50'
367370
)}
368371
>
369372
<h3
370373
className={cn(
371374
'mb-2 font-serif text-sm font-semibold',
372-
isDark ? 'text-stone-200' : 'text-stone-800'
375+
'text-stone-800 dark:text-stone-200'
373376
)}
374377
>
375378
{t('executionInfo.title')}
@@ -379,7 +382,7 @@ export function TextGenerationResultViewer({
379382
<span
380383
className={cn(
381384
'font-medium',
382-
isDark ? 'text-stone-300' : 'text-stone-700'
385+
'text-stone-700 dark:text-stone-300'
383386
)}
384387
>
385388
{t('executionInfo.status')}
@@ -388,11 +391,11 @@ export function TextGenerationResultViewer({
388391
className={cn(
389392
'ml-2',
390393
execution.status === 'completed' &&
391-
(isDark ? 'text-green-400' : 'text-green-600'),
394+
'text-green-600 dark:text-green-400',
392395
execution.status === 'failed' &&
393-
(isDark ? 'text-red-400' : 'text-red-600'),
396+
'text-red-600 dark:text-red-400',
394397
execution.status === 'stopped' &&
395-
(isDark ? 'text-yellow-400' : 'text-yellow-600')
398+
'text-yellow-600 dark:text-yellow-400'
396399
)}
397400
>
398401
{execution.status === 'completed'
@@ -409,15 +412,15 @@ export function TextGenerationResultViewer({
409412
<span
410413
className={cn(
411414
'font-medium',
412-
isDark ? 'text-stone-300' : 'text-stone-700'
415+
'text-stone-700 dark:text-stone-300'
413416
)}
414417
>
415418
{t('executionInfo.createdAt')}
416419
</span>
417420
<span
418421
className={cn(
419422
'ml-2',
420-
isDark ? 'text-stone-400' : 'text-stone-600'
423+
'text-stone-600 dark:text-stone-400'
421424
)}
422425
>
423426
{formatDate(
@@ -432,15 +435,15 @@ export function TextGenerationResultViewer({
432435
<span
433436
className={cn(
434437
'font-medium',
435-
isDark ? 'text-stone-300' : 'text-stone-700'
438+
'text-stone-700 dark:text-stone-300'
436439
)}
437440
>
438441
{t('executionInfo.elapsedTime')}
439442
</span>
440443
<span
441444
className={cn(
442445
'ml-2',
443-
isDark ? 'text-stone-400' : 'text-stone-600'
446+
'text-stone-600 dark:text-stone-400'
444447
)}
445448
>
446449
{execution.elapsed_time}s
@@ -456,17 +459,15 @@ export function TextGenerationResultViewer({
456459
<h3
457460
className={cn(
458461
'mb-3 font-serif text-sm font-semibold',
459-
isDark ? 'text-stone-200' : 'text-stone-800'
462+
'text-stone-800 dark:text-stone-200'
460463
)}
461464
>
462465
{t('content.title')}
463466
</h3>
464467
<div
465468
className={cn(
466469
'assistant-message-content rounded-lg border p-4 font-serif',
467-
isDark
468-
? 'border-stone-700 bg-stone-800 text-stone-200'
469-
: 'border-stone-200 bg-white text-stone-900'
470+
'border-stone-200 bg-white text-stone-900 dark:border-stone-700 dark:bg-stone-800 dark:text-stone-200'
470471
)}
471472
>
472473
<ReactMarkdown

0 commit comments

Comments
 (0)