diff --git a/src/ArticleCard.tsx b/src/ArticleCard.tsx index 7c47294..13fa42f 100644 --- a/src/ArticleCard.tsx +++ b/src/ArticleCard.tsx @@ -1,4 +1,6 @@ -import { createStyles, Card, Image, Avatar, Text, Group } from '@mantine/core'; +import { createStyles, Card, Image, Avatar, Text, Group, Center, rem } from '@mantine/core'; +import { IconCurrentLocation } from '@tabler/icons-react'; + const useStyles = createStyles((theme) => ({ card: { @@ -41,9 +43,10 @@ export function ArticleCardVertical({ category, title, address, + coordinates, // author, selected, - setSelected + handleAddressClick }: ArticleCardVerticalProps) { const { classes } = useStyles(); return ( @@ -57,9 +60,13 @@ export function ArticleCardVertical({ {title} - setSelected(id)} className={classes.address}> - • {address} - +
handleAddressClick(id)} className={classes.address}> + + {/* */} + + {address} + +
diff --git a/src/KartaPage.tsx b/src/KartaPage.tsx index ca45bf6..984d5e2 100644 --- a/src/KartaPage.tsx +++ b/src/KartaPage.tsx @@ -3,10 +3,11 @@ import { ArticleCardVertical } from './ArticleCard'; import articleCard from './assets/card.json'; import Map, {Source, Layer} from 'react-map-gl/maplibre'; import mapstyle from './assets/basemap.json'; -import { useState, useEffect } from 'react'; +import { useState, useEffect, useRef } from 'react'; import Fuse from 'fuse.js' export function KartaPage() { + const mapRef = useRef(null); const [initial, setInitial] = useState(null); const [articles, setArticles] = useState(null); const [search, setSearch] = useState(''); @@ -50,9 +51,15 @@ export function KartaPage() { setArticles(updatedArticles) }, [search]) + const handleAddressClick = (id) => { + setSelected(id) + id > 0 && articles && mapRef.current?.flyTo({ center: Object.values(articles.find(e => e.id == id).attributes.coordinates).slice(1) }) + } + return (
a.id)]} paint={{ - "circle-color": ['match', ['get', 'id'], selected, '#FF0000', '#000000'] + "circle-color": ['match', ['get', 'id'], selected, '#FF0000', '#1c9099'], + "circle-radius": 8, + "circle-opacity": 0.7, }} /> @@ -118,15 +127,16 @@ export function KartaPage() { const articleInfo = { "id": article.id, // "image": article.attributes.cover.data !== null ? "http://strapi.wg.gateway.ts" + article.attributes.cover.data.attributes.url : "https://images.unsplash.com/photo-1628890923662-2cb23c2e0cfe?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80", - "category": "technology", + "category": "", "title": article.attributes.title, - "address": new Date(article.attributes.publishedAt).toLocaleDateString("ru-RU"), + "address": article.attributes.address, + "coordinates": article.attributes.coordinates, // "author": { // "name": "Elsa Brown", // "avatar": "https://images.unsplash.com/photo-1628890923662-2cb23c2e0cfe?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80" // }, "selected": selected, - "setSelected": setSelected + "handleAddressClick": handleAddressClick } return