Skip to content

Commit

Permalink
Merge pull request #56 from StarsbySea/search-bug-fix
Browse files Browse the repository at this point in the history
Respect URL params & display correct bucket content
  • Loading branch information
gpailler committed May 6, 2023
2 parents c12c9b6 + ab859ed commit 6d45590
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/Buckets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const Buckets = (): JSX.Element => {
<Link
to={{
pathname: '/apps',
search: `?q="${encodeURIComponent(item.bucket)}"`,
search: `?q="${encodeURIComponent(item.bucket)}"${item.official ? '' : '&o=false'}`,
}}
>
{Utils.extractPathFromUrl(item.bucket)}
Expand Down
13 changes: 9 additions & 4 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ const Search = (): JSX.Element => {
}, [getCurrentPageFromSearchParams]);

useEffect(() => {
updateSearchParams(SEARCH_PARAM_SORT_INDEX, sortIndex.toString(), true);
updateSearchParams(SEARCH_PARAM_SORT_DIRECTION, sortDirection.toString(), true);
updateSearchParams(SEARCH_PARAM_FILTER_OFFICIALONLY, searchOfficialOnly.toString(), true);
}, [updateSearchParams, sortIndex, sortDirection, searchOfficialOnly]);
const sortIndexFromUrl = getSortIndexFromSearchParams();
const sortDirectionFromUrl = getSortDirectionFromSearchParams(sortIndexFromUrl);
setSortIndex(sortIndexFromUrl);
setSortDirection(sortDirectionFromUrl);
setSearchOfficialOnly(getSearchOfficialOnlyFromSearchParams());
}, [getSortIndexFromSearchParams, getSortDirectionFromSearchParams, getSearchOfficialOnlyFromSearchParams]);

useEffect(() => {
if (searchResults?.results && selectedResultId) {
Expand Down Expand Up @@ -190,11 +192,14 @@ const Search = (): JSX.Element => {
);

const handleSortChange = (newSortIndex: number, newSortDirection: SortDirection): void => {
updateSearchParams(SEARCH_PARAM_SORT_INDEX, newSortIndex.toString(), true);
updateSearchParams(SEARCH_PARAM_SORT_DIRECTION, newSortDirection.toString(), true);
setSortIndex(newSortIndex);
setSortDirection(newSortDirection);
};

const handleSearchOfficialOnlyChange = (newSearchOfficialOnly: boolean): void => {
updateSearchParams(SEARCH_PARAM_FILTER_OFFICIALONLY, newSearchOfficialOnly.toString(), true);
setSearchOfficialOnly(newSearchOfficialOnly);
};

Expand Down

0 comments on commit 6d45590

Please sign in to comment.