Don't show list of instances by default
Very basic sorting too
This commit is contained in:
parent
e88b24fe6f
commit
4aaf308d6e
|
@ -51,3 +51,11 @@
|
|||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#instances-eg {
|
||||
margin: 0.2em 0 0;
|
||||
padding: 8px;
|
||||
height: 2.5em;
|
||||
color: var(--text-insignificant-color);
|
||||
font-style: italic;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,24 @@ function Login() {
|
|||
submitInstance(instanceURL);
|
||||
};
|
||||
|
||||
const instancesSuggestions = instanceText
|
||||
? instancesList
|
||||
.filter((instance) => instance.includes(instanceText))
|
||||
.sort((a, b) => {
|
||||
// Move text that starts with instanceText to the start
|
||||
const aStartsWith = a
|
||||
.toLowerCase()
|
||||
.startsWith(instanceText.toLowerCase());
|
||||
const bStartsWith = b
|
||||
.toLowerCase()
|
||||
.startsWith(instanceText.toLowerCase());
|
||||
if (aStartsWith && !bStartsWith) return -1;
|
||||
if (!aStartsWith && bStartsWith) return 1;
|
||||
return 0;
|
||||
})
|
||||
.slice(0, 10)
|
||||
: [];
|
||||
|
||||
return (
|
||||
<main id="login" style={{ textAlign: 'center' }}>
|
||||
<form onSubmit={onSubmit}>
|
||||
|
@ -107,11 +125,9 @@ function Login() {
|
|||
setInstanceText(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<ul id="instances-suggestions">
|
||||
{instancesList
|
||||
.filter((instance) => instance.includes(instanceText))
|
||||
.slice(0, 10)
|
||||
.map((instance) => (
|
||||
{instancesSuggestions?.length > 0 ? (
|
||||
<ul id="instances-suggestions">
|
||||
{instancesSuggestions.map((instance) => (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
|
@ -124,7 +140,10 @@ function Login() {
|
|||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</ul>
|
||||
) : (
|
||||
<div id="instances-eg">e.g. “mastodon.social’</div>
|
||||
)}
|
||||
{/* <datalist id="instances-list">
|
||||
{instancesList.map((instance) => (
|
||||
<option value={instance} />
|
||||
|
|
Loading…
Reference in a new issue