refactor: 代码质量优化与安全修复
- 删除根目录重复的 server.js (830行),统一使用模块化的 server/index.js - 修复 ESLint 错误: 移除未使用变量、修复 const 声明、处理未使用参数 - 修复 React Hooks 依赖警告: 使用 useCallback 包装函数并添加正确依赖项 - SQL LIKE 查询添加特殊字符转义,防止注入风险 - 移除 CSS 中重复的 @keyframes spin 定义 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
63c97ab31a
commit
98aa39cb1c
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { isLoggedIn, getCategories, createCategory, deleteCategory } from '../lib/api';
|
||||
import AppShell from '../components/AppShell';
|
||||
@@ -30,15 +30,7 @@ export default function Categories() {
|
||||
icon: '📝',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn()) {
|
||||
router.push('/login');
|
||||
return;
|
||||
}
|
||||
loadCategories();
|
||||
}, [router]);
|
||||
|
||||
const loadCategories = async () => {
|
||||
const loadCategories = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await getCategories();
|
||||
@@ -49,7 +41,15 @@ export default function Categories() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
}, [showToast]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn()) {
|
||||
router.push('/login');
|
||||
return;
|
||||
}
|
||||
loadCategories();
|
||||
}, [router, loadCategories]);
|
||||
|
||||
const openAddModal = (type) => {
|
||||
setCategoryType(type);
|
||||
|
||||
Reference in New Issue
Block a user