Skip to content
Snippets Groups Projects

feat(background selector): added component to allow switch between backgrounds

Merged Tadeusz Miesiąc requested to merge feature/MIN-109-display-backgroud-images into development
3 unresolved threads

Description

Added component to allow background selection

Functionality

  • change background on switch
  • change query params on switch
  • load correct background on appload if query params are set

Additionally

  • Fixed issue with wrongly typed selector in background.selectors. It could lead to unexpected calling empty value which lead to crashing the app. It required some fixes in few tests.

Important

CSS are not ready yet! Waiting for design update.

Edited by Tadeusz Miesiąc

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
76 const buttonName = screen.getByTestId('background-dropdown-button-name');
77 await act(() => {
78 buttonName.click();
79 });
80
81 const backgroundButton = screen.getByText('Network');
82 await act(() => {
83 backgroundButton.click();
84 });
85
86 expect(store.getState().map.data.backgroundId).toBe(14);
87 });
88
89 describe('query params', () => {
90 it('should display default value when main background id is in query params', async () => {
91 (useRouter as jest.Mock).mockReturnValue({
  • 4 backgroundsDataSelector,
    5 mainBackgroundIdSelector,
    6 } from '@/redux/backgrounds/background.selectors';
    7 import { useAppSelector } from '@/redux/hooks/useAppSelector';
    8 import { twMerge } from 'tailwind-merge';
    9 import { Icon } from '@/shared/Icon';
    10 import { MapBackground } from '@/types/models';
    11 import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
    12 import { setMapBackground } from '@/redux/map/map.slice';
    13 import { useRouter } from 'next/router';
    14 import { parseQueryToTypes } from '@/utils/parseQueryToTypes';
    15
    16 const DEFAULT_TOGGLE_BUTTON_TEXT = 'Background';
    17
    18 export const BackgroundSelector = (): JSX.Element => {
    19 const [selectedItem, setSelectedItem] = useState<MapBackground | undefined>(undefined);
  • 11 import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
    12 import { setMapBackground } from '@/redux/map/map.slice';
    13 import { useRouter } from 'next/router';
    14 import { parseQueryToTypes } from '@/utils/parseQueryToTypes';
    15
    16 const DEFAULT_TOGGLE_BUTTON_TEXT = 'Background';
    17
    18 export const BackgroundSelector = (): JSX.Element => {
    19 const [selectedItem, setSelectedItem] = useState<MapBackground | undefined>(undefined);
    20 const dispatch = useAppDispatch();
    21 const { query } = useRouter();
    22 const backgrounds = useAppSelector(backgroundsDataSelector);
    23 const mainBackgroundId = useAppSelector(mainBackgroundIdSelector);
    24
    25 useEffect(() => {
    26 const onApplicationLoadSetInitialSelectedItem = (): void => {
  • RFC

    The concept is OK but I'm completely against doubling the state here. Both list of backgrounds and currently selected background id we should keep only in the Redux store. Is there a reason to do that here differently?

    First principle of Redux https://redux.js.org/understanding/thinking-in-redux/three-principles

  • added 1 commit

    • 3d70b54f - refactor: removed local state from background selector component

    Compare with previous version

  • Tadeusz Miesiąc mentioned in commit 9186428d

    mentioned in commit 9186428d

  • Please register or sign in to reply
    Loading