-
Notifications
You must be signed in to change notification settings - Fork 0
/
FailedSearchBar
52 lines (50 loc) · 1.5 KB
/
FailedSearchBar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const FailedSearchBar = ({ shown, onFormSubmit }) => {
const [allUsernames, setAllUsernames] = useState(null);
useEffect(() => {
fetch("https://ecranked.ddns.net/api/v1/user/@all")
.then(async (response) => {
const data = await response.json();
console.log("allUsernames code:" + response.statusCode);
if (response.status === 404) {
} else {
if (!response.ok) {
// get error message from body or default to response statusText
const error = (data && data.message) || response.statusText;
return Promise.reject(error);
}
console.log(data);
setAllUsernames(data);
}
})
.catch((error) => {
console.error("SetAllUsernames => There was an error!", error);
});
}, []);
return (
<FailedSearchBarStyle
style={
shown
? {
height: `600px`,
border: "1px solid #fff",
margin: "10px 10px 0px",
}
: {
height: `0px`,
border: "0px solid #222",
margin: "0px 10px 0px",
}
}
>
<FailedSearchBarTitleStyle>Could not find user</FailedSearchBarTitleStyle>
<AutoComplete
onFormSubmit={onFormSubmit}
options={allUsernames}
maxAllowed={6}
Box={autoCompleteBox}
OptionDiv={autoCompleteOptionDiv}
Input={autoCompleteInput}
></AutoComplete>
</FailedSearchBarStyle>
);
};