Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement post search; refs #137 #201

Merged
merged 8 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/Article/Article.Blocks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useArticleContainerContext } from '@/containers/ArticleContainer.Context'
import { useIntersectionObserver } from '@/utils/ui.utils'
import { useMemo } from 'react'
import { usePostSearch } from '../../containers/PostSearchContainer/PostSearch.context'
import { LPE } from '../../types/lpe.types'
import { RenderArticleBlock } from './Article.Block'

Expand All @@ -12,7 +13,9 @@ const ArticleBlocks = ({ data }: Props) => {
const { setTocId, tocId } = useArticleContainerContext()
const headingElementsRef = useIntersectionObserver(setTocId)

const blocks = useMemo(
const search = usePostSearch()

const filteredBlocks = useMemo(
() =>
data.content.filter(
(b) =>
Expand All @@ -24,6 +27,11 @@ const ArticleBlocks = ({ data }: Props) => {
[data.content],
)

const blocks =
search.active && !search.isInitialLoading
? search.results.map((i) => i.data)
: filteredBlocks

return blocks.length ? (
<>
{blocks.map((block, idx) => (
Expand Down
13 changes: 9 additions & 4 deletions src/components/Article/Article.Body.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import styled from '@emotion/styled'

import { LPE } from '../../types/lpe.types'
import ArticleBlocks from './Article.Blocks'
import ArticleFooter from './Footer/Article.Footer'
import ArticleHeader from './Header/Article.Header'

interface Props {
data: LPE.Article.Document
header?: boolean
footer?: boolean
}

export default function ArticleBody({ data }: Props) {
export default function ArticleBody({
data,
header = true,
footer = true,
}: Props) {
return (
<ArticleContainer>
<ArticleHeader {...data.data} />
{header && <ArticleHeader {...data.data} />}
<ArticleBlocks data={data.data} />
<ArticleFooter data={data} />
{footer && <ArticleFooter data={data} />}
</ArticleContainer>
)
}
Expand Down
26 changes: 16 additions & 10 deletions src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,31 @@ export default function NavBar({ defaultState }: NavBarProps) {
defaultState && state.state.set((value) => ({ ...value, ...defaultState }))
}, [defaultState])

const searchButton =
state.showSearchButton.get() &&
(!!state.onSearch ? (
<IconButton size={'small'} onClick={() => state.onSearch!()}>
<SearchIcon color={'primary'} />
</IconButton>
) : (
<Link href={'/search'}>
<IconButton size={'small'}>
<SearchIcon color={'primary'} />
</IconButton>
</Link>
))

const buttons = (
<>
<Buttons>
<ThemeSwitch
toggle={themeState.toggleMode}
mode={themeState.get().mode}
/>
<Link href={'/search'}>
<IconButton size={'small'}>
<SearchIcon color={'primary'} />
</IconButton>
</Link>
{searchButton}
</Buttons>
<Buttons mobile>
<Link href={'/search'}>
<IconButton size={'small'}>
<SearchIcon color={'primary'} />
</IconButton>
</Link>
{searchButton}

<IconButton size={'small'} onClick={toggleMobileMenu}>
{showMobileMenu ? (
Expand Down
Loading
Loading