Skip to content

Commit

Permalink
Merge pull request #103 from berlin/staging
Browse files Browse the repository at this point in the history
Staging to Main
  • Loading branch information
dnsos authored Nov 24, 2022
2 parents 8d34d9c + 8bcaa6a commit d2d9c4b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 66 deletions.
2 changes: 0 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mapRawQueryToState } from '@lib/utils/queryUtil'
import { ParsedUrlQuery } from 'querystring'
import { StrictMode, FC } from 'react'
import { Banner } from '@components/Banner'
import { Head } from '@components/Head'
import '../src/style/global.css'
import { useMatomo } from '@lib/hooks/useMatomo'
Expand Down Expand Up @@ -31,7 +30,6 @@ const App: FC<{

return (
<StrictMode>
{pathname !== '/share' && <Banner />}
<Head pageTitle={pageProps.title || ''} />
{pathname !== '/share' && <Header {...pageProps.query} />}
<Component {...pageProps} query={parsedQuery} />
Expand Down
77 changes: 48 additions & 29 deletions pages/search.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { FC, useRef, useState } from 'react'
import React, { FC, useEffect, useRef, useState } from 'react'
import { supabase } from '@lib/requests/createSupabaseClient'
import { GetStaticProps } from 'next'
import classNames from 'classnames'
import { formatCurrency } from '@lib/utils/numberUtil'
import { Button } from '@components/Button'

export interface FilteredSearchResultsType {
id: string
Expand All @@ -22,7 +23,7 @@ export interface FilteredSearchResultsType {
kapitel_bezeichnung: string
}

const MAX_RENDERED_RESULTS = 500
const ITEMS_PER_PAGE = 100

const toTitleCase = (s: string): string =>
s.replace(/^_*(.)|_+(.)/g, (_s, c: string, d: string) =>
Expand Down Expand Up @@ -54,6 +55,11 @@ export const Search: FC = () => {
)
const [searchTerm, setSearchTerm] = useState<string | null>(null)
const [loading, setLoading] = useState(false)
const [itemsShown, setItemsShown] = useState(ITEMS_PER_PAGE)

useEffect(() => {
setItemsShown(ITEMS_PER_PAGE)
}, [searchTerm])

const form = useRef<HTMLFormElement>(null)
const handleClick: (
Expand Down Expand Up @@ -103,11 +109,7 @@ export const Search: FC = () => {
}
}
)
setResults(
mappedData.length > MAX_RENDERED_RESULTS
? mappedData.slice(0, MAX_RENDERED_RESULTS)
: mappedData
)
setResults(mappedData)
}
}

Expand Down Expand Up @@ -173,18 +175,15 @@ export const Search: FC = () => {
{!loading ? (
<div className="flex flex-col">
<div className="overflow-x-auto">
<div className="min-w-full py-2">
<div className="overflow-x-auto" id="results">
{results ? (
<>
<div className="min-w-full pt-2 pb-16">
{results ? (
<>
<div className="overflow-x-auto" id="results">
<div className="w-full flex justify-center mb-8">
<div>
{searchTerm ? (
<p>
{results.length}
{results.length === MAX_RENDERED_RESULTS &&
'+'}{' '}
Ergebnis
{results.length} Ergebnis
{results.length !== 1 && 'se'} für den Begriff{' '}
<span className="font-bold">{searchTerm}</span>
</p>
Expand All @@ -209,7 +208,7 @@ export const Search: FC = () => {
})}
</tr>
}
body={results.map((result) => {
body={results.slice(0, itemsShown).map((result) => {
return (
<tr key={result.id}>
{Object.keys(result).map((k, i) => {
Expand All @@ -231,26 +230,46 @@ export const Search: FC = () => {
)
})}
/>
</>
) : (
<div className="w-full flex justify-center mb-24">
<div className="">
{searchTerm ? (
<p>
Keine Ergebnisse für den Begriff{' '}
<span className="font-bold">{searchTerm}</span>
</p>
) : null}
</div>
{results.length > ITEMS_PER_PAGE && (
<div className="justify-center flex mt-8">
<Button
onClick={() =>
setItemsShown(itemsShown + ITEMS_PER_PAGE)
}
disabled={itemsShown >= results.length}
>
<span className="block">
{itemsShown >= results.length
? 'Keine weitere Suchergebnisse'
: 'Weitere Suchergebnisse anzeigen'}
<span className="font-normal text-xs block">
({Math.min(itemsShown, results.length)}/
{results.length})
</span>
</span>
</Button>
</div>
)}
</>
) : (
<div className="w-full flex justify-center mb-24">
<div className="">
{searchTerm ? (
<p>
Keine Ergebnisse für den Begriff{' '}
<span className="font-bold">{searchTerm}</span>
</p>
) : null}
</div>
)}
</div>
</div>
)}
</div>
</div>
</div>
) : (
<>
<div className="container flex justify-center">
<div className="container flex justify-center pb-20 mx-auto">
<div role="status">
<svg
aria-hidden="true"
Expand Down
35 changes: 0 additions & 35 deletions src/components/Banner/index.tsx

This file was deleted.

1 comment on commit d2d9c4b

@vercel
Copy link

@vercel vercel bot commented on d2d9c4b Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.