diff --git a/packages/web/components/elements/images/GridSelectorIcon.tsx b/packages/web/components/elements/images/GridSelectorIcon.tsx index c1fad8ab2..65eb8a1d1 100644 --- a/packages/web/components/elements/images/GridSelectorIcon.tsx +++ b/packages/web/components/elements/images/GridSelectorIcon.tsx @@ -15,34 +15,24 @@ export function GridSelectorIcon(props: GridSelectorIconProps): JSX.Element { fill="none" xmlns="http://www.w3.org/2000/svg" > - + - - - - - ) } diff --git a/packages/web/components/elements/images/ListSelectorIcon.tsx b/packages/web/components/elements/images/ListSelectorIcon.tsx index fafcc14fa..5702b29f2 100644 --- a/packages/web/components/elements/images/ListSelectorIcon.tsx +++ b/packages/web/components/elements/images/ListSelectorIcon.tsx @@ -15,30 +15,20 @@ export function ListSelectorIcon(props: ListSelectorIconProps): JSX.Element { fill="none" xmlns="http://www.w3.org/2000/svg" > - + - - - - - ) } diff --git a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx index ca8a66a3a..bbfd0520b 100644 --- a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx +++ b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx @@ -578,6 +578,7 @@ export function HomeFeedContainer(): JSX.Element { searchTerm={queryInputs.searchQuery} gridContainerRef={gridContainerRef} applySearchQuery={(searchQuery: string) => { + console.log('TOP LEVEL SETTING QUERY INPUTS: ', searchQuery) setQueryInputs({ ...queryInputs, searchQuery, @@ -781,8 +782,13 @@ function HomeFeedGrid(props: HomeFeedContentProps): JSX.Element { return ( { + console.log('searching with searchQuery: ', searchQuery) + props.applySearchQuery(searchQuery) + }} /> - + { + console.log('searching with searchQuery: ', searchQuery) + props.applySearchQuery(searchQuery) + }} + /> void + + searchTerm: string | undefined + applySearchQuery: (searchTerm: string) => void +} + +export function LibraryFilterMenu(props: LibraryFilterMenuProps): JSX.Element { return ( <> - - - + + + - + props.setShowAddLinkModal(true)} + /> {/* This spacer pushes library content to the right of the fixed left side menu. */} @@ -67,19 +78,45 @@ export function LibraryFilterMenu(): JSX.Element { ) } -function SavedSearches(): JSX.Element { +function SavedSearches(props: LibraryFilterMenuProps): JSX.Element { return ( - - - - + + + + + ) } -function Subscriptions(): JSX.Element { +function Subscriptions(props: LibraryFilterMenuProps): JSX.Element { const { subscriptions } = useGetSubscriptionsQuery() const [viewAll, setViewAll] = useState(false) @@ -92,14 +129,21 @@ function Subscriptions(): JSX.Element { }} > {subscriptions.slice(0, viewAll ? undefined : 4).map((item) => { - return + return ( + + ) })} ) } -function Labels(): JSX.Element { +function Labels(props: LibraryFilterMenuProps): JSX.Element { const { labels } = useGetLabelsQuery() const [viewAll, setViewAll] = useState(false) @@ -112,7 +156,7 @@ function Labels(): JSX.Element { }} > {labels.slice(0, viewAll ? undefined : 4).map((item) => { - return + return })} @@ -185,10 +229,20 @@ function MenuPanel(props: MenuPanelProps): JSX.Element { type FilterButtonProps = { text: string spaced?: boolean - selected: boolean + + filterTerm: string + searchTerm: string | undefined + applySearchQuery: (searchTerm: string) => void } function FilterButton(props: FilterButtonProps): JSX.Element { + const selected = useMemo(() => { + if (props.filterTerm === '' && !props.searchTerm) { + return true + } + return props.searchTerm === props.filterTerm + }, [props.searchTerm, props.filterTerm]) + return ( { + props.applySearchQuery(props.filterTerm) + e.preventDefault() }} > {props.text} @@ -212,10 +277,21 @@ function FilterButton(props: FilterButtonProps): JSX.Element { type LabelButtonProps = { label: Label - state: 'on' | 'off' | 'unset' + searchTerm: string | undefined + applySearchQuery: (searchTerm: string) => void } function LabelButton(props: LabelButtonProps): JSX.Element { + const state = useMemo(() => { + const term = props.searchTerm ?? '' + if (term.indexOf(`label:\"${props.label.name}\"`) >= 0) { + console.log('returning true for: ', term) + return 'on' + } + console.log('returning off for: ', term) + return 'off' + }, [props.searchTerm, props.label]) + return ( {props.label.name} - + { + console.log('changing check state') + if (e.target.checked) { + props.applySearchQuery + props.applySearchQuery( + `${props.searchTerm} label:\"${props.label.name}\"` + ) + } else { + const query = + props.searchTerm?.replace( + `label:\"${props.label.name}\"`, + '' + ) ?? '' + props.applySearchQuery(query) + } + }} + /> ) } -function AddLinkButton(): JSX.Element { +type AddLinkButtonProps = { + showAddLinkModal: () => void +} + +function AddLinkButton(props: AddLinkButtonProps): JSX.Element { return ( { + props.showAddLinkModal() + e.preventDefault() + }} > Add Link diff --git a/packages/web/components/templates/homeFeed/LibraryHeader.tsx b/packages/web/components/templates/homeFeed/LibraryHeader.tsx index 2fd2d6793..9911fbb1d 100644 --- a/packages/web/components/templates/homeFeed/LibraryHeader.tsx +++ b/packages/web/components/templates/homeFeed/LibraryHeader.tsx @@ -1,6 +1,7 @@ import { InputHTMLAttributes, ReactNode, + useCallback, useEffect, useRef, useState, @@ -8,7 +9,7 @@ import { import { StyledText } from '../../elements/StyledText' import { Box, HStack, SpanBox, VStack } from '../../elements/LayoutPrimitives' import { SearchIcon } from '../../elements/images/SearchIcon' -import { theme } from '../../tokens/stitches.config' +import { theme, ThemeId } from '../../tokens/stitches.config' import { Dropdown, DropdownOption } from '../../elements/DropdownElements' import { FormInput } from '../../elements/FormElements' import { searchBarCommands } from '../../../lib/keyboardShortcuts/navigationShortcuts' @@ -20,48 +21,25 @@ import { OmnivoreFullLogo } from '../../elements/images/OmnivoreFullLogo' import { AvatarDropdown } from '../../elements/AvatarDropdown' import { ListSelectorIcon } from '../../elements/images/ListSelectorIcon' import { GridSelectorIcon } from '../../elements/images/GridSelectorIcon' +import { LayoutType } from './HomeFeedContainer' +import { DropdownMenu, HeaderDropdownAction } from '../../patterns/DropdownMenu' +import { updateTheme } from '../../../lib/themeUpdater' +import { useRouter } from 'next/router' -type LibrarySearchBarProps = { - searchTerm?: string +type LibraryHeaderProps = { + layout: LayoutType + updateLayout: (layout: LayoutType) => void + + searchTerm: string | undefined applySearchQuery: (searchQuery: string) => void } -type LibraryFilter = - | 'in:inbox' - | 'in:all' - | 'in:archive' - | 'type:file' - | 'type:highlights' - | `saved:${string}` - | `sort:read` - -// get last week's date -const recentlySavedStartDate = new Date( - new Date().getTime() - 7 * 24 * 60 * 60 * 1000 -).toLocaleDateString('en-US') - const FOCUSED_BOXSHADOW = '0px 0px 2px 2px rgba(255, 234, 159, 0.56)' const HEADER_HEIGHT = '105px' -const MOBILE_HEIGHT = '44px' - -export function LibraryHeader(props: LibrarySearchBarProps): JSX.Element { - const [focused, setFocused] = useState(false) - const inputRef = useRef(null) - const [searchTerm, setSearchTerm] = useState(props.searchTerm || '') - - useEffect(() => { - setSearchTerm(props.searchTerm || '') - }, [props.searchTerm]) - - useKeyboardShortcuts( - searchBarCommands((action) => { - if (action === 'focusSearchBar' && inputRef.current) { - inputRef.current.select() - } - }) - ) +const MOBILE_HEIGHT = '48px' +export function LibraryHeader(props: LibraryHeaderProps): JSX.Element { return ( <> - + {/* This spacer is put in to push library content down @@ -111,10 +92,23 @@ export function LibraryHeader(props: LibrarySearchBarProps): JSX.Element { ) } -function SearchBox(props: LibrarySearchBarProps): JSX.Element { +type SearchBoxProps = { + searchTerm: string | undefined + applySearchQuery: (searchQuery: string) => void +} + +function SearchBox(props: SearchBoxProps): JSX.Element { const inputRef = useRef(null) const [focused, setFocused] = useState(false) - const [searchTerm, setSearchTerm] = useState('') + const [searchTerm, setSearchTerm] = useState(props.searchTerm ?? '') + + useKeyboardShortcuts( + searchBarCommands((action) => { + if (action === 'focusSearchBar' && inputRef.current) { + inputRef.current.select() + } + }) + ) return ( { + inputRef.current?.focus() + e.preventDefault() + }} > - {searchTerm ? ( + {props.searchTerm ? ( + + + } + actionHandler={headerDropdownActionHandler} + />