Skip to content

Commit e0caca3

Browse files
Copilotlyzno1
andauthored
refactor: replace isDark conditional logic with Tailwind dark: prefix across codebase (iflabx#228)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com>
1 parent b178fa1 commit e0caca3

7 files changed

Lines changed: 25 additions & 198 deletions

File tree

app/forgot-password/page.tsx

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,11 @@
11
'use client';
22

33
import { ForgotPasswordForm } from '@components/auth/forgot-password-form';
4-
import { useTheme } from '@lib/hooks/use-theme';
54
import { motion } from 'framer-motion';
65

7-
import { useEffect, useState } from 'react';
8-
96
export default function ForgotPasswordPage() {
10-
const { isDark } = useTheme();
11-
const [mounted, setMounted] = useState(false);
12-
13-
// ensure client-side rendering consistency
14-
useEffect(() => {
15-
setMounted(true);
16-
}, []);
17-
18-
// get colors based on theme
19-
const getColors = () => {
20-
if (isDark) {
21-
return {
22-
bgColor: 'bg-stone-800',
23-
};
24-
} else {
25-
return {
26-
bgColor: 'bg-stone-100',
27-
};
28-
}
29-
};
30-
31-
const colors = mounted
32-
? getColors()
33-
: {
34-
bgColor: '',
35-
};
36-
377
return (
38-
<main
39-
className={`flex min-h-screen w-full flex-col items-center justify-center gap-4 px-4 py-12 sm:px-6 lg:px-8 ${colors.bgColor} font-serif`}
40-
>
8+
<main className="flex min-h-screen w-full flex-col items-center justify-center gap-4 bg-stone-100 px-4 py-12 font-serif sm:px-6 lg:px-8 dark:bg-stone-800">
419
<motion.div
4210
initial={{ opacity: 0, y: 20 }}
4311
animate={{ opacity: 1, y: 0 }}

app/login/page.tsx

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
'use client';
22

33
import { LoginForm } from '@components/auth/login-form';
4-
import { useTheme } from '@lib/hooks/use-theme';
54
import { motion } from 'framer-motion';
65
import { AlertTriangle, CheckCircle } from 'lucide-react';
76

8-
import { useEffect, useState } from 'react';
9-
107
import { useTranslations } from 'next-intl';
118
import { useSearchParams } from 'next/navigation';
129

@@ -17,57 +14,7 @@ export default function LoginPage() {
1714
const registered = searchParams.get('registered');
1815
const resetSuccess = searchParams.get('reset');
1916
const oauthError = searchParams.get('error');
20-
const { isDark } = useTheme();
2117
const t = useTranslations('pages.auth.login');
22-
const [mounted, setMounted] = useState(false);
23-
24-
// ensure client-side rendering consistency
25-
useEffect(() => {
26-
setMounted(true);
27-
}, []);
28-
29-
// get colors based on theme
30-
const getColors = () => {
31-
if (isDark) {
32-
return {
33-
bgColor: 'bg-stone-800',
34-
alertBg: 'bg-stone-800/50',
35-
alertBorder: 'border-stone-600',
36-
alertText: 'text-stone-300',
37-
iconColor: 'text-stone-400',
38-
errorAlertBg: 'bg-red-900/30',
39-
errorAlertBorder: 'border-red-500',
40-
errorAlertText: 'text-red-400',
41-
errorIconColor: 'text-red-400',
42-
};
43-
} else {
44-
return {
45-
bgColor: 'bg-stone-100',
46-
alertBg: 'bg-stone-50',
47-
alertBorder: 'border-stone-300',
48-
alertText: 'text-stone-700',
49-
iconColor: 'text-stone-600',
50-
errorAlertBg: 'bg-red-50',
51-
errorAlertBorder: 'border-red-500',
52-
errorAlertText: 'text-red-700',
53-
errorIconColor: 'text-red-500',
54-
};
55-
}
56-
};
57-
58-
const colors = mounted
59-
? getColors()
60-
: {
61-
bgColor: '',
62-
alertBg: '',
63-
alertBorder: '',
64-
alertText: '',
65-
iconColor: '',
66-
errorAlertBg: '',
67-
errorAlertBorder: '',
68-
errorAlertText: '',
69-
errorIconColor: '',
70-
};
7118

7219
// get error message
7320
const getErrorMessage = (error: string) => {
@@ -96,20 +43,16 @@ export default function LoginPage() {
9643
};
9744

9845
return (
99-
<main
100-
className={`flex min-h-screen w-full flex-col items-center justify-center gap-4 px-4 py-12 sm:px-6 lg:px-8 ${colors.bgColor} font-serif`}
101-
>
46+
<main className="flex min-h-screen w-full flex-col items-center justify-center gap-4 bg-stone-100 px-4 py-12 font-serif sm:px-6 lg:px-8 dark:bg-stone-800">
10247
{registered && (
10348
<motion.div
10449
initial={{ opacity: 0, y: -20 }}
10550
animate={{ opacity: 1, y: 0 }}
10651
transition={{ duration: 0.6 }}
10752
>
108-
<Alert
109-
className={`max-w-md border-l-4 ${colors.alertBg} ${colors.alertBorder}`}
110-
>
111-
<CheckCircle className={`h-4 w-4 ${colors.iconColor}`} />
112-
<AlertDescription className={`${colors.alertText} font-serif`}>
53+
<Alert className="max-w-md border-l-4 border-stone-300 bg-stone-50 dark:border-stone-600 dark:bg-stone-800/50">
54+
<CheckCircle className="h-4 w-4 text-stone-600 dark:text-stone-400" />
55+
<AlertDescription className="font-serif text-stone-700 dark:text-stone-300">
11356
{t('alerts.registered')}
11457
</AlertDescription>
11558
</Alert>
@@ -121,11 +64,9 @@ export default function LoginPage() {
12164
animate={{ opacity: 1, y: 0 }}
12265
transition={{ duration: 0.6 }}
12366
>
124-
<Alert
125-
className={`max-w-md border-l-4 ${colors.alertBg} ${colors.alertBorder}`}
126-
>
127-
<CheckCircle className={`h-4 w-4 ${colors.iconColor}`} />
128-
<AlertDescription className={`${colors.alertText} font-serif`}>
67+
<Alert className="max-w-md border-l-4 border-stone-300 bg-stone-50 dark:border-stone-600 dark:bg-stone-800/50">
68+
<CheckCircle className="h-4 w-4 text-stone-600 dark:text-stone-400" />
69+
<AlertDescription className="font-serif text-stone-700 dark:text-stone-300">
12970
{t('alerts.resetSuccess')}
13071
</AlertDescription>
13172
</Alert>
@@ -137,11 +78,9 @@ export default function LoginPage() {
13778
animate={{ opacity: 1, y: 0 }}
13879
transition={{ duration: 0.6 }}
13980
>
140-
<Alert
141-
className={`max-w-md border-l-4 ${colors.errorAlertBg} ${colors.errorAlertBorder}`}
142-
>
143-
<AlertTriangle className={`h-4 w-4 ${colors.errorIconColor}`} />
144-
<AlertDescription className={`${colors.errorAlertText} font-serif`}>
81+
<Alert className="max-w-md border-l-4 border-red-500 bg-red-50 dark:border-red-500 dark:bg-red-900/30">
82+
<AlertTriangle className="h-4 w-4 text-red-500 dark:text-red-400" />
83+
<AlertDescription className="font-serif text-red-700 dark:text-red-400">
14584
{getErrorMessage(oauthError)}
14685
</AlertDescription>
14786
</Alert>

app/register/page.tsx

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,11 @@
11
'use client';
22

33
import { RegisterForm } from '@components/auth/register-form';
4-
import { useTheme } from '@lib/hooks/use-theme';
54
import { motion } from 'framer-motion';
65

7-
import { useEffect, useState } from 'react';
8-
96
export default function RegisterPage() {
10-
const { isDark } = useTheme();
11-
const [mounted, setMounted] = useState(false);
12-
13-
// ensure client-side rendering consistency
14-
useEffect(() => {
15-
setMounted(true);
16-
}, []);
17-
18-
// get colors based on theme
19-
const getColors = () => {
20-
if (isDark) {
21-
return {
22-
bgColor: 'bg-stone-800',
23-
};
24-
} else {
25-
return {
26-
bgColor: 'bg-stone-100',
27-
};
28-
}
29-
};
30-
31-
const colors = mounted
32-
? getColors()
33-
: {
34-
bgColor: '',
35-
};
36-
377
return (
38-
<main
39-
className={`flex min-h-screen w-full flex-col items-center justify-center px-4 py-12 sm:px-6 lg:px-8 ${colors.bgColor} font-serif`}
40-
>
8+
<main className="flex min-h-screen w-full flex-col items-center justify-center bg-stone-100 px-4 py-12 font-serif sm:px-6 lg:px-8 dark:bg-stone-800">
419
<motion.div
4210
initial={{ opacity: 0, y: 20 }}
4311
animate={{ opacity: 1, y: 0 }}

app/reset-password/page.tsx

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use client';
22

33
import { ResetPasswordForm } from '@components/auth/reset-password-form';
4-
import { useTheme } from '@lib/hooks/use-theme';
54
import { cn } from '@lib/utils';
65
import { motion } from 'framer-motion';
76

8-
import { Suspense, useEffect, useState } from 'react';
7+
import { Suspense } from 'react';
98

109
import { useTranslations } from 'next-intl';
1110

@@ -14,38 +13,10 @@ function ResetPasswordContent() {
1413
}
1514

1615
export default function ResetPasswordPage() {
17-
const { isDark } = useTheme();
1816
const t = useTranslations('loading');
19-
const [mounted, setMounted] = useState(false);
20-
21-
// ensure client-side rendering consistency
22-
useEffect(() => {
23-
setMounted(true);
24-
}, []);
25-
26-
// get colors based on theme
27-
const getColors = () => {
28-
if (isDark) {
29-
return {
30-
bgColor: 'bg-stone-800',
31-
};
32-
} else {
33-
return {
34-
bgColor: 'bg-stone-100',
35-
};
36-
}
37-
};
38-
39-
const colors = mounted
40-
? getColors()
41-
: {
42-
bgColor: '',
43-
};
4417

4518
return (
46-
<main
47-
className={`flex min-h-screen w-full flex-col items-center justify-center gap-4 px-4 py-12 sm:px-6 lg:px-8 ${colors.bgColor} font-serif`}
48-
>
19+
<main className="flex min-h-screen w-full flex-col items-center justify-center gap-4 bg-stone-100 px-4 py-12 font-serif sm:px-6 lg:px-8 dark:bg-stone-800">
4920
<motion.div
5021
initial={{ opacity: 0, y: 20 }}
5122
animate={{ opacity: 1, y: 0 }}
@@ -57,22 +28,21 @@ export default function ResetPasswordPage() {
5728
<div
5829
className={cn(
5930
'w-full max-w-md space-y-6 rounded-xl border p-6 font-serif shadow-lg transition-all sm:space-y-8 sm:p-8',
60-
isDark
61-
? 'border-stone-800 bg-stone-900'
62-
: 'border-stone-200 bg-stone-50'
31+
'border-stone-200 bg-stone-50',
32+
'dark:border-stone-800 dark:bg-stone-900'
6333
)}
6434
>
6535
<div className="text-center">
6636
<div
6737
className={cn(
6838
'mx-auto mb-4 flex h-16 w-16 animate-pulse items-center justify-center rounded-full',
69-
isDark ? 'bg-stone-800' : 'bg-stone-100'
39+
'bg-stone-100 dark:bg-stone-800'
7040
)}
7141
>
7242
<div
7343
className={cn(
7444
'h-8 w-8 rounded-full',
75-
isDark ? 'bg-stone-600' : 'bg-stone-300'
45+
'bg-stone-300 dark:bg-stone-600'
7646
)}
7747
></div>
7848
</div>

components/chat/messages-loading-indicator.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Message loading indicator component
33
*/
44
import { LoadingState } from '@lib/hooks/use-conversation-messages';
5-
import { useThemeColors } from '@lib/hooks/use-theme-colors';
65
import { cn } from '@lib/utils';
76

87
import { useEffect, useRef, useState } from 'react';
@@ -24,7 +23,6 @@ export function MessagesLoadingIndicator({
2423
error,
2524
onRetry,
2625
}: MessagesLoadingIndicatorProps) {
27-
const { colors } = useThemeColors();
2826
const t = useTranslations('loading');
2927
const [isAtTop, setIsAtTop] = useState(false);
3028

@@ -96,8 +94,8 @@ export function MessagesLoadingIndicator({
9694
onClick={onRetry}
9795
className={cn(
9896
'rounded-full px-4 py-2 text-sm',
99-
colors.sidebarBackground.tailwind,
100-
colors.buttonHover.tailwind
97+
'bg-stone-100 text-stone-700 hover:bg-stone-200',
98+
'dark:bg-stone-800 dark:text-stone-300 dark:hover:bg-stone-700'
10199
)}
102100
>
103101
{t('retry')}
@@ -113,7 +111,7 @@ export function MessagesLoadingIndicator({
113111
<div
114112
className={cn(
115113
'flex items-center space-x-2 rounded-full px-4 py-2',
116-
colors.sidebarBackground.tailwind
114+
'bg-stone-100 dark:bg-stone-800'
117115
)}
118116
>
119117
<LoadingSpinner />
@@ -131,8 +129,8 @@ export function MessagesLoadingIndicator({
131129
onClick={onRetry}
132130
className={cn(
133131
'rounded-full px-4 py-2 text-sm',
134-
colors.sidebarBackground.tailwind,
135-
colors.buttonHover.tailwind,
132+
'bg-stone-100 text-stone-700 hover:bg-stone-200',
133+
'dark:bg-stone-800 dark:text-stone-300 dark:hover:bg-stone-700',
136134
'transition-colors duration-200'
137135
)}
138136
>

components/ui/message-action-button.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client';
22

3-
import { useTheme } from '@lib/hooks';
43
import { cn } from '@lib/utils';
54
import { IconType } from 'react-icons';
65

@@ -35,7 +34,6 @@ export const MessageActionButton: React.FC<MessageActionButtonProps> = ({
3534
tooltipSize = 'sm', // message-actions default use small size
3635
showTooltipArrow = false, // message-actions default do not show arrow
3736
}) => {
38-
const { isDark } = useTheme();
3937
// Use the external active property to control the state, instead of the internal state
4038
// The current displayed icon and label
4139
// If the button is active and an active icon is provided, use the active icon
@@ -62,9 +60,8 @@ export const MessageActionButton: React.FC<MessageActionButtonProps> = ({
6260
'flex items-center justify-center rounded-md p-1.5 transition-all',
6361
'text-sm',
6462
// Button style, do not change background when active
65-
isDark
66-
? 'text-gray-400 hover:bg-gray-700/50 hover:text-gray-200'
67-
: 'text-gray-500 hover:bg-gray-200/50 hover:text-gray-700',
63+
'text-gray-500 hover:bg-gray-200/50 hover:text-gray-700',
64+
'dark:text-gray-400 dark:hover:bg-gray-700/50 dark:hover:text-gray-200',
6865
// Keep the original color when active, do not use blue
6966
disabled && 'cursor-not-allowed opacity-50 hover:bg-transparent',
7067
className

0 commit comments

Comments
 (0)