Merge pull request #4634 from tomholford/fix/leap-result-order

landscape: sort Leap search results
This commit is contained in:
matildepark 2021-03-23 16:14:18 -04:00 committed by GitHub
commit 225ce93b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -251,6 +251,15 @@ export function Omnibox(props: OmniboxProps) {
setQuery(event.target.value); setQuery(event.target.value);
}, []); }, []);
// Sort Omnibox results alphabetically
const sortResults = (a: Record<'title', string>, b: Record<'title', string>) => {
// Do not sort unless searching (preserves order of menu actions)
if (query === '') { return 0 };
if (a.title < b.title) { return -1 };
if (a.title > b.title) { return 1 };
return 0;
}
const renderResults = useCallback(() => { const renderResults = useCallback(() => {
return <Box return <Box
maxHeight={['200px', '400px']} maxHeight={['200px', '400px']}
@ -268,16 +277,18 @@ export function Omnibox(props: OmniboxProps) {
const sel = selected?.length ? selected[1] : ''; const sel = selected?.length ? selected[1] : '';
return (<Box key={i} width='max(50vw, 300px)' maxWidth='600px'> return (<Box key={i} width='max(50vw, 300px)' maxWidth='600px'>
{categoryTitle} {categoryTitle}
{categoryResults.map((result, i2) => ( {categoryResults
<OmniboxResult .sort(sortResults)
key={i2} .map((result, i2) => (
icon={result.app} <OmniboxResult
text={result.title} key={i2}
subtext={result.host} icon={result.app}
link={result.link} text={result.title}
navigate={() => navigate(result.app, result.link)} subtext={result.host}
selected={sel} link={result.link}
/> navigate={() => navigate(result.app, result.link)}
selected={sel}
/>
))} ))}
</Box> </Box>
); );