forked from knarakochkanian/game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanageCountriesHighlighting.ts
33 lines (31 loc) · 1.05 KB
/
manageCountriesHighlighting.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { DEFAULT_COLOR } from "../components/Map/theme";
import { TSetCountryColor, TFocusOnCountry, TSetCountryContourVisibility } from "../hooks/useManagePlaceClick";
import { removeFromPickedCountries, addToPickedCountries } from "../redux/features/generalSlice";
import { AppDispatch } from "../redux/store";
export type ManageCountriesHighlightingParameters = {
name: string,
pickedCountries: string[],
setCountryColor: TSetCountryColor,
focusOnCountry: TFocusOnCountry,
setCountryContourVisibility: TSetCountryContourVisibility,
highlightColor: string,
dispatch: AppDispatch,
}
export const manageCountriesHighlighting = ({
name,
pickedCountries,
setCountryColor,
focusOnCountry,
setCountryContourVisibility,
highlightColor,
dispatch,
}: ManageCountriesHighlightingParameters) => {
if (pickedCountries.includes(name)) {
dispatch(removeFromPickedCountries(name));
setCountryColor(name, DEFAULT_COLOR)
} else {
dispatch(addToPickedCountries(name));
setCountryColor(name, highlightColor)
focusOnCountry(name);
}
}