diff --git a/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx b/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx index bf4a8807c..79d7a28ff 100644 --- a/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx +++ b/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx @@ -3,7 +3,10 @@ import { StyledText } from '../../elements/StyledText' import { Box, HStack, SpanBox, VStack } from '../../elements/LayoutPrimitives' import { Button } from '../../elements/Button' import { Circle } from 'phosphor-react' -import { useGetSubscriptionsQuery } from '../../../lib/networking/queries/useGetSubscriptionsQuery' +import { + Subscription, + useGetSubscriptionsQuery, +} from '../../../lib/networking/queries/useGetSubscriptionsQuery' import { useGetLabelsQuery } from '../../../lib/networking/queries/useGetLabelsQuery' import { Label } from '../../../lib/networking/fragments/labelFragment' import { theme } from '../../tokens/stitches.config' @@ -29,6 +32,11 @@ type LibraryFilterMenuProps = { } export function LibraryFilterMenu(props: LibraryFilterMenuProps): JSX.Element { + const { labels, isValidating: labelsLoading } = useGetLabelsQuery() + const { savedSearches, isLoading: searchesLoading } = useGetSavedSearchQuery() + const { subscriptions, isValidating: subscriptionsLoading } = + useGetSubscriptionsQuery() + return ( <> - - - + {!labelsLoading && !searchesLoading && !subscriptionsLoading && ( + <> + + + + + )} {/* This spacer pushes library content to the right of @@ -85,17 +97,17 @@ export function LibraryFilterMenu(props: LibraryFilterMenuProps): JSX.Element { ) } -function SavedSearches(props: LibraryFilterMenuProps): JSX.Element { - const { savedSearches, isLoading } = useGetSavedSearchQuery() - +function SavedSearches( + props: LibraryFilterMenuProps & { savedSearches: SavedSearch[] | undefined } +): JSX.Element { const sortedSearches = useMemo(() => { - return savedSearches + return props.savedSearches ?.filter((it) => it.visible) ?.sort( (left: SavedSearch, right: SavedSearch) => left.position - right.position ) - }, [savedSearches]) + }, [props.savedSearches]) useRegisterActions( (sortedSearches ?? []).map((item, idx) => { @@ -111,7 +123,7 @@ function SavedSearches(props: LibraryFilterMenuProps): JSX.Element { }, } }), - [isLoading] + [props.savedSearches] ) const [collapsed, setCollapsed] = usePersistedState({ @@ -135,7 +147,7 @@ function SavedSearches(props: LibraryFilterMenuProps): JSX.Element { {...props} /> ))} - {!collapsed && !isLoading && ( + {!collapsed && sortedSearches !== undefined && ( ({ key: `--subscriptions-collapsed`, initialValue: false, }) useRegisterActions( - (subscriptions ?? []).map((subscription, idx) => { + (props.subscriptions ?? []).map((subscription, idx) => { const key = String(idx + 1) const name = subscription.name return { @@ -168,7 +181,7 @@ function Subscriptions(props: LibraryFilterMenuProps): JSX.Element { }, } }), - [subscriptions] + [props.subscriptions] ) return ( @@ -186,7 +199,7 @@ function Subscriptions(props: LibraryFilterMenuProps): JSX.Element { text="Newsletters" {...props} /> - {(subscriptions ?? []).map((item) => { + {(props.subscriptions ?? []).map((item) => { return ( ({ key: `--labels-collapsed`, initialValue: false, }) const sortedLabels = useMemo(() => { - return labels.sort((left: Label, right: Label) => + return props.labels.sort((left: Label, right: Label) => left.name.localeCompare(right.name) ) - }, [labels]) + }, [props.labels]) return (