refactor: migrate img tags to next/image and fix hook usage
This commit is contained in:
@@ -14,12 +14,12 @@ import { authRepository } from "@/data/repositories/auth_repository";
|
||||
import { AuthStorage } from "@/data/storage/auth/auth_storage";
|
||||
import { Result } from "@/utils/result";
|
||||
|
||||
import { AuthState, initialState } from "../auth-state";
|
||||
import { AuthState, initialState } from "./auth-state";
|
||||
import type { AuthEvent } from "./auth-events";
|
||||
|
||||
// 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变
|
||||
export type { AuthState } from "../auth-state";
|
||||
export { initialState } from "../auth-state";
|
||||
export type { AuthState } from "./auth-state";
|
||||
export { initialState } from "./auth-state";
|
||||
export type { AuthEvent } from "./auth-events";
|
||||
|
||||
// ============================================================
|
||||
@@ -7,4 +7,4 @@
|
||||
* - Context 形状与初始值由 `auth-context.ts` 导出
|
||||
* - `AuthState` 由 `auth-context.tsx` 导出(保持原 API 兼容)
|
||||
*/
|
||||
export type { AuthEvent } from "./machine/auth-events";
|
||||
export type { AuthEvent } from "./auth-events";
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
*/
|
||||
export * from "./auth-state";
|
||||
export * from "./auth-context";
|
||||
export * from "./machine/auth-events";
|
||||
export * from "./machine/auth-machine";
|
||||
export * from "./auth-events";
|
||||
export * from "./auth-machine";
|
||||
export * from "./auth-types";
|
||||
|
||||
@@ -20,8 +20,8 @@ import {
|
||||
} from "react";
|
||||
import { useMachine } from "@xstate/react";
|
||||
|
||||
import { chatMachine } from "./machine/chat-machine";
|
||||
import type { ChatEvent, ChatState as MachineContext } from "./machine/chat-machine";
|
||||
import { chatMachine } from "./chat-machine";
|
||||
import type { ChatEvent, ChatState as MachineContext } from "./chat-machine";
|
||||
|
||||
/**
|
||||
* 对外暴露的 State 形状(保持与原 ChatState 兼容)
|
||||
@@ -46,7 +46,7 @@ export interface ChatProviderProps {
|
||||
}
|
||||
|
||||
export function ChatProvider({ children }: ChatProviderProps) {
|
||||
const [state, send] = useMachine(chatMachine);
|
||||
const [state, send] = useMachine(chatMachine, {});
|
||||
|
||||
// 映射 XState 状态机快照 → 原 ChatState 形状
|
||||
const chatState = useMemo<ChatState>(
|
||||
|
||||
@@ -24,7 +24,7 @@ import { formatDate } from "@/utils/date";
|
||||
import { Result } from "@/utils/result";
|
||||
|
||||
import { ChatState, initialState } from "./chat-state";
|
||||
import type { ChatEvent } from "./machine/chat-events";
|
||||
import type { ChatEvent } from "./chat-events";
|
||||
|
||||
/** 游客配额阈值(与 Dart `GuestChatQuota` 保持一致) */
|
||||
export const GuestChatQuota = {
|
||||
@@ -35,7 +35,7 @@ export const GuestChatQuota = {
|
||||
// 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变
|
||||
export type { ChatState } from "./chat-state";
|
||||
export { initialState } from "./chat-state";
|
||||
export type { ChatEvent } from "./machine/chat-events";
|
||||
export type { ChatEvent } from "./chat-events";
|
||||
|
||||
// ============================================================
|
||||
// Helpers
|
||||
@@ -8,5 +8,5 @@
|
||||
* - `ChatState` 由 `chat-context.tsx` 导出(保持原 API 兼容)
|
||||
* - `GuestChatQuota` 仍由 `chat-machine.ts` 导出(业务常量,与上下文配对紧密)
|
||||
*/
|
||||
export type { ChatEvent } from "./machine/chat-events";
|
||||
export type { ChatEvent } from "./chat-events";
|
||||
export { GuestChatQuota } from "./chat-machine";
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
* 注:chat-side-effects.ts 暂未删除(其中 WebSocket 长生命周期逻辑
|
||||
* 待下一轮迁移到 fromCallback actor)。
|
||||
*/
|
||||
export * from "./machine/chat-state";
|
||||
export * from "./chat-state";
|
||||
export * from "./chat-context";
|
||||
export * from "./machine/chat-events";
|
||||
export * from "./chat-events";
|
||||
export * from "./chat-types";
|
||||
export { chatMachine } from "./chat-machine";
|
||||
|
||||
@@ -12,4 +12,4 @@ export * from "./sidebar-state";
|
||||
export * from "./sidebar-context";
|
||||
export * from "./sidebar-events";
|
||||
export * from "./sidebar-types";
|
||||
export { sidebarMachine } from "./machine/sidebar-machine";
|
||||
export { sidebarMachine } from "./sidebar-machine";
|
||||
|
||||
@@ -17,11 +17,11 @@ import {
|
||||
} from "react";
|
||||
import { useMachine } from "@xstate/react";
|
||||
|
||||
import { sidebarMachine } from "./machine/sidebar-machine";
|
||||
import { sidebarMachine } from "./sidebar-machine";
|
||||
import type {
|
||||
SidebarState as MachineContext,
|
||||
SidebarEvent,
|
||||
} from "./machine/sidebar-machine";
|
||||
} from "./sidebar-machine";
|
||||
|
||||
/**
|
||||
* 对外暴露的 State 形状(保持与原 SidebarState 兼容)
|
||||
@@ -37,7 +37,7 @@ const SidebarStateCtx = createContext<SidebarState | null>(null);
|
||||
const SidebarDispatchCtx = createContext<Dispatch<SidebarEvent> | null>(null);
|
||||
|
||||
export function SidebarProvider({ children }: { children: ReactNode }) {
|
||||
const [state, send] = useMachine(sidebarMachine);
|
||||
const [state, send] = useMachine(sidebarMachine, {});
|
||||
|
||||
// 映射 XState 状态机快照 → 原 SidebarState 形状
|
||||
const sidebarState = useMemo<SidebarState>(
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
import { setup, assign } from "xstate";
|
||||
|
||||
import { SidebarState, initialState } from "../sidebar-state";
|
||||
import { SidebarState, initialState } from "./sidebar-state";
|
||||
import type { SidebarEvent } from "./sidebar-events";
|
||||
|
||||
/**
|
||||
@@ -37,8 +37,8 @@ export const BottomNavItem = {
|
||||
export type BottomNavItem = (typeof BottomNavItem)[keyof typeof BottomNavItem];
|
||||
|
||||
// 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变
|
||||
export type { SidebarState } from "../sidebar-state";
|
||||
export { initialState } from "../sidebar-state";
|
||||
export type { SidebarState } from "./sidebar-state";
|
||||
export { initialState } from "./sidebar-state";
|
||||
export type { SidebarEvent } from "./sidebar-events";
|
||||
|
||||
// ============================================================
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* SidebarPage / BottomNavItem 仍由 sidebar-machine.ts 导出(事件/上下文均需引用)。
|
||||
*/
|
||||
import { SidebarPage, BottomNavItem } from "./machine/sidebar-machine";
|
||||
import { SidebarPage, BottomNavItem } from "./sidebar-machine";
|
||||
|
||||
export interface SidebarState {
|
||||
currentPage: SidebarPage;
|
||||
@@ -8,5 +8,5 @@
|
||||
* - Context 形状由 `sidebar-context.ts` 导出
|
||||
* - SidebarState 由 `sidebar-context.tsx` 导出(保持原 API 兼容)
|
||||
*/
|
||||
export { SidebarPage, BottomNavItem } from "./machine/sidebar-machine";
|
||||
export { SidebarPage, BottomNavItem } from "./sidebar-machine";
|
||||
export type { SidebarEvent } from "./sidebar-events";
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* - Context 形状与初始值位于 user-context.ts
|
||||
* - 事件联合位于 user-events.ts
|
||||
*/
|
||||
export * from "./machine/user-state";
|
||||
export * from "./user-state";
|
||||
export * from "./user-context";
|
||||
export * from "./machine/user-events";
|
||||
export * from "./user-events";
|
||||
export * from "./user-types";
|
||||
export { userMachine } from "./user-machine";
|
||||
|
||||
@@ -17,13 +17,13 @@ import { authRepository } from "@/data/repositories/auth_repository";
|
||||
import { UserStorage } from "@/data/storage/user/user_storage";
|
||||
import { Result } from "@/utils/result";
|
||||
|
||||
import { UserState, initialState } from "./machine/user-state";
|
||||
import type { UserEvent } from "./machine/user-events";
|
||||
import { UserState, initialState } from "./user-state";
|
||||
import type { UserEvent } from "./user-events";
|
||||
|
||||
// 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变
|
||||
export type { UserState } from "./machine/user-state";
|
||||
export { initialState } from "./machine/user-state";
|
||||
export type { UserEvent } from "./machine/user-events";
|
||||
export type { UserState } from "./user-state";
|
||||
export { initialState } from "./user-state";
|
||||
export type { UserEvent } from "./user-events";
|
||||
|
||||
// ============================================================
|
||||
// Helpers
|
||||
@@ -7,4 +7,4 @@
|
||||
* - Context 形状与初始值由 `user-context.ts` 导出
|
||||
* - `UserState` 由 `user-context.tsx` 导出(保持原 API 兼容)
|
||||
*/
|
||||
export type { UserEvent } from "./machine/user-events";
|
||||
export type { UserEvent } from "./user-events";
|
||||
|
||||
Reference in New Issue
Block a user