fix: export templateSocialStore as callable object

- Export templateSocialStore with all methods via getState()
- Allows hooks to call store methods directly
- Fix 'setLiked is not a function' error
This commit is contained in:
imeepos 2026-01-28 20:10:59 +08:00
parent 20459ffd1d
commit 46b45872c1
1 changed files with 38 additions and 2 deletions

View File

@ -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<string, boolean>) =>
useTemplateSocialStore.getState().setLikedStates(states),
setFavoritedStates: (states: Record<string, boolean>) =>
useTemplateSocialStore.getState().setFavoritedStates(states),
setLikeCountStates: (states: Record<string, number>) =>
useTemplateSocialStore.getState().setLikeCountStates(states),
setFavoriteCountStates: (states: Record<string, number>) =>
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(),
}