bigblocks
Version:
Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React
17 lines • 2.23 kB
JSON
{
"name": "social-hooks-usechannels",
"type": "registry:hook",
"dependencies": [
"@tanstack/react-query"
],
"devDependencies": [],
"registryDependencies": [],
"files": [
{
"path": "components/social/hooks/useChannels.ts",
"type": "registry:hook",
"content": "// useChannels Hook - Fetch and manage channels\nimport { useQuery } from \"@tanstack/react-query\";\nimport type {\n\tChannelInfo,\n\tChannelMessageParams,\n\tMessagesResponse,\n} from \"bmap-api-types\";\nimport { useApiClient } from \"./useApiClient.js\";\n\ninterface UseChannelsResult {\n\tchannels: ChannelInfo[];\n\tisLoading: boolean;\n\terror: Error | null;\n\trefetch: () => void;\n}\n\nexport function useChannels(): UseChannelsResult {\n\tconst apiClient = useApiClient();\n\n\tconst {\n\t\tdata: channels = [],\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t} = useQuery<ChannelInfo[], Error>({\n\t\tqueryKey: [\"channels\"],\n\t\tqueryFn: async () => {\n\t\t\treturn await apiClient.channels.list();\n\t\t},\n\t\tstaleTime: 1000 * 60 * 5, // 5 minutes\n\t});\n\n\treturn {\n\t\tchannels,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t};\n}\n\n// Hook for fetching channel messages\ninterface UseChannelMessagesOptions extends Partial<ChannelMessageParams> {\n\tenabled?: boolean;\n}\n\ninterface UseChannelMessagesResult {\n\tmessages: MessagesResponse | null;\n\tisLoading: boolean;\n\terror: Error | null;\n\trefetch: () => void;\n}\n\nexport function useChannelMessages({\n\tchannelId = \"\",\n\tpage = 1,\n\tlimit = 20,\n\tenabled = true,\n}: UseChannelMessagesOptions): UseChannelMessagesResult {\n\tconst apiClient = useApiClient();\n\n\tconst {\n\t\tdata: messages = null,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t} = useQuery<MessagesResponse | null, Error>({\n\t\tqueryKey: [\"channelMessages\", channelId, page, limit],\n\t\tqueryFn: async () => {\n\t\t\tif (!channelId) return null;\n\t\t\treturn await apiClient.messages.channel(channelId, page, limit);\n\t\t},\n\t\tenabled: enabled && !!channelId,\n\t\tstaleTime: 1000 * 60, // 1 minute\n\t});\n\n\treturn {\n\t\tmessages,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t};\n}\n",
"target": "<%- config.aliases.hooks %>/usechannels.ts"
}
]
}