Skip to content

Commit

Permalink
Merge pull request #72 from City-of-Helsinki/fix-ongoing-filter
Browse files Browse the repository at this point in the history
Fix the ongoing searches filter
  • Loading branch information
EmiliaMakelaVincit authored Sep 26, 2023
2 parents 7099253 + 23460f7 commit d69273b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
17 changes: 1 addition & 16 deletions src/mapSearch/mapSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import BlockLoader from '../loader/blockLoader';
import {
fetchPlotSearchAttributes,
fetchPlotSearches,
fetchPlotSearchStages,
fetchPlotSearchTypes,
} from '../plotSearch/actions';

import { ApiAttributes } from '../api/types';
import {
PlotSearch,
PlotSearchStage,
PlotSearchSubtype,
PlotSearchTarget,
PlotSearchType,
Expand All @@ -36,7 +34,6 @@ interface State {
plotSearches: Array<PlotSearch>;
plotSearchAttributes: ApiAttributes;
plotSearchTypes: Array<PlotSearchType>;
plotSearchStages: Array<PlotSearchStage>;
favourite: Favourite;
}

Expand All @@ -45,15 +42,13 @@ interface Props {
fetchPlotSearches: (payload?: { params: Record<string, string> }) => void;
fetchPlotSearchAttributes: () => void;
fetchPlotSearchTypes: () => void;
fetchPlotSearchStages: () => void;
isFetchingPlotSearches: boolean;
isFetchingPlotSearchAttributes: boolean;
isFetchingPlotSearchTypes: boolean;
isFetchingPlotSearchStages: boolean;
plotSearches: Array<PlotSearch>;
plotSearchAttributes: ApiAttributes;
plotSearchTypes: Array<PlotSearchType>;
plotSearchStages: Array<PlotSearchStage>;
favourite: Favourite;
}

Expand All @@ -76,13 +71,11 @@ const MapSearchPage = (props: Props): JSX.Element => {
fetchPlotSearches,
fetchPlotSearchAttributes,
fetchPlotSearchTypes,
fetchPlotSearchStages,
isFetchingPlotSearches,
isFetchingPlotSearchAttributes,
isFetchingPlotSearchTypes,
isFetchingPlotSearchStages,
plotSearchTypes,
plotSearchStages,
plotSearches,
favourite,
} = props;
Expand Down Expand Up @@ -139,15 +132,9 @@ const MapSearchPage = (props: Props): JSX.Element => {
useEffect(() => {
fetchPlotSearchAttributes();
fetchPlotSearchTypes();
fetchPlotSearchStages();
fetchPlotSearches({ params: { search_class: searchClass } });
}, []);

useEffect(() => {
if (!isFetchingPlotSearchStages && plotSearchStages.length > 0) {
fetchPlotSearches({ params: { search_class: searchClass } });
}
}, [isFetchingPlotSearchStages]);

useEffect(() => {
let newOptions = [...(plotSearchTypes || [])];

Expand Down Expand Up @@ -253,13 +240,11 @@ const mapStateToProps = (state: RootState): State => ({
state.plotSearch.isFetchingPlotSearchAttributes,
isFetchingPlotSearchTypes: state.plotSearch.isFetchingPlotSearchTypes,
isFetchingPlotSearchStages: state.plotSearch.isFetchingPlotSearchStages,
plotSearchStages: state.plotSearch.plotSearchStages,
favourite: state.favourite.favourite,
});

export default connect(mapStateToProps, {
fetchPlotSearches,
fetchPlotSearchAttributes,
fetchPlotSearchTypes,
fetchPlotSearchStages,
})(MapSearchPage);
16 changes: 15 additions & 1 deletion src/plotSearch/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
put,
select,
takeLatest,
take,
} from 'redux-saga/effects';
import {
fetchPlotSearchAttributesRequest,
Expand All @@ -22,8 +23,11 @@ import {
PlotSearchFromBackend,
PlotSearchStage,
FETCH_PLOT_SEARCH_STAGES,
PLOT_SEARCH_STAGES_NOT_FOUND,
RECEIVE_PLOT_SEARCH_STAGES,
} from './types';
import {
fetchPlotSearchStages,
plotSearchAttributesNotFound,
plotSearchesNotFound,
plotSearchStagesNotFound,
Expand All @@ -43,9 +47,19 @@ function* fetchPlotSearchesSaga({
payload,
}: FetchPlotSearchesAction): Generator<Effect, void, never> {
try {
const stages: Array<PlotSearchStage> = yield select(
let stages: Array<PlotSearchStage> = yield select(
(state: RootState) => state.plotSearch.plotSearchStages
);

if (!stages.length) {
yield put(fetchPlotSearchStages());
yield take([RECEIVE_PLOT_SEARCH_STAGES, PLOT_SEARCH_STAGES_NOT_FOUND]);

stages = yield select(
(state: RootState) => state.plotSearch.plotSearchStages
);
}

const ongoingId = stages.find((stage) => stage.stage === 'in_action')?.id;

if (!ongoingId) {
Expand Down

0 comments on commit d69273b

Please sign in to comment.