diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index bf8ffc7..4cda19e 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -4,6 +4,7 @@ import { useUIStore } from './stores/useUIStore';
import { useLibraryStore } from './stores/useLibraryStore';
import { useImageStore } from './stores/useImageStore';
import { useScanStore } from './stores/useScanStore';
+import { useTheme } from './hooks/useTheme';
import { libraryAPI, imageAPI, scanAPI } from './api';
import domCleanup from './utils/domCleanup';
import Sidebar from './components/Sidebar';
@@ -13,7 +14,10 @@ import Header from './components/Header';
import LibraryMissingModal from './components/LibraryMissingModal';
function App() {
- const { theme, mobileView, setMobileView } = useUIStore();
+ // 使用统一的主题管理 Hook
+ useTheme();
+
+ const { mobileView, setMobileView } = useUIStore();
const {
setLibraries,
setCurrentLibrary,
@@ -33,15 +37,6 @@ function App() {
const [missingLibrary, setMissingLibrary] = useState(null); // 丢失的素材库信息
const containerRef = useRef(null);
- useEffect(() => {
- // Apply theme
- if (theme === 'dark') {
- document.documentElement.classList.add('dark');
- } else {
- document.documentElement.classList.remove('dark');
- }
- }, [theme]);
-
// 检测屏幕尺寸
useEffect(() => {
const checkMobile = () => {
@@ -581,7 +576,7 @@ function App() {
/>
{/* 左侧边栏 */}
-
+
@@ -623,7 +618,7 @@ function App() {
{/* 右侧边栏 */}
-
diff --git a/frontend/src/components/Header.jsx b/frontend/src/components/Header.jsx
index 97ab2c2..9555794 100644
--- a/frontend/src/components/Header.jsx
+++ b/frontend/src/components/Header.jsx
@@ -4,12 +4,14 @@ import { useLibraryStore } from '../stores/useLibraryStore';
import { useImageStore } from '../stores/useImageStore';
import { useUIStore } from '../stores/useUIStore';
import { useScanStore } from '../stores/useScanStore';
+import { useTheme } from '../hooks/useTheme';
import { libraryAPI, scanAPI, watchAPI } from '../api';
function Header() {
const { currentLibraryId } = useLibraryStore();
const { searchKeywords, originalImages, selectedFolder, setSearchKeywords, filters, setFilters, resetFilters } = useImageStore();
- const { theme, toggleTheme, thumbnailHeight, setThumbnailHeight, mobileView } = useUIStore();
+ const { thumbnailHeight, setThumbnailHeight, mobileView } = useUIStore();
+ const { theme, toggleTheme } = useTheme();
const [showFilters, setShowFilters] = useState(false);
const [isRefreshing, setIsRefreshing] = useState(false);
@@ -226,15 +228,6 @@ function Header() {
setFilters({ formats: [], sizes: [], orientation: '' });
};
- const handleThemeToggle = async () => {
- toggleTheme();
- try {
- await libraryAPI.updateTheme(theme === 'light' ? 'dark' : 'light');
- } catch (error) {
- console.error('Error saving theme:', error);
- }
- };
-
const handleThumbnailHeightChange = async (height) => {
setThumbnailHeight(height);
try {
@@ -298,7 +291,7 @@ function Header() {