view as team or user search now uses prefix search for better results
This commit is contained in:
parent
2c859d9de9
commit
23a658d807
1 changed files with 15 additions and 3 deletions
|
|
@ -16,20 +16,32 @@ export default function TeamSearch(props: Props) {
|
||||||
const teamAPI = useTeamAPI();
|
const teamAPI = useTeamAPI();
|
||||||
const userAPI = useUserAPI();
|
const userAPI = useUserAPI();
|
||||||
const [selectedTeam, setSelectedTeam] = useState<Option | null>(null);
|
const [selectedTeam, setSelectedTeam] = useState<Option | null>(null);
|
||||||
|
const [handler, setHandler] = useState<NodeJS.Timeout | undefined>(undefined);
|
||||||
const [teams, setTeams] = useState<Option[]>([]);
|
const [teams, setTeams] = useState<Option[]>([]);
|
||||||
|
const [searchText, setSearchText] = useState("");
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [{ user }] = useGlobalState();
|
const [{ user }] = useGlobalState();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!setSearch) return;
|
||||||
|
if (searchText === undefined) return;
|
||||||
|
setHandler(setTimeout(() => {
|
||||||
|
setSearchText(searchText);
|
||||||
|
}, 750)); // Delay of 750ms
|
||||||
|
|
||||||
|
return () => clearTimeout(handler); // Cleanup on change
|
||||||
|
}, [searchText]);
|
||||||
|
|
||||||
const onChange = (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
const onChange = (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
||||||
setSearch(e.target.value);
|
setSearchText(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadTeams = useCallback(() => {
|
const loadTeams = useCallback(() => {
|
||||||
let options: Option[] = [];
|
let options: Option[] = [];
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
teamAPI
|
teamAPI
|
||||||
.listTeams(10, 0, "desc", undefined, search)
|
.listTeams(10, 0, "desc", undefined, undefined, undefined, undefined, search)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (loadUsers)
|
if (loadUsers)
|
||||||
options.push({
|
options.push({
|
||||||
|
|
@ -51,7 +63,7 @@ export default function TeamSearch(props: Props) {
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
if (loadUsers) {
|
if (loadUsers) {
|
||||||
userAPI
|
userAPI
|
||||||
.listUsers(10, 0, "desc", undefined, search)
|
.listUsers(10, 0, "desc", undefined, undefined, search)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
resp.users.forEach(user => {
|
resp.users.forEach(user => {
|
||||||
options.push({
|
options.push({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue