Skip to content
Snippets Groups Projects
modal.reducers.ts 1.47 KiB
Newer Older
Adrian Orłów's avatar
Adrian Orłów committed
import { ModalName } from '@/types/modal';
import { PayloadAction } from '@reduxjs/toolkit';
import { ModalState } from './modal.types';

export const openModalReducer = (state: ModalState, action: PayloadAction<ModalName>): void => {
  state.isOpen = true;
  state.modalName = action.payload;
};

export const closeModalReducer = (state: ModalState): void => {
  state.isOpen = false;
  state.modalName = 'none';
};

export const openOverviewImagesModalByIdReducer = (
  state: ModalState,
  action: PayloadAction<number>,
): void => {
Adrian Orłów's avatar
Adrian Orłów committed
  state.isOpen = true;
  state.modalName = 'overview-images';
  state.modalTitle = 'Overview images';
  state.overviewImagesState = {
    imageId: action.payload,
  };
Adrian Orłów's avatar
Adrian Orłów committed
};
Mateusz Bolewski's avatar
Mateusz Bolewski committed

export const openMolArtModalByIdReducer = (
  state: ModalState,
  action: PayloadAction<string | undefined>,
): void => {
  state.isOpen = true;
  state.modalName = 'mol-art';
  state.modalTitle = 'MolArt';
  state.molArtState = {
    uniprotId: action.payload,
  };
};
export const openLoginModalReducer = (state: ModalState): void => {
  state.isOpen = true;
  state.modalName = 'login';
  state.modalTitle = 'You need to login';
};

export const setOverviewImageIdReducer = (
  state: ModalState,
  action: PayloadAction<number>,
): void => {
  state.overviewImagesState = {
    imageId: action.payload,
  };
};

export const openPublicationsModalReducer = (state: ModalState): void => {
  state.isOpen = true;
  state.modalName = 'publications';
  state.modalTitle = 'Publications';
};