-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a bookmark search and bookmark search suggestion feature. DD-78 #done
- Loading branch information
1 parent
9573c36
commit 135e48e
Showing
11 changed files
with
488 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { ReactElement } from 'react'; | ||
import Link from 'next/link'; | ||
import BookmarkIcon from '../../icons/bookmark.svg'; | ||
import { headerHeight } from '../styles/sizes'; | ||
import sizeN from '../../macros/sizeN.macro'; | ||
import { Button } from './buttons/Button'; | ||
|
||
export default function BookmarkEmptyScreen(): ReactElement { | ||
return ( | ||
<main | ||
className="flex fixed inset-0 flex-col justify-center items-center px-6 withNavBar text-theme-label-secondary" | ||
style={{ marginTop: headerHeight }} | ||
> | ||
<BookmarkIcon | ||
className="m-0 icon text-theme-label-tertiary" | ||
style={{ fontSize: sizeN(20) }} | ||
/> | ||
<h1 | ||
className="my-4 text-center text-theme-label-primary typo-title1" | ||
style={{ maxWidth: '32.5rem' }} | ||
> | ||
Your bookmark list is empty. | ||
</h1> | ||
<p className="mb-10 text-center" style={{ maxWidth: '32.5rem' }}> | ||
Go back to your feed and bookmark posts you’d like to keep or read | ||
later. Each post you bookmark will be stored here. | ||
</p> | ||
<Link href="/" passHref> | ||
<Button className="btn-primary" tag="a" buttonSize="large"> | ||
Back to feed | ||
</Button> | ||
</Link> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { | ||
ReactElement, | ||
ReactNode, | ||
useContext, | ||
useMemo, | ||
useState, | ||
} from 'react'; | ||
import Link from 'next/link'; | ||
import MagnifyingIcon from '../../icons/magnifying.svg'; | ||
import { BOOKMARKS_FEED_QUERY, SEARCH_BOOKMARKS_QUERY } from '../graphql/feed'; | ||
import AuthContext from '../contexts/AuthContext'; | ||
import { CustomFeedHeader, FeedPage } from './utilities'; | ||
import SearchEmptyScreen from './SearchEmptyScreen'; | ||
import Feed, { FeedProps } from './Feed'; | ||
import BookmarkEmptyScreen from './BookmarkEmptyScreen'; | ||
import { Button } from './buttons/Button'; | ||
|
||
export type BookmarkFeedLayoutProps = { | ||
isSearchOn: boolean; | ||
searchQuery?: string; | ||
children?: ReactNode; | ||
searchChildren: ReactNode; | ||
onSearchButtonClick?: () => unknown; | ||
}; | ||
|
||
export default function BookmarkFeedLayout({ | ||
searchQuery, | ||
isSearchOn, | ||
searchChildren, | ||
children, | ||
}: BookmarkFeedLayoutProps): ReactElement { | ||
const { user, tokenRefreshed } = useContext(AuthContext); | ||
const [showEmptyScreen, setShowEmptyScreen] = useState(false); | ||
|
||
const feedProps = useMemo<FeedProps<unknown>>(() => { | ||
if (isSearchOn && searchQuery) { | ||
return { | ||
feedQueryKey: ['bookmarks', user?.id ?? 'anonymous', searchQuery], | ||
query: SEARCH_BOOKMARKS_QUERY, | ||
variables: { query: searchQuery }, | ||
emptyScreen: <SearchEmptyScreen />, | ||
className: 'my-3', | ||
}; | ||
} | ||
return { | ||
feedQueryKey: ['bookmarks', user?.id ?? 'anonymous'], | ||
query: BOOKMARKS_FEED_QUERY, | ||
className: 'my-3', | ||
onEmptyFeed: () => setShowEmptyScreen(true), | ||
}; | ||
}, [isSearchOn && searchQuery, user]); | ||
|
||
if (showEmptyScreen) { | ||
return <BookmarkEmptyScreen />; | ||
} | ||
|
||
return ( | ||
<FeedPage> | ||
{children} | ||
<CustomFeedHeader className="relative"> | ||
{!isSearchOn && ( | ||
<> | ||
<Link href="/bookmarks/search"> | ||
<Button | ||
href="/bookmarks/search" | ||
aria-label="Search bookmarks" | ||
icon={<MagnifyingIcon />} | ||
/> | ||
</Link> | ||
<div className="mx-4 w-px h-full bg-theme-bg-tertiary"> </div> | ||
<span className="font-bold typo-callout">Bookmarks</span> | ||
</> | ||
)} | ||
{isSearchOn ? searchChildren : undefined} | ||
</CustomFeedHeader> | ||
{tokenRefreshed && <Feed {...feedProps} />} | ||
</FeedPage> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.