refactor(react-hooks): enable stricter effect rules

Turn on react-hooks/set-state-in-effect and react-hooks/incompatible-library, then remove effect-driven local state sync patterns across affected pages. Keep behavior stable by deriving values from source state, remounting tab state by role key, and replacing useForm watch with useWatch.
This commit is contained in:
zetaloop
2026-02-22 10:03:00 +08:00
parent c9dbf5037e
commit 519fb92c34
9 changed files with 36 additions and 59 deletions
-2
View File
@@ -55,8 +55,6 @@ export default function OrderDetailPage({ params }: { params: Promise<{ id: stri
if (!order) return
if (order.status !== "pending_accept" && order.status !== "pending_close") return
setNowTs(Date.now())
const timer = setInterval(() => {
setNowTs(Date.now())
}, 1000)
+8 -8
View File
@@ -8,7 +8,7 @@ import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { statusLabels } from "@/lib/constants"
import type { OrderStatus } from "@/lib/types"
import type { OrderStatus, UserRole } from "@/lib/types"
import { cn } from "@/lib/utils"
import { useAuthStore } from "@/store/auth"
import { useChatStore } from "@/store/chat"
@@ -50,19 +50,19 @@ const ownerTabs = [
]
export default function OrderListPage() {
const [tab, setTab] = useState<TabFilter | "pending">("all")
const { currentRole, user } = useAuthStore()
const userId = user?.id ?? "u1"
return <OrderListContent key={currentRole} currentRole={currentRole} userId={userId} />
}
function OrderListContent({ currentRole, userId }: { currentRole: UserRole; userId: string }) {
const [tab, setTab] = useState<TabFilter | "pending">("all")
const orders = useOrderStore((state) => state.orders)
const sessions = useChatStore((state) => state.sessions)
const ensureOrderSession = useChatStore((state) => state.ensureOrderSession)
const userId = user?.id ?? "u1"
const ownerShopId = "shop1"
useEffect(() => {
if (!currentRole) return
setTab("all")
}, [currentRole])
const tabs =
currentRole === "consumer" ? consumerTabs : currentRole === "player" ? playerTabs : ownerTabs