@@ -4,6 +4,7 @@ import { useState, useEffect, useRef } from "react"
4
4
import { Loader2 } from "lucide-react"
5
5
import { RadioGroup , RadioGroupItem } from "@/components/ui/radio-group"
6
6
import { Label } from "@/components/ui/label"
7
+ import { useTheme } from "next-themes"
7
8
8
9
interface Message {
9
10
id : string
@@ -27,6 +28,7 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
27
28
const [ loading , setLoading ] = useState ( true )
28
29
const [ viewMode , setViewMode ] = useState < ViewMode > ( "html" )
29
30
const iframeRef = useRef < HTMLIFrameElement > ( null )
31
+ const { theme } = useTheme ( )
30
32
31
33
useEffect ( ( ) => {
32
34
const fetchMessage = async ( ) => {
@@ -47,8 +49,7 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
47
49
fetchMessage ( )
48
50
} , [ emailId , messageId ] )
49
51
50
- // 处理 iframe 内容
51
- useEffect ( ( ) => {
52
+ const updateIframeContent = ( ) => {
52
53
if ( viewMode === "html" && message ?. html && iframeRef . current ) {
53
54
const iframe = iframeRef . current
54
55
const doc = iframe . contentDocument || iframe . contentWindow ?. document
@@ -66,8 +67,8 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
66
67
padding: 0;
67
68
min-height: 100%;
68
69
font-family: system-ui, -apple-system, sans-serif;
69
- color: ${ document . documentElement . classList . contains ( 'dark' ) ? '#fff' : '#000' } ;
70
- background: transparent ;
70
+ color: ${ theme === 'dark' ? '#fff' : '#000' } ;
71
+ background: ${ theme === 'dark' ? '#1a1a1a' : '#fff' } ;
71
72
}
72
73
body {
73
74
padding: 20px;
@@ -88,21 +89,21 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
88
89
background: transparent;
89
90
}
90
91
::-webkit-scrollbar-thumb {
91
- background: ${ document . documentElement . classList . contains ( 'dark' )
92
- ? 'rgba(130, 109, 217, 0.3)'
92
+ background: ${ theme === 'dark'
93
+ ? 'rgba(130, 109, 217, 0.3)'
93
94
: 'rgba(130, 109, 217, 0.2)' } ;
94
95
border-radius: 9999px;
95
96
transition: background-color 0.2s;
96
97
}
97
98
::-webkit-scrollbar-thumb:hover {
98
- background: ${ document . documentElement . classList . contains ( 'dark' )
99
+ background: ${ theme === 'dark'
99
100
? 'rgba(130, 109, 217, 0.5)'
100
101
: 'rgba(130, 109, 217, 0.4)' } ;
101
102
}
102
103
/* Firefox 滚动条 */
103
104
* {
104
105
scrollbar-width: thin;
105
- scrollbar-color: ${ document . documentElement . classList . contains ( 'dark' )
106
+ scrollbar-color: ${ theme === 'dark'
106
107
? 'rgba(130, 109, 217, 0.3) transparent'
107
108
: 'rgba(130, 109, 217, 0.2) transparent' } ;
108
109
}
@@ -139,7 +140,12 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
139
140
}
140
141
}
141
142
}
142
- } , [ message ?. html , viewMode ] )
143
+ }
144
+
145
+ // 监听主题变化和内容变化
146
+ useEffect ( ( ) => {
147
+ updateIframeContent ( )
148
+ } , [ message ?. html , viewMode , theme ] )
143
149
144
150
if ( loading ) {
145
151
return (
0 commit comments