Skip to content

Commit

Permalink
Merge pull request #922 from OpenSourceBrain/feature/920
Browse files Browse the repository at this point in the history
#920 - fix latency in typing in search box
  • Loading branch information
filippomc authored Mar 26, 2024
2 parents 146943a + 91b17d8 commit 12d26d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
21 changes: 11 additions & 10 deletions applications/osb-portal/src/pages/Repositories/RepositoriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ export const RepositoriesPage = ({
navigate(`/repositories/${repositoryId}`);
};

const debouncedHandleSearchFilter = debounce((newTextFilter: string) => {
const debouncedHandleSearchFilter = (newTextFilter: string) => {
setSearchFilterValues({ ...searchFilterValues, text: newTextFilter });
}, 500);
debounce(() => updateReposList(newTextFilter), 500)();
};

const setReposValues = (reposDetails) => {
setRepositories(reposDetails.osbrepositories);
Expand All @@ -122,15 +123,15 @@ export const RepositoriesPage = ({
setLoading(false);
};

const updateReposList = () => {
const updateReposList = (updatedSearchFilterValues) => {
const isSearchFieldsEmpty =
searchFilterValues.tags.length === 0 &&
searchFilterValues.types.length === 0 &&
(typeof searchFilterValues.text === "undefined" ||
searchFilterValues.text === "");
updatedSearchFilterValues.tags.length === 0 &&
updatedSearchFilterValues.types.length === 0 &&
(typeof updatedSearchFilterValues.text === "undefined" ||
updatedSearchFilterValues.text === "");
setLoading(true);
if (!isSearchFieldsEmpty) {
const myReposFilter = tabValue ? {...searchFilterValues, user_id: user.id} : searchFilterValues
const myReposFilter = tabValue ? { ...updatedSearchFilterValues, user_id: user.id } : updatedSearchFilterValues

RepositoryService.getRepositoriesByFilter(
page,
Expand All @@ -152,7 +153,7 @@ export const RepositoriesPage = ({
};

const handleRefreshRepositories = () => {
updateReposList();
updateReposList(searchFilterValues);
}

const handleTabChange = (event: any, newValue: RepositoriesTab) => {
Expand Down Expand Up @@ -190,7 +191,7 @@ export const RepositoriesPage = ({
);
}
};
React.useEffect(updateReposList, [page, searchFilterValues, tabValue, counter]);
React.useEffect(() => updateReposList(searchFilterValues), [page, searchFilterValues, tabValue, counter]);

return (
<>
Expand Down
12 changes: 10 additions & 2 deletions applications/osb-portal/src/pages/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,20 @@ export const WorkspacesPage = (props: WorkspacesPageProps) => {
navigate(`/workspaces/${workspaceId}`);
};

const debouncedHandleSearchFilter = debounce((newTextFilter: string) => {

const debouncedHandleSearchFilter = (newTextFilter: string) => {
setSearchFilterValues({
...searchFilterValues,
text: newTextFilter,
});
}, 500);

debounce(() => {
getWorkspacesList({ searchFilterValues: { ...searchFilterValues, text: newTextFilter } });
}, 500);
};




const setWorkspacesValues = (workspacesDetails) => {
setWorkspaces(workspacesDetails.items);
Expand Down

0 comments on commit 12d26d8

Please sign in to comment.