From 61d3373c89cc89236ed25f0e44f75b6fd08f12e7 Mon Sep 17 00:00:00 2001 From: evlist Date: Tue, 11 Oct 2022 23:21:59 +0200 Subject: [PATCH] Missing file... --- src/components/map/OsmNotesChat.tsx | 143 ++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/components/map/OsmNotesChat.tsx diff --git a/src/components/map/OsmNotesChat.tsx b/src/components/map/OsmNotesChat.tsx new file mode 100644 index 0000000..6ad15dd --- /dev/null +++ b/src/components/map/OsmNotesChat.tsx @@ -0,0 +1,143 @@ +import React, { useState } from 'react'; +import { + MainContainer, + Sidebar, + ConversationList, + Conversation, + ConversationHeader, + ChatContainer, + MessageList, + Message, + Avatar, +} from '@chatscope/chat-ui-kit-react'; +import '@chatscope/chat-ui-kit-styles/dist/default/styles.min.css'; + +import { useSelector } from 'react-redux'; +import i18n from '../../i18n'; +import { geoPoint } from '../../lib/geo'; +import { MapState } from '../../store/map'; +import AvatarForLocation from './AvatarForLocation'; +interface OsmNotesChatProps { + notes: { features: any }; +} + +const OsmNotesChat: React.FC = ( + props: OsmNotesChatProps +) => { + const scope = useSelector((state: { map: MapState }) => state.map.scope); + + const [noteIndex, setNoteIndex] = useState(0); + const conversationClickHandlerFactory = (index: number) => (event: any) => { + setNoteIndex(index); + }; + + const roughDistance = (a: geoPoint, b: geoPoint): number => { + const pseudoDistanceInDegrees = Math.sqrt( + (a.lat - b.lat) ** 2 + (a.lon - b.lon) ** 2 + ); + const metresPerDegree = + 111111 * Math.cos((scope.center.lat * Math.PI) / 180); + return pseudoDistanceInDegrees * metresPerDegree; + }; + + const AvatarForFeature: React.FC<{ + feature: any; + size: number; + as: any; + }> = (props: { feature: any; size: number; as: any }) => { + const distance = roughDistance(scope.center, { + lon: props.feature.geometry.coordinates[0], + lat: props.feature.geometry.coordinates[1], + }); + return ( + + + + ); + }; + + return ( +
+ + + + {props.notes + .features!.slice(0, 5) + .map((feature: any, index: number) => ( + + + + ))} + + + + + + + + {i18n.locationInfo!.at!( + roughDistance(scope.center, { + lon: props.notes.features[noteIndex].geometry + .coordinates[0], + lat: props.notes.features[noteIndex].geometry + .coordinates[1], + }) + )} + + + + + {noteIndex < props.notes.features.length && + props.notes.features[noteIndex].properties.comments.map( + (comment: any, index: number) => ( + + + + {comment.user ? comment.user : '??'} + + ) + )} + + + +
+ ); +}; + +export default OsmNotesChat;