Files
shorturl-analytics/app/utils/store.ts
2025-04-07 23:20:48 +08:00

30 lines
732 B
TypeScript

import { create } from 'zustand';
// 定义 ShortUrl 数据类型
export interface ShortUrlData {
id: string;
slug: string;
originalUrl: string;
title?: string;
shortUrl: string;
teams?: any[];
projects?: any[];
tags?: any[];
createdAt?: string;
domain?: string;
}
// 定义 store 类型
interface ShortUrlStore {
selectedShortUrl: ShortUrlData | null;
setSelectedShortUrl: (shortUrl: ShortUrlData | null) => void;
clearSelectedShortUrl: () => void;
}
// 创建 store
export const useShortUrlStore = create<ShortUrlStore>((set) => ({
selectedShortUrl: null,
setSelectedShortUrl: (shortUrl) => set({ selectedShortUrl: shortUrl }),
clearSelectedShortUrl: () => set({ selectedShortUrl: null }),
}));