全新popiart网站 react项目重构
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

125 lines
3.6 KiB

import { create } from "zustand";
/**
* 「制作同款」:从探索卡片等任意位置把作品 id 交给底部 GlobalPromptPanel。
* 用 tick 保证同一 id 连续点击也会再次触发。
*/
type MakeSameState = {
pendingPostId: number | string | null;
makeSameTick: number;
requestMakeSame: (postId: number | string) => void;
clearPendingMakeSame: () => void;
};
export const useMakeSameStore = create<MakeSameState>((set) => ({
pendingPostId: null,
makeSameTick: 0,
requestMakeSame: (postId) =>
set((s) => ({
pendingPostId: postId,
makeSameTick: s.makeSameTick + 1,
})),
clearPendingMakeSame: () => set({ pendingPostId: null }),
}));
/**
* 「模板制作同款」:与 {@link useMakeSameStore} 相同字段与 tick 语义,独立 store 避免与探索入口互相覆盖。
*/
export const useTemplateMakeSameStore = create<MakeSameState>((set) => ({
pendingPostId: null,
makeSameTick: 0,
requestMakeSame: (postId) =>
set((s) => ({
pendingPostId: postId,
makeSameTick: s.makeSameTick + 1,
})),
clearPendingMakeSame: () => set({ pendingPostId: null }),
}));
type GlobalPromptImageState = {
pendingImageUrl: string | null;
pendingImageLabel: string | null;
pendingImageSubType: number | null;
appendImageTick: number;
requestAppendImageUrl: (url: string, label?: string, subType?: number | null) => void;
clearPendingImageUrl: () => void;
};
/**
* 跨页面向 GlobalPromptPanel 追加一张图片 URL。
* 使用 tick 保证同一 URL 连续触发时也会生效。
*/
export const useGlobalPromptImageStore = create<GlobalPromptImageState>((set) => ({
pendingImageUrl: null,
pendingImageLabel: null,
pendingImageSubType: null,
appendImageTick: 0,
requestAppendImageUrl: (url, label, subType) =>
set((s) => ({
pendingImageUrl: url,
pendingImageLabel: typeof label === "string" && label.trim() !== "" ? label.trim() : null,
pendingImageSubType: typeof subType === "number" ? subType : null,
appendImageTick: s.appendImageTick + 1,
})),
clearPendingImageUrl: () => set({ pendingImageUrl: null, pendingImageLabel: null, pendingImageSubType: null }),
}));
/**
* 从任意页面请求切换 GlobalPromptPanel 的「当前产品分类」。
* 用 tick 保证同一 subType 连续触发也会再次生效。
*/
type ActiveTaskSubTypeState = {
pendingTaskSubType: number | null;
activeTaskSubTypeTick: number;
requestSetActiveTaskSubType: (subType: number) => void;
clearPendingActiveTaskSubType: () => void;
};
export const useActiveTaskSubTypeStore = create<ActiveTaskSubTypeState>((set) => ({
pendingTaskSubType: null,
activeTaskSubTypeTick: 0,
requestSetActiveTaskSubType: (subType) =>
set((s) => ({
pendingTaskSubType: subType,
activeTaskSubTypeTick: s.activeTaskSubTypeTick + 1,
})),
clearPendingActiveTaskSubType: () => set({ pendingTaskSubType: null }),
}));
type CharacterReferencePayload = {
id: number | string;
title: string;
threeViewImage: string;
};
/**
// 应用角色到参考
*/
type CharacterToReferenceState = {
pendingCharacter: CharacterReferencePayload | null;
applyCharacterTick: number;
requestApplyCharacterToReference: (payload: CharacterReferencePayload) => void;
clearPendingCharacter: () => void;
};
export const useCharacterToReferenceStore = create<CharacterToReferenceState>((set) => ({
pendingCharacter: null,
applyCharacterTick: 0,
requestApplyCharacterToReference: (payload) =>
set((s) => ({
pendingCharacter: payload,
applyCharacterTick: s.applyCharacterTick + 1,
})),
clearPendingCharacter: () => set({ pendingCharacter: null }),
}));