Skip to content

Commit

Permalink
Also highlight matches in proposal search results
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Feb 2, 2024
1 parent 81f588c commit 5b9aacf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/app/pages/ProposalDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import InfoIcon from '@mui/icons-material/Info'
import { useRequiredScopeParam } from '../../hooks/useScopeParam'
import { Layer, Proposal, useGetConsensusProposalsProposalId } from '../../../oasis-nexus/api'
import { AppErrors } from '../../../types/errors'
import { useParams } from 'react-router-dom'
import { useLoaderData } from 'react-router-dom'
import { PageLayout } from '../../components/PageLayout'
import { SubPageCard } from '../../components/SubPageCard'
import { StyledDescriptionList } from 'app/components/StyledDescriptionList'
Expand All @@ -16,6 +16,8 @@ import { useScreenSize } from '../../hooks/useScreensize'
import { ProposalStatusIcon } from '../../components/Proposals/ProposalStatusIcon'
import { TextSkeleton } from '../../components/Skeleton'
import { AccountLink } from '../../components/Account/AccountLink'
import { HighlightedText } from '../../components/HighlightedText'
import { ProposalIdLoaderData } from '../../utils/route-utils'
import { COLORS } from 'styles/theme/colors'
import { getTypeNameForProposal } from '../../../types/proposalType'

Expand All @@ -25,7 +27,7 @@ export const ProposalDetailsPage: FC = () => {
if (scope.layer !== Layer.consensus) {
throw AppErrors.UnsupportedLayer
}
const proposalId = parseInt(useParams().proposalId!, 10)
const { proposalId, searchTerm } = useLoaderData() as ProposalIdLoaderData

const { isLoading, data } = useGetConsensusProposalsProposalId(scope.network, proposalId)
if (!data?.data && !isLoading) {
Expand All @@ -35,18 +37,19 @@ export const ProposalDetailsPage: FC = () => {
return (
<PageLayout>
<SubPageCard featured title={t('common.proposal')}>
<ProposalDetailView isLoading={isLoading} proposal={proposal} />
<ProposalDetailView isLoading={isLoading} proposal={proposal} highlightedPart={searchTerm} />
</SubPageCard>
</PageLayout>
)
}

export const ProposalDetailView: FC<{
proposal: Proposal
highlightedPart?: string
isLoading?: boolean
showLayer?: boolean
standalone?: boolean
}> = ({ proposal, isLoading, showLayer = false, standalone = false }) => {
}> = ({ proposal, highlightedPart, isLoading, showLayer = false, standalone = false }) => {
const { t } = useTranslation()
const { isMobile } = useScreenSize()
if (isLoading) return <TextSkeleton numberOfRows={7} />
Expand All @@ -68,7 +71,9 @@ export const ProposalDetailView: FC<{
<dd>{proposal.id}</dd>

<dt>{t('common.title')}</dt>
<dd>{proposal.handler}</dd>
<dd>
<HighlightedText text={proposal.handler} pattern={highlightedPart} />
</dd>

<dt>{t('common.type')}</dt>
<dd>{proposalType}</dd>
Expand Down
4 changes: 3 additions & 1 deletion src/app/pages/SearchResultsPage/SearchResultsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export const SearchResultsList: FC<{
<ResultsGroupByType
title={t('search.results.proposals.title')}
results={searchResults.filter((item): item is ProposalResult => item.resultType === 'proposal')}
resultComponent={item => <ProposalDetailView proposal={item} showLayer />}
resultComponent={item => (
<ProposalDetailView proposal={item} highlightedPart={searchTerm} showLayer />
)}
link={proposal => RouteUtils.getProposalRoute(proposal.network, proposal.id)}
linkLabel={t('search.results.proposals.viewLink')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function useRedirectIfSingleResult(
)}?q=${searchTerm}`
break
case 'proposal':
redirectTo = RouteUtils.getProposalRoute(item.network, item.id)
redirectTo = `${RouteUtils.getProposalRoute(item.network, item.id)}?q=${searchTerm}`
break
default:
exhaustedTypeWarning('Unexpected result type', item)
Expand Down
14 changes: 12 additions & 2 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const validateTxHashParam = (hash: string) => {
}
return true
}

export type AddressLoaderData = {
address: string
searchTerm: string
Expand Down Expand Up @@ -224,6 +225,15 @@ export const assertEnabledScope = ({
return { network, layer } as SearchScope
}

export const proposalIdParamLoader = async ({ params }: LoaderFunctionArgs) => {
return validateProposalIdParam(params.proposalId!)
export type ProposalIdLoaderData = {
proposalId: number
searchTerm: string
}

export const proposalIdParamLoader = async ({ params, request }: LoaderFunctionArgs) => {
validateProposalIdParam(params.proposalId!)
return {
proposalId: parseInt(params.proposalId!),
searchTerm: getSearchTermFromRequest(request),
}
}

0 comments on commit 5b9aacf

Please sign in to comment.