Skip to content

Commit f5d4979

Browse files
committed
feat: integrate theme support in message view for improved styling
1 parent 6ddd5bd commit f5d4979

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

app/components/emails/message-view.tsx

+15-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useState, useEffect, useRef } from "react"
44
import { Loader2 } from "lucide-react"
55
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
66
import { Label } from "@/components/ui/label"
7+
import { useTheme } from "next-themes"
78

89
interface Message {
910
id: string
@@ -27,6 +28,7 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
2728
const [loading, setLoading] = useState(true)
2829
const [viewMode, setViewMode] = useState<ViewMode>("html")
2930
const iframeRef = useRef<HTMLIFrameElement>(null)
31+
const { theme } = useTheme()
3032

3133
useEffect(() => {
3234
const fetchMessage = async () => {
@@ -47,8 +49,7 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
4749
fetchMessage()
4850
}, [emailId, messageId])
4951

50-
// 处理 iframe 内容
51-
useEffect(() => {
52+
const updateIframeContent = () => {
5253
if (viewMode === "html" && message?.html && iframeRef.current) {
5354
const iframe = iframeRef.current
5455
const doc = iframe.contentDocument || iframe.contentWindow?.document
@@ -66,8 +67,8 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
6667
padding: 0;
6768
min-height: 100%;
6869
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'};
7172
}
7273
body {
7374
padding: 20px;
@@ -88,21 +89,21 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
8889
background: transparent;
8990
}
9091
::-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)'
9394
: 'rgba(130, 109, 217, 0.2)'};
9495
border-radius: 9999px;
9596
transition: background-color 0.2s;
9697
}
9798
::-webkit-scrollbar-thumb:hover {
98-
background: ${document.documentElement.classList.contains('dark')
99+
background: ${theme === 'dark'
99100
? 'rgba(130, 109, 217, 0.5)'
100101
: 'rgba(130, 109, 217, 0.4)'};
101102
}
102103
/* Firefox 滚动条 */
103104
* {
104105
scrollbar-width: thin;
105-
scrollbar-color: ${document.documentElement.classList.contains('dark')
106+
scrollbar-color: ${theme === 'dark'
106107
? 'rgba(130, 109, 217, 0.3) transparent'
107108
: 'rgba(130, 109, 217, 0.2) transparent'};
108109
}
@@ -139,7 +140,12 @@ export function MessageView({ emailId, messageId }: MessageViewProps) {
139140
}
140141
}
141142
}
142-
}, [message?.html, viewMode])
143+
}
144+
145+
// 监听主题变化和内容变化
146+
useEffect(() => {
147+
updateIframeContent()
148+
}, [message?.html, viewMode, theme])
143149

144150
if (loading) {
145151
return (

0 commit comments

Comments
 (0)