UNPKG

bigblocks

Version:

Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React

18 lines 2.41 kB
{ "name": "social-hooks-usefetchlikes", "type": "registry:hook", "dependencies": [ "@tanstack/react-query", "bmap-api-types" ], "devDependencies": [], "registryDependencies": [], "files": [ { "path": "components/social/hooks/useFetchLikes.ts", "type": "registry:hook", "content": "// useFetchLikes Hook - Fetch likes for posts\nimport { useQuery } from \"@tanstack/react-query\";\nimport type { LikeInfo, LikesResponse } from \"bmap-api-types\";\nimport { useApiClient } from \"./useApiClient.js\";\n\ninterface UseFetchLikesOptions {\n\ttxid: string;\n\tenabled?: boolean;\n}\n\ninterface UseFetchLikesResult {\n\tlikeInfo: LikeInfo | null;\n\tisLoading: boolean;\n\terror: Error | null;\n\trefetch: () => void;\n}\n\nexport function useFetchLikes({\n\ttxid,\n\tenabled = true,\n}: UseFetchLikesOptions): UseFetchLikesResult {\n\tconst apiClient = useApiClient();\n\n\tconst {\n\t\tdata: likeInfo = null,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t} = useQuery<LikeInfo | null, Error>({\n\t\tqueryKey: [\"likes\", txid],\n\t\tqueryFn: async () => {\n\t\t\tif (!txid) return null;\n\t\t\treturn await apiClient.likes.forPost(txid);\n\t\t},\n\t\tenabled: enabled && !!txid,\n\t\tstaleTime: 1000 * 60, // 1 minute\n\t});\n\n\treturn {\n\t\tlikeInfo,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t};\n}\n\n// Hook for fetching likes for a user\ninterface UseFetchUserLikesOptions {\n\tbapId: string;\n\tpage?: number;\n\tlimit?: number;\n\tenabled?: boolean;\n}\n\ninterface UseFetchUserLikesResult {\n\tlikesResponse: LikesResponse | null;\n\tisLoading: boolean;\n\terror: Error | null;\n\trefetch: () => void;\n}\n\nexport function useFetchUserLikes({\n\tbapId,\n\tpage = 1,\n\tlimit = 20,\n\tenabled = true,\n}: UseFetchUserLikesOptions): UseFetchUserLikesResult {\n\tconst apiClient = useApiClient();\n\n\tconst {\n\t\tdata: likesResponse = null,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t} = useQuery<LikesResponse | null, Error>({\n\t\tqueryKey: [\"userLikes\", bapId, page, limit],\n\t\tqueryFn: async () => {\n\t\t\tif (!bapId) return null;\n\t\t\treturn await apiClient.likes.byUser(bapId, page, limit);\n\t\t},\n\t\tenabled: enabled && !!bapId,\n\t\tstaleTime: 1000 * 60 * 5, // 5 minutes\n\t});\n\n\treturn {\n\t\tlikesResponse,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t};\n}\n", "target": "<%- config.aliases.hooks %>/usefetchlikes.ts" } ] }