diff --git a/stores/templateSocialStore.ts b/stores/templateSocialStore.ts index abc87f4..64e49c6 100644 --- a/stores/templateSocialStore.ts +++ b/stores/templateSocialStore.ts @@ -208,5 +208,41 @@ export function useTemplateFavoriteCount(templateId: string | undefined) { ) } -// 为了方便使用,导出 templateSocialStore 别名 -export const templateSocialStore = useTemplateSocialStore +// 为了方便使用,导出 store 实例用于直接调用方法 +// 注意:在组件中使用时应该用 useTemplateSocialStore() hook +export const templateSocialStore = { + setLiked: (templateId: string, liked: boolean) => + useTemplateSocialStore.getState().setLiked(templateId, liked), + setFavorited: (templateId: string, favorited: boolean) => + useTemplateSocialStore.getState().setFavorited(templateId, favorited), + setLikeCount: (templateId: string, count: number) => + useTemplateSocialStore.getState().setLikeCount(templateId, count), + setFavoriteCount: (templateId: string, count: number) => + useTemplateSocialStore.getState().setFavoriteCount(templateId, count), + setLikedStates: (states: Record) => + useTemplateSocialStore.getState().setLikedStates(states), + setFavoritedStates: (states: Record) => + useTemplateSocialStore.getState().setFavoritedStates(states), + setLikeCountStates: (states: Record) => + useTemplateSocialStore.getState().setLikeCountStates(states), + setFavoriteCountStates: (states: Record) => + useTemplateSocialStore.getState().setFavoriteCountStates(states), + incrementLikeCount: (templateId: string) => + useTemplateSocialStore.getState().incrementLikeCount(templateId), + decrementLikeCount: (templateId: string) => + useTemplateSocialStore.getState().decrementLikeCount(templateId), + getLiked: (templateId: string) => + useTemplateSocialStore.getState().getLiked(templateId), + getFavorited: (templateId: string) => + useTemplateSocialStore.getState().getFavorited(templateId), + getLikeCount: (templateId: string) => + useTemplateSocialStore.getState().getLikeCount(templateId), + getFavoriteCount: (templateId: string) => + useTemplateSocialStore.getState().getFavoriteCount(templateId), + isLiked: (templateId: string) => + useTemplateSocialStore.getState().isLiked(templateId), + isFavorited: (templateId: string) => + useTemplateSocialStore.getState().isFavorited(templateId), + clear: () => + useTemplateSocialStore.getState().clear(), +}