Add search page

This commit is contained in:
James Grugett 2022-09-13 22:48:52 -05:00
parent c11a5c3c2f
commit a06c659cc8
2 changed files with 32 additions and 6 deletions

View File

@ -102,7 +102,7 @@ function SearchSection(props: {
<Col> <Col>
<SectionHeader <SectionHeader
label={label} label={label}
href={`/home?s=${sort}${pill ? `&p=${pill}` : ''}`} href={`/search?s=${sort}${pill ? `&p=${pill}` : ''}`}
/> />
<ContractSearch <ContractSearch
user={user} user={user}
@ -185,11 +185,12 @@ function DailyProfitAndBalance(props: {
const metrics = usePortfolioHistory(user?.id ?? '', 'daily') ?? [] const metrics = usePortfolioHistory(user?.id ?? '', 'daily') ?? []
const [first, last] = [metrics[0], metrics[metrics.length - 1]] const [first, last] = [metrics[0], metrics[metrics.length - 1]]
if (first === undefined || last === undefined) return null let profit = 0
let profitPercent = 0
const profit = if (first && last) {
calculatePortfolioProfit(last) - calculatePortfolioProfit(first) profit = calculatePortfolioProfit(last) - calculatePortfolioProfit(first)
const profitPercent = profit / first.investmentValue profitPercent = profit / first.investmentValue
}
return ( return (
<Row className={'gap-4'}> <Row className={'gap-4'}>

25
web/pages/search.tsx Normal file
View File

@ -0,0 +1,25 @@
import { Page } from 'web/components/page'
import { Col } from 'web/components/layout/col'
import { ContractSearch } from 'web/components/contract-search'
import { useTracking } from 'web/hooks/use-tracking'
import { useUser } from 'web/hooks/use-user'
import { usePrefetch } from 'web/hooks/use-prefetch'
export default function Search() {
const user = useUser()
usePrefetch(user?.id)
useTracking('view search')
return (
<Page>
<Col className="mx-auto w-full p-2">
<ContractSearch
user={user}
persistPrefix="search"
useQueryUrlParam={true}
/>
</Col>
</Page>
)
}