mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-23 17:16:26 +01:00
Don't show list of instances by default
Very basic sorting too
This commit is contained in:
parent
e88b24fe6f
commit
4aaf308d6e
2 changed files with 33 additions and 6 deletions
|
@ -51,3 +51,11 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 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);
|
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 (
|
return (
|
||||||
<main id="login" style={{ textAlign: 'center' }}>
|
<main id="login" style={{ textAlign: 'center' }}>
|
||||||
<form onSubmit={onSubmit}>
|
<form onSubmit={onSubmit}>
|
||||||
|
@ -107,11 +125,9 @@ function Login() {
|
||||||
setInstanceText(e.target.value);
|
setInstanceText(e.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{instancesSuggestions?.length > 0 ? (
|
||||||
<ul id="instances-suggestions">
|
<ul id="instances-suggestions">
|
||||||
{instancesList
|
{instancesSuggestions.map((instance) => (
|
||||||
.filter((instance) => instance.includes(instanceText))
|
|
||||||
.slice(0, 10)
|
|
||||||
.map((instance) => (
|
|
||||||
<li>
|
<li>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -125,6 +141,9 @@ function Login() {
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
) : (
|
||||||
|
<div id="instances-eg">e.g. “mastodon.social’</div>
|
||||||
|
)}
|
||||||
{/* <datalist id="instances-list">
|
{/* <datalist id="instances-list">
|
||||||
{instancesList.map((instance) => (
|
{instancesList.map((instance) => (
|
||||||
<option value={instance} />
|
<option value={instance} />
|
||||||
|
|
Loading…
Reference in a new issue