diff --git a/packages/web/pages/settings/pinned-searches.tsx b/packages/web/pages/settings/pinned-searches.tsx index f7d85437e..819278b78 100644 --- a/packages/web/pages/settings/pinned-searches.tsx +++ b/packages/web/pages/settings/pinned-searches.tsx @@ -1,13 +1,11 @@ -import { +import React, { + ReactNode, useCallback, useEffect, useMemo, useReducer, - useRef, - useState, } from 'react' import { Toaster } from 'react-hot-toast' -import { Button } from '../../components/elements/Button' import { Box, HStack, @@ -16,25 +14,13 @@ import { } from '../../components/elements/LayoutPrimitives' import { StyledText } from '../../components/elements/StyledText' import { SettingsLayout } from '../../components/templates/SettingsLayout' -import { styled, theme } from '../../components/tokens/stitches.config' -import { updateEmailMutation } from '../../lib/networking/mutations/updateEmailMutation' -import { updateUserMutation } from '../../lib/networking/mutations/updateUserMutation' -import { updateUserProfileMutation } from '../../lib/networking/mutations/updateUserProfileMutation' -import { useGetLibraryItemsQuery } from '../../lib/networking/queries/useGetLibraryItemsQuery' -import { useGetViewerQuery } from '../../lib/networking/queries/useGetViewerQuery' -import { useValidateUsernameQuery } from '../../lib/networking/queries/useValidateUsernameQuery' import { applyStoredTheme } from '../../lib/themeUpdater' -import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers' -import { ConfirmationModal } from '../../components/patterns/ConfirmationModal' -import { ProgressBar } from '../../components/elements/ProgressBar' import { useGetLabelsQuery } from '../../lib/networking/queries/useGetLabelsQuery' import { useGetSavedSearchQuery } from '../../lib/networking/queries/useGetSavedSearchQuery' -import CheckboxComponent from '../../components/elements/Checkbox' import { Label } from '../../lib/networking/fragments/labelFragment' -import { Circle, ToggleLeft } from 'phosphor-react' +import { Circle } from 'phosphor-react' import { SavedSearch } from '../../lib/networking/fragments/savedSearchFragment' import { usePersistedState } from '../../lib/hooks/usePersistedState' -import { StyledToggleButton } from '../../components/templates/PrimaryDropdown' export type PinnedSearch = { type: 'saved-search' | 'label' @@ -162,92 +148,89 @@ export default function PinnedSearches(): JSX.Element { top: '5rem', }} /> - -
+ + + + Pinned Searches + + + Pin up to five searches from your labels or saved searches. + + + - - - Pinned Searches - - - Pin up to five searches from your labels or saved searches. - - + + { + setHidePinnedSearches(!event.currentTarget.checked) + }} + style={{ padding: '0px', margin: '0px' }} + /> + Enable Pinned Searches + - - - { - setHidePinnedSearches(!event.currentTarget.checked) - }} - style={{ padding: '0px', margin: '0px' }} - /> - Enable Pinned Searches - + {!hidePinnedSearches && ( + <> + + Saved Searches + + {items.savedSearchItems.map((item) => { + return ( + + ) + })} - {!hidePinnedSearches && ( - <> - - Saved Searches - - {items.savedSearchItems.map((item) => { - return ( - - ) - })} - - - Labels - - {items.labelItems.map((item) => { - return ( - - ) - })} - - )} - + + Labels + + {items.labelItems.map((item) => { + return ( + + ) + })} + + )} - +
) } @@ -263,78 +246,28 @@ type LabelButtonProps = { function LabelButton(props: LabelButtonProps): JSX.Element { const labelId = `checkbox-label-${props.label.id}` - - const changeState = useCallback( - (newState: boolean) => { - if (!newState) { - props.listAction({ - type: 'REMOVE_ITEM', - item: { - type: 'label', - itemId: props.label.id, - name: props.label.name, - search: `label:\"${props.label.name}\"`, - }, - }) - } else { - props.listAction({ - type: 'ADD_ITEM', - item: { - type: 'label', - itemId: props.label.id, - name: props.label.name, - search: `label:\"${props.label.name}\"`, - }, - }) - } - }, - [props] - ) - return ( - { - changeState(!props.isSelected) - event.preventDefault() + isSelected={props.isSelected} + item={{ + type: 'label', + itemId: props.label.id, + name: props.label.name, + search: `label:\"${props.label.name}\"`, }} + listAction={props.listAction} > { - changeState(event.currentTarget.checked) - event.preventDefault() - }} + // eslint-disable-next-line @typescript-eslint/no-empty-function + onChange={(event) => {}} /> {props.label.name} - + ) } @@ -350,9 +283,63 @@ type SearchButtonProps = { function SearchButton(props: SearchButtonProps): JSX.Element { const searchId = `checkbox-search-${props.search.id}` return ( - + {}} + /> + {props.search.name} + + ) +} + +type CheckboxButtonProps = { + key: string + title: string + isSelected: boolean + item: PinnedSearch + + listAction: (arg: { + type: ListAction + item?: PinnedSearch | undefined + }) => void + children: ReactNode +} + +function CheckboxButton(props: CheckboxButtonProps): JSX.Element { + const handleChange = useCallback( + (selected: boolean) => { + if (!selected) { + props.listAction({ + type: 'REMOVE_ITEM', + item: props.item, + }) + } else { + props.listAction({ + type: 'ADD_ITEM', + item: props.item, + }) + } + }, + [props] + ) + return ( + { - if (props.isSelected) { - props.listAction({ - type: 'REMOVE_ITEM', - item: { - type: 'saved-search', - itemId: props.search.id, - name: props.search.name, - search: props.search.filter, - }, - }) - } else { - props.listAction({ - type: 'ADD_ITEM', - item: { - type: 'saved-search', - itemId: props.search.id, - name: props.search.name, - search: props.search.filter, - }, - }) - } + handleChange(!props.isSelected) event.preventDefault() }} > - {}} /> - {props.search.name} + {props.children} ) }