Search bar fixes and performance updates
This commit is contained in:
@@ -15,7 +15,7 @@ import { isNotEmpty, useForm } from '@mantine/form';
|
||||
import { useDebouncedValue, useDisclosure } from '@mantine/hooks';
|
||||
import { AddItemModal, NoItemsFound, SettingsHeader } from 'components';
|
||||
import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { FaTerminal } from 'react-icons/fa';
|
||||
import { FaComputer, FaDesktop } from 'react-icons/fa6';
|
||||
import { popoverClasses, selectClasses, textInputClasses } from 'styles';
|
||||
@@ -39,20 +39,24 @@ const GuacamoleClients = () => {
|
||||
},
|
||||
});
|
||||
const types: string[] = ['SSH', 'RDP', 'VNC'];
|
||||
const [searchValue, setSearchValue] = useState<string | number>('');
|
||||
const [debouncedSearch] = useDebouncedValue(searchValue, 500);
|
||||
const endpoint = 'api/guacamoleClients';
|
||||
const {
|
||||
data: guacamoleClientsData,
|
||||
isFetched: guacamoleClientsIsFetched,
|
||||
isFetching: guacamoleClientsIsFetching,
|
||||
} = useQueryAPI({
|
||||
endpoint: endpoint,
|
||||
});
|
||||
const [guacamoleClients, setGuacamoleClients] = useState<GuacamoleClient[]>([]);
|
||||
const { data: guacamoleClientsData, isFetching: guacamoleClientsIsFetching } =
|
||||
useQueryAPI({
|
||||
endpoint: endpoint,
|
||||
});
|
||||
const guacamoleClients =
|
||||
guacamoleClientsData.filter(
|
||||
(a: GuacamoleClient) =>
|
||||
a.clientName.toLowerCase().includes((debouncedSearch as string).toLowerCase()) ||
|
||||
a.clientIdentifier
|
||||
.toLowerCase()
|
||||
.includes((debouncedSearch as string).toLowerCase()),
|
||||
) || [];
|
||||
const { mutateAsync } = useMutationAPI();
|
||||
const { isMobile, theme } = useCommonHooks();
|
||||
const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false);
|
||||
const [searchValue, setSearchValue] = useState<string | number>('');
|
||||
const [debouncedSearch] = useDebouncedValue(searchValue, 500);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
@@ -61,25 +65,6 @@ const GuacamoleClients = () => {
|
||||
form.reset();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (guacamoleClientsData && guacamoleClientsIsFetched) {
|
||||
setGuacamoleClients(
|
||||
guacamoleClientsData.filter(
|
||||
(a: GuacamoleClient) =>
|
||||
a.clientName
|
||||
.toLowerCase()
|
||||
.includes((debouncedSearch as string).toLowerCase()) ||
|
||||
a.clientIdentifier
|
||||
.toLowerCase()
|
||||
.includes((debouncedSearch as string).toLowerCase()),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (debouncedSearch === searchValue) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [guacamoleClientsData, guacamoleClientsIsFetched, debouncedSearch]);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<AddItemModal
|
||||
|
||||
Reference in New Issue
Block a user