Skip to content

Commit

Permalink
hide search result text if empty query
Browse files Browse the repository at this point in the history
  • Loading branch information
the-kwisatz-haderach committed May 5, 2024
1 parent fef438c commit 3b26418
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
8 changes: 7 additions & 1 deletion components/ObituaryGrid/ObituaryGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
hasMore: boolean
isLoading: boolean
isLoadingNext: boolean
hasQuery: boolean
}

export default function ObituaryGrid({
Expand All @@ -22,11 +23,16 @@ export default function ObituaryGrid({
onLoadMore,
isLoading,
isLoadingNext,
hasQuery,
}: Props): ReactElement {
const { t } = useTranslation()
return (
<Contained my={{ base: 0, lg: 8 }}>
<ResultsDescription resultsCount={obituaries.length} hasMore={hasMore} />
<ResultsDescription
resultsCount={obituaries.length}
hasMore={hasMore}
hasQuery={hasQuery}
/>
{isLoading || obituaries.length > 0 ? (
<SimpleGrid spacing={4} columns={[1, 2, 3, 4]}>
{isLoading
Expand Down
9 changes: 7 additions & 2 deletions components/ObituaryGrid/ResultsDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { useTranslation } from 'next-i18next'
interface Props {
hasMore: boolean
resultsCount: number
hasQuery?: boolean
}

export const ResultsDescription = ({ resultsCount, hasMore }: Props) => {
export const ResultsDescription = ({
resultsCount,
hasMore,
hasQuery,
}: Props) => {
const { t } = useTranslation()
return (
<Text hidden={resultsCount < 1} textAlign="center" my={5}>
<Text hidden={!hasQuery || resultsCount < 1} textAlign="center" my={5}>
{t('search-results-found')}
{hasMore ? ' ' + t('search-results-over') : ' '} <b>{resultsCount}</b>{' '}
{t('search-results-result')}.
Expand Down
1 change: 1 addition & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
1 change: 1 addition & 0 deletions pages/[category]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default function Obituaries({
obituaries={data.pages.flatMap((page) => page.data)}
hasMore={hasNextPage}
onLoadMore={fetchNextPage}
hasQuery={query !== ''}
/>
<TopScroll
show={data.pages.some((page) => page.data.length > 10)}
Expand Down
1 change: 1 addition & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function Home({ story: initialStory }: Props): ReactElement {
obituaries={data.pages.flatMap((page) => page.data)}
hasMore={hasNextPage}
onLoadMore={fetchNextPage}
hasQuery={query !== ''}
/>
<TopScroll
show={data.pages?.some((page) => page.data.length > 10)}
Expand Down
20 changes: 16 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -17,14 +21,22 @@
"downlevelIteration": true,
"jsx": "preserve",
"baseUrl": ".",
"incremental": true
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": [
"src",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"lib/pathTranslations.js"
"lib/pathTranslations.js",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
"exclude": [
"node_modules"
]
}

0 comments on commit 3b26418

Please sign in to comment.