feat(frontend): 添加捕获存储钩子
- 新增 useCapture 使用 Zustand 库创建状态管理
This commit is contained in:
@@ -79,7 +79,7 @@ function CapturePage() {
|
||||
const fetchInterfaces = async () => {
|
||||
setIsCapturing(false);
|
||||
setCapturedData([]);
|
||||
setParsedData(null);
|
||||
// setParsedData(null);
|
||||
setLoading(false);
|
||||
setInterfaceLoading(true);
|
||||
try {
|
||||
@@ -145,7 +145,7 @@ function CapturePage() {
|
||||
setLoading(false);
|
||||
setIsCapturing(false);
|
||||
setCapturedData([]);
|
||||
setParsedData(null);
|
||||
// setParsedData(null);
|
||||
try {
|
||||
setLoading(true);
|
||||
await safeApiCall(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {create} from 'zustand';
|
||||
import {persist} from 'zustand/middleware';
|
||||
|
||||
export interface Equipment {
|
||||
id: string;
|
||||
@@ -24,7 +25,14 @@ interface CaptureStoreState {
|
||||
setParsedData: (data: CaptureResult | null) => void;
|
||||
}
|
||||
|
||||
export const useCaptureStore = create<CaptureStoreState>((set) => ({
|
||||
export const useCaptureStore = create<CaptureStoreState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
parsedData: null,
|
||||
setParsedData: (data) => set({ parsedData: data }),
|
||||
}));
|
||||
}),
|
||||
{
|
||||
name: 'capture-store', // localStorage key
|
||||
partialize: (state) => ({ parsedData: state.parsedData }) }
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user