Skip to content
Snippets Groups Projects
Commit 8b5ac299 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

toggle comments is working

parent 122b61c5
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!200Resolve "[MIN-113] Show comments on the map"
...@@ -11,6 +11,8 @@ import { Icon } from '@/shared/Icon'; ...@@ -11,6 +11,8 @@ import { Icon } from '@/shared/Icon';
import { MouseEvent } from 'react'; import { MouseEvent } from 'react';
import { twMerge } from 'tailwind-merge'; import { twMerge } from 'tailwind-merge';
import { getComments } from '@/redux/comment/thunks/getComments'; import { getComments } from '@/redux/comment/thunks/getComments';
import { commentSelector } from '@/redux/comment/comment.selectors';
import { hideComments, showComments } from '@/redux/comment/comment.slice';
export const MapNavigation = (): JSX.Element => { export const MapNavigation = (): JSX.Element => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
...@@ -21,6 +23,8 @@ export const MapNavigation = (): JSX.Element => { ...@@ -21,6 +23,8 @@ export const MapNavigation = (): JSX.Element => {
const isActive = (modelId: number): boolean => currentModelId === modelId; const isActive = (modelId: number): boolean => currentModelId === modelId;
const isNotMainMap = (modelName: string): boolean => modelName !== MAIN_MAP; const isNotMainMap = (modelName: string): boolean => modelName !== MAIN_MAP;
const commentsOpen = useAppSelector(commentSelector).isOpen;
const onCloseSubmap = (event: MouseEvent<HTMLDivElement>, map: OppenedMap): void => { const onCloseSubmap = (event: MouseEvent<HTMLDivElement>, map: OppenedMap): void => {
event.stopPropagation(); event.stopPropagation();
if (isActive(map.modelId)) { if (isActive(map.modelId)) {
...@@ -47,7 +51,12 @@ export const MapNavigation = (): JSX.Element => { ...@@ -47,7 +51,12 @@ export const MapNavigation = (): JSX.Element => {
}; };
const toggleComments = async (): Promise<void> => { const toggleComments = async (): Promise<void> => {
await dispatch(getComments()); if (!commentsOpen) {
await dispatch(getComments());
dispatch(showComments());
} else {
dispatch(hideComments());
}
}; };
return ( return (
......
...@@ -5,22 +5,26 @@ import { Geometry } from 'ol/geom'; ...@@ -5,22 +5,26 @@ import { Geometry } from 'ol/geom';
import VectorLayer from 'ol/layer/Vector'; import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector'; import VectorSource from 'ol/source/Vector';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { allCommentsSelectorOfCurrentMap } from '@/redux/comment/comment.selectors'; import {
allCommentsSelectorOfCurrentMap,
commentSelector,
} from '@/redux/comment/comment.selectors';
import { getCommentsFeatures } from '@/components/Map/MapViewer/utils/config/commentsLayer/getCommentsFeatures'; import { getCommentsFeatures } from '@/components/Map/MapViewer/utils/config/commentsLayer/getCommentsFeatures';
import { useMemo } from 'react'; import { useMemo } from 'react';
export const useOlMapCommentsLayer = (): VectorLayer<VectorSource<Feature<Geometry>>> => { export const useOlMapCommentsLayer = (): VectorLayer<VectorSource<Feature<Geometry>>> => {
const pointToProjection = usePointToProjection(); const pointToProjection = usePointToProjection();
const comments = useSelector(allCommentsSelectorOfCurrentMap); const comments = useSelector(allCommentsSelectorOfCurrentMap);
const isVisible = useSelector(commentSelector).isOpen;
const elementsFeatures = useMemo( const elementsFeatures = useMemo(
() => () =>
[ [
getCommentsFeatures(comments, { getCommentsFeatures(isVisible ? comments : [], {
pointToProjection, pointToProjection,
}), }),
].flat(), ].flat(),
[comments, pointToProjection], [comments, pointToProjection, isVisible],
); );
const vectorSource = useMemo(() => { const vectorSource = useMemo(() => {
......
...@@ -11,4 +11,5 @@ export const COMMENT_INITIAL_STATE: CommentsState = { ...@@ -11,4 +11,5 @@ export const COMMENT_INITIAL_STATE: CommentsState = {
data: [], data: [],
loading: 'idle', loading: 'idle',
error: { name: '', message: '' }, error: { name: '', message: '' },
isOpen: false,
}; };
...@@ -5,4 +5,5 @@ export const COMMENT_INITIAL_STATE_MOCK: CommentsState = { ...@@ -5,4 +5,5 @@ export const COMMENT_INITIAL_STATE_MOCK: CommentsState = {
data: [], data: [],
loading: 'idle', loading: 'idle',
error: DEFAULT_ERROR, error: DEFAULT_ERROR,
isOpen: false,
}; };
...@@ -11,7 +11,16 @@ export const getCommentsReducer = (builder: ActionReducerMapBuilder<CommentsStat ...@@ -11,7 +11,16 @@ export const getCommentsReducer = (builder: ActionReducerMapBuilder<CommentsStat
state.loading = 'succeeded'; state.loading = 'succeeded';
state.data = action.payload; state.data = action.payload;
}); });
builder.addCase(getComments.rejected, state => { builder.addCase(getComments.rejected, state => {
state.loading = 'failed'; state.loading = 'failed';
}); });
}; };
export const showCommentsReducer = (state: CommentsState): void => {
state.isOpen = true;
};
export const hideCommentsReducer = (state: CommentsState): void => {
state.isOpen = false;
};
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import { COMMENT_INITIAL_STATE } from '@/redux/comment/comment.constants'; import { COMMENT_INITIAL_STATE } from '@/redux/comment/comment.constants';
import { getCommentsReducer } from '@/redux/comment/comment.reducers'; import {
getCommentsReducer,
hideCommentsReducer,
showCommentsReducer,
} from '@/redux/comment/comment.reducers';
export const commentsSlice = createSlice({ export const commentsSlice = createSlice({
name: 'comments', name: 'comments',
initialState: COMMENT_INITIAL_STATE, initialState: COMMENT_INITIAL_STATE,
reducers: {}, reducers: {
showComments: showCommentsReducer,
hideComments: hideCommentsReducer,
},
extraReducers: builder => { extraReducers: builder => {
getCommentsReducer(builder); getCommentsReducer(builder);
}, },
}); });
export const { showComments, hideComments } = commentsSlice.actions;
export default commentsSlice.reducer; export default commentsSlice.reducer;
import { FetchDataState } from '@/types/fetchDataState'; import { FetchDataState } from '@/types/fetchDataState';
import { Comment } from '@/types/models'; import { Comment } from '@/types/models';
export type CommentsState = FetchDataState<Comment[], []>; export interface CommentsState extends FetchDataState<Comment[], []> {
isOpen: boolean;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment