hide filter
This commit is contained in:
@@ -1,4 +1,18 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
// Define interface for team, project and tag objects
|
||||
interface TeamData {
|
||||
team_id: string;
|
||||
team_name: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface ProjectData {
|
||||
project_id: string;
|
||||
project_name: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
// 定义 ShortUrl 数据类型
|
||||
export interface ShortUrlData {
|
||||
@@ -7,9 +21,9 @@ export interface ShortUrlData {
|
||||
originalUrl: string;
|
||||
title?: string;
|
||||
shortUrl: string;
|
||||
teams?: any[];
|
||||
projects?: any[];
|
||||
tags?: any[];
|
||||
teams?: TeamData[];
|
||||
projects?: ProjectData[];
|
||||
tags?: string[];
|
||||
createdAt?: string;
|
||||
domain?: string;
|
||||
}
|
||||
@@ -21,9 +35,17 @@ interface ShortUrlStore {
|
||||
clearSelectedShortUrl: () => void;
|
||||
}
|
||||
|
||||
// 创建 store
|
||||
export const useShortUrlStore = create<ShortUrlStore>((set) => ({
|
||||
selectedShortUrl: null,
|
||||
setSelectedShortUrl: (shortUrl) => set({ selectedShortUrl: shortUrl }),
|
||||
clearSelectedShortUrl: () => set({ selectedShortUrl: null }),
|
||||
}));
|
||||
// 创建 store 并使用 persist 中间件保存到 localStorage
|
||||
export const useShortUrlStore = create<ShortUrlStore>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
selectedShortUrl: null,
|
||||
setSelectedShortUrl: (shortUrl) => set({ selectedShortUrl: shortUrl }),
|
||||
clearSelectedShortUrl: () => set({ selectedShortUrl: null }),
|
||||
}),
|
||||
{
|
||||
name: 'shorturl-storage', // localStorage 中的 key 名称
|
||||
partialize: (state) => ({ selectedShortUrl: state.selectedShortUrl }), // 只持久化 selectedShortUrl
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user