mirror of
https://github.com/hanzo-io/chat.git
synced 2026-10-30 18:57:58 +00:00
29 lines
943 B
TypeScript
29 lines
943 B
TypeScript
import React, { useContext, useMemo } from 'react'
|
|
import { ChannelListContext } from '../providers/ChannelListProvider'
|
|
|
|
type Props = {
|
|
/** If set to true, will return all channels including archived ones. */
|
|
showArchived?: boolean
|
|
}
|
|
|
|
/**
|
|
* Hook to get the channels from the channel list provider. Also returns if the channel list is loading or not.
|
|
* @param props
|
|
* @returns
|
|
*/
|
|
const useGetChannels = ({ showArchived = false }: Props) => {
|
|
|
|
const channelListContextData = useContext(ChannelListContext)
|
|
|
|
const filteredChannels = useMemo(() => {
|
|
if (showArchived) return channelListContextData?.channels ?? []
|
|
return channelListContextData?.channels?.filter(channel => !channel.is_archived) ?? []
|
|
}, [channelListContextData?.channels, showArchived])
|
|
|
|
return {
|
|
channels: filteredChannels,
|
|
isLoading: channelListContextData?.isLoading ?? false
|
|
}
|
|
}
|
|
|
|
export default useGetChannels |