react-code-dataset / wp-calypso /packages /data-stores /src /reader /contexts /unsubscribed-feeds-search.tsx
react-code-dataset / wp-calypso /packages /data-stores /src /reader /contexts /unsubscribed-feeds-search.tsx
Download wp-calypso/packages/data-stores/src/reader/contexts/unsubscribed-feeds-search.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/reader/contexts/unsubscribed-feeds-search.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/data-stores/src/reader/contexts/unsubscribed-feeds-search.tsx
-
curl -L -o unsubscribed-feeds-search.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/reader/contexts/unsubscribed-feeds-search.tsx
1.22 kB
| import React, { createContext, useContext, ReactNode, useMemo } from 'react'; | |
| import useReadFeedSearchQuery, { FeedItem } from '../queries/use-read-feed-search-query'; | |
| import { useSiteSubscriptionsQueryProps } from './site-subscriptions-query-props'; | |
| type UnsubscribedFeedsSearch = { | |
| feedItems: FeedItem[]; | |
| searchQueryResult: ReturnType< typeof useReadFeedSearchQuery >; | |
| }; | |
| const UnsubscribedFeedsSearchContext = createContext< UnsubscribedFeedsSearch | undefined >( | |
| undefined | |
| ); | |
| export const UnsubscribedFeedsSearchProvider: React.FC< { children: ReactNode } > = ( { | |
| children, | |
| } ) => { | |
| const { searchTerm } = useSiteSubscriptionsQueryProps(); | |
| const searchQueryResult = useReadFeedSearchQuery( { query: searchTerm, excludeFollowed: true } ); | |
| const feedItems = useMemo( () => { | |
| if ( searchTerm === '' ) { | |
| return []; | |
| } | |
| return searchQueryResult.data?.pages?.[ 0 ]?.feeds || []; | |
| }, [ searchTerm, searchQueryResult.data?.pages ] ); | |
| return ( | |
| <UnsubscribedFeedsSearchContext.Provider value={ { feedItems, searchQueryResult } }> | |
| { children } | |
| </UnsubscribedFeedsSearchContext.Provider> | |
| ); | |
| }; | |
| export const useUnsubscribedFeedsSearch = () => { | |
| return useContext( UnsubscribedFeedsSearchContext ); | |
| }; | |