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);
}, []);
// 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(() => {
return <Box
maxHeight={['200px', '400px']}
@ -268,16 +277,18 @@ export function Omnibox(props: OmniboxProps) {
const sel = selected?.length ? selected[1] : '';
return (<Box key={i} width='max(50vw, 300px)' maxWidth='600px'>
{categoryTitle}
{categoryResults.map((result, i2) => (
<OmniboxResult
key={i2}
icon={result.app}
text={result.title}
subtext={result.host}
link={result.link}
navigate={() => navigate(result.app, result.link)}
selected={sel}
/>
{categoryResults
.sort(sortResults)
.map((result, i2) => (
<OmniboxResult
key={i2}
icon={result.app}
text={result.title}
subtext={result.host}
link={result.link}
navigate={() => navigate(result.app, result.link)}
selected={sel}
/>
))}
</Box>
);