From 08fcd5832cc00285cd74beecac5500313db782bc Mon Sep 17 00:00:00 2001 From: kimuichan Date: Tue, 31 May 2022 22:28:28 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20(#118)=20=EC=A7=80?= =?UTF-8?q?=EB=8F=84=20=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/userDetail/measurement/Map.tsx | 39 ++++++++-- .../measurement/MeasurementCard.tsx | 75 +++++++++++++++---- 2 files changed, 92 insertions(+), 22 deletions(-) diff --git a/src/components/userDetail/measurement/Map.tsx b/src/components/userDetail/measurement/Map.tsx index d27f576..267886f 100644 --- a/src/components/userDetail/measurement/Map.tsx +++ b/src/components/userDetail/measurement/Map.tsx @@ -1,21 +1,48 @@ -import { useEffect, useState } from "react"; +import fetcher from "@src/utils/function/fetcher"; +import { useEffect } from "react"; +import useSWR from "swr"; interface Props { id: number; isOpen: boolean; } +interface ExerciseList { + exercise_list: { + sequence: number; + latitude: number; + longitude: number; + }[]; +} + const Map: React.FC = ({ id, isOpen }) => { + const { data } = useSWR(`/exercises/${id}`, fetcher); useEffect(() => { const { kakao } = window; kakao.maps.load(function () { - console.log(kakao); - var container = document.getElementById(`map${id}`); - var options = { - center: new kakao.maps.LatLng(33.450701, 126.570667), + let container = document.getElementById(`map${id}`); + let options = { + center: new kakao.maps.LatLng( + data?.exercise_list[0].latitude, + data?.exercise_list[0].longitude - 0.001 + ), level: 3, }; - var map = new kakao.maps.Map(container, options); + let map = new kakao.maps.Map(container, options); + + let linePath = data?.exercise_list.map(i => { + return new kakao.maps.LatLng(i.latitude, i.longitude); + }); + + var polyline = new kakao.maps.Polyline({ + path: linePath, + strokeWeight: 5, + strokeColor: "#4D99F0", + strokeOpacity: 1, + strokeStyle: "solid", + }); + + polyline.setMap(map); if (isOpen) setTimeout(() => { diff --git a/src/components/userDetail/measurement/MeasurementCard.tsx b/src/components/userDetail/measurement/MeasurementCard.tsx index e6ce9c0..9040b46 100644 --- a/src/components/userDetail/measurement/MeasurementCard.tsx +++ b/src/components/userDetail/measurement/MeasurementCard.tsx @@ -1,55 +1,95 @@ import { keyframes } from "@emotion/react"; import styled from "@emotion/styled"; -import { useState } from "react"; +import dayjs from "dayjs"; +import { useEffect, useState } from "react"; +import useSWR from "swr"; +import { ExerciseList } from "."; import Map from "./Map"; -interface Props { +interface Props extends ExerciseList { isRight?: boolean; - id: number; } -const MeasurementCard: React.FC = ({ isRight = false, id }) => { +const MeasurementCard: React.FC = ({ + isRight = false, + calorie, + certifying_shot, + end_at, + exercise_id, + latitude, + longitude, + speed, + time, + walk_count, +}) => { const [mapOpen, setMapOpen] = useState(false); + const [address, setAddress] = useState(""); + + useEffect(() => { + const { kakao } = window; + console.log(kakao); + function getAddr(lat: number, lng: number) { + kakao.maps.load(function () { + let geocoder = new kakao.maps.services.Geocoder(); + let coord = new kakao.maps.LatLng(latitude, longitude); + let callback = function (result, status) { + console.log(status); + if (status === kakao.maps.services.Status.OK) { + setAddress( + `${result[0].address.region_2depth_name} ${result[0].address.region_3depth_name}` + ); + } + }; + geocoder.coord2Address(coord.getLng(), coord.getLat(), callback); + }); + } + getAddr(latitude, longitude); + }, [latitude, longitude]); + return ( setMapOpen(true)} onMouseLeave={() => setMapOpen(false)} > - - {isRight && } + + {isRight && }
-

2022.02.02

-

대전 장동

+

{dayjs(end_at).format("YYYY-MM-DD")}

+

{address}

걸음수 - 3827 + {walk_count} 속도 - 0.9m/s + {Math.ceil(speed / 1) || 0} + m/s 칼로리 - 0.9kcal + {calorie} + kcal 시간 - 0h - 47m + {Math.ceil(time / 60)} + h + {time % 60} + m
- {isRight === false && } + {isRight === false && }
); @@ -70,7 +110,7 @@ const hoverIn = keyframes` } `; -const CardBox = styled.div<{ isRight: boolean }>` +const CardBox = styled.div<{ isRight: boolean; certifying_shot: string }>` position: relative; width: 184px; height: 100%; @@ -79,6 +119,9 @@ const CardBox = styled.div<{ isRight: boolean }>` display: flex; overflow: hidden; align-items: flex-end; + background-image: ${({ certifying_shot }) => `url(${certifying_shot})`}; + background-position: ${({ isRight }) => (isRight ? "right" : "left")}; + background-size: 184px 100%; transition: all 0.5s; cursor: pointer; right: 0; @@ -98,7 +141,7 @@ const CardBox = styled.div<{ isRight: boolean }>` width: 184px; transition: all 0.5s; > div { - :first-child { + :first-of-type { display: none; } :last-child {