mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 16:51:42 +03:00
Merge pull request #4634 from tomholford/fix/leap-result-order
landscape: sort Leap search results
This commit is contained in:
commit
225ce93b4c
@ -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>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user