Skip to content

Commit

Permalink
Remove a few hooks (mozilla#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrice-acasandrei authored Oct 27, 2023
1 parent e241085 commit 7e81839
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 101 deletions.
19 changes: 0 additions & 19 deletions src/__tests__/hooks/useQueryParams.test.ts

This file was deleted.

14 changes: 9 additions & 5 deletions src/components/Search/FrameworkDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Tooltip from '@mui/material/Tooltip';
import { style, cssRule } from 'typestyle';

import { frameworkMap } from '../../common/constants';
import { useAppSelector } from '../../hooks/app';
import useHandleChangeFrameworkDropdown from '../../hooks/useHandleFrameworkDropdown';
import { useAppDispatch, useAppSelector } from '../../hooks/app';
import { updateFramework } from '../../reducers/FrameworkSlice';
import { Strings } from '../../resources/Strings';
import {
Spacing,
Expand Down Expand Up @@ -78,15 +78,19 @@ function FrameworkDropdown({ mode }: FrameworkDropdownProps) {
}),
};

const dispatch = useAppDispatch();
const frameworkId = useAppSelector((state) => state.framework.id);

const { handleChangeFrameworkDropdown } = useHandleChangeFrameworkDropdown();

const handleFrameworkSelect = async (event: SelectChangeEvent) => {
const id = +event.target.value as Framework['id'];
const name = frameworkMap[id];

await handleChangeFrameworkDropdown({ id, name });
dispatch(
updateFramework({
id,
name,
}),
);
};

return (
Expand Down
29 changes: 23 additions & 6 deletions src/components/Search/SearchDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import { style, cssRule } from 'typestyle';
import { repoMap } from '../../common/constants';
import { compareView } from '../../common/constants';
import { useAppSelector } from '../../hooks/app';
import useHandleChangeDropdown from '../../hooks/useHandleChangeDropdown';
import { useAppDispatch } from '../../hooks/app';
import { updateRepository } from '../../reducers/SearchSlice';
import {
ButtonsLightRaw,
ButtonsDarkRaw,
TooltipRaw,
FontsRaw,
Colors,
} from '../../styles';
import { fetchRecentRevisions } from '../../thunks/searchThunk';
import { InputType, ThemeMode, View } from '../../types/state';
import type { Repository } from '../../types/state';

interface SearchDropdownProps {
view: View;
Expand All @@ -31,13 +34,27 @@ function SearchDropdown({
searchType,
}: SearchDropdownProps) {
const size = view == compareView ? 'small' : undefined;
const { handleChangeDropdown } = useHandleChangeDropdown();
const searchState = useAppSelector((state) => state.search[searchType]);
const { repository } = searchState;
const repository = useAppSelector(
(state) => state.search[searchType].repository,
);
const dispatch = useAppDispatch();

const handleRepoSelect = async (event: SelectChangeEvent) => {
const selectedRepository = event.target.value;
await handleChangeDropdown({ selectedRepository, searchType });
const selectedRepository = event.target.value as Repository['name'];
dispatch(
updateRepository({
repository: selectedRepository,
searchType: searchType,
}),
);

// Fetch 10 most recent revisions when repository changes
await dispatch(
fetchRecentRevisions({
repository: selectedRepository,
searchType: searchType,
}),
);
};

cssRule('.MuiTooltip-popper', {
Expand Down
33 changes: 0 additions & 33 deletions src/hooks/useHandleChangeDropdown.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/hooks/useHandleFrameworkDropdown.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/hooks/useQueryParams.ts

This file was deleted.

0 comments on commit 7e81839

Please sign in to comment.