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

comment selector implemented

parent 4d971ccb
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"
/* eslint-disable no-magic-numbers */
import { usePointToProjection } from '@/utils/map/usePointToProjection';
import Feature from 'ol/Feature';
import { Geometry } from 'ol/geom';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import { useSelector } from 'react-redux';
import { allCommentsSelectorOfCurrentMap } from '@/redux/comment/comment.selectors';
import { getCommentsFeatures } from '@/components/Map/MapViewer/utils/config/commentsLayer/getCommentsFeatures';
import { useMemo } from 'react';
export const useOlMapCommentsLayer = (): VectorLayer<VectorSource<Feature<Geometry>>> => {
const pointToProjection = usePointToProjection();
const comments = useSelector(allCommentsSelectorOfCurrentMap);
const elementsFeatures = useMemo(
() =>
[
getCommentsFeatures(comments, {
pointToProjection,
}),
].flat(),
[comments, pointToProjection],
);
const vectorSource = useMemo(() => {
return new VectorSource({
features: [...elementsFeatures],
});
}, [elementsFeatures]);
const pinsLayer = useMemo(
() =>
new VectorLayer({
source: vectorSource,
}),
[vectorSource],
);
return pinsLayer;
};
import { rootSelector } from '@/redux/root/root.selectors';
import { createSelector } from '@reduxjs/toolkit';
import { CommentWithPinType } from '@/types/comment';
import { currentModelIdSelector } from '../models/models.selectors';
export const commentSelector = createSelector(rootSelector, state => state.comment);
export const allCommentsSelectorOfCurrentMap = createSelector(
commentSelector,
currentModelIdSelector,
(commentState, currentModelId): CommentWithPinType[] => {
if (!commentState) {
return [];
}
return (commentState.data || [])
.filter(comment => comment.modelId === currentModelId)
.map(comment => {
return {
...comment,
pinType: 'comment',
};
});
},
);
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