From d94c7ca11e755e9f781f63fbe8c5bcbb9f7e858c Mon Sep 17 00:00:00 2001 From: MacaronFR Date: Sat, 29 Jun 2024 23:24:53 +0200 Subject: [PATCH] Add event journey view --- packages/frontend/src/app.tsx | 5 ++ .../src/events/EventParticipantJourney.tsx | 78 +++++++++++++++++++ .../frontend/src/events/EventParticipants.tsx | 7 +- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 packages/frontend/src/events/EventParticipantJourney.tsx diff --git a/packages/frontend/src/app.tsx b/packages/frontend/src/app.tsx index 3349602a..bbab9f16 100644 --- a/packages/frontend/src/app.tsx +++ b/packages/frontend/src/app.tsx @@ -30,6 +30,7 @@ import { NewJourney } from "./journey/NewJourney.tsx"; import { useConfMode } from "./utils/useConfMode.tsx"; import { CGU } from "./page/CGU.tsx"; import { Invite } from "./page/Invite.tsx"; +import { EventParticipantJourney } from "./events/EventParticipantJourney.tsx"; export function App() { const [loaded, setLoaded] = useState(false); @@ -97,6 +98,10 @@ export function App() { path: "events/:id", element: , }, + { + path: "events/:id/participants/:idparticipant/journey", + element: , + }, { path: "journeys", element: , diff --git a/packages/frontend/src/events/EventParticipantJourney.tsx b/packages/frontend/src/events/EventParticipantJourney.tsx new file mode 100644 index 00000000..5e02d917 --- /dev/null +++ b/packages/frontend/src/events/EventParticipantJourney.tsx @@ -0,0 +1,78 @@ +import { useParams } from "react-router-dom"; +import { useApi } from "../utils/useApi.ts"; +import { TUser } from "../types/TUser.ts"; +import { TEvent } from "../types/TEvent.ts"; +import { Card } from "../components/Card/Card.tsx"; +import { distanceToHumanReadable } from "../utils/distanceToHumanReadable.ts"; +import { TUserJourney } from "../types/TUserJourney.ts"; +import Map, { + Layer, LineLayer, Source, +} from "react-map-gl"; +import { useState } from "preact/hooks"; + +const accessToken = import.meta.env.VITE_MAPBOX_KEY; + +const layerStyle: LineLayer = { + id: "point", + type: "line", + layout: { + "line-join": "round", + "line-cap": "round", + }, + paint: { + "line-color": "#3457D5", + "line-width": 5, + "line-opacity": 1, + }, +}; + +export function EventParticipantJourney() { + const { + id, idparticipant, + } = useParams(); + const user = useApi(`/users/${idparticipant}`); + const event = useApi(`/events/${id}`); + const journey = useApi(`/events/${id}/participations/${idparticipant}/journey`); + const [viewState, setViewState] = useState({ + longitude: 1.2084545, + latitude: 44.3392763, + zoom: 4, + }); + return ( +
+

Trajet de { user.data?.username } lors de l'évènement { event.data?.name }

+ +

Distance totale

+

{ distanceToHumanReadable(journey.data?.total_distance) }

+
+

Altitude max: { distanceToHumanReadable(journey.data?.max_elevation) }

+

Altitude min: { distanceToHumanReadable(journey.data?.min_elevation) }

+

Dénivelé positif: { distanceToHumanReadable(journey.data?.total_elevation_gain) }

+

Dénivelé négatif: { distanceToHumanReadable(journey.data?.total_elevation_loss) }

+
+
+

Temps total: { journey.data?.total_time }

+

Vitesse moyenne: { journey.data?.avg_speed }

+

Vitesse de pointe: { journey.data?.max_speed }

+
+
+ + setViewState(evt.viewState)} + style={{ + height: "calc(100% - 48px)", + width: "100%", + }} + mapLib={import("mapbox-gl")} + mapStyle={"mapbox://styles/mapbox/navigation-night-v1"} + mapboxAccessToken={accessToken} + > + + + + + +
+ ); +} diff --git a/packages/frontend/src/events/EventParticipants.tsx b/packages/frontend/src/events/EventParticipants.tsx index 5a502d10..9720ccb3 100644 --- a/packages/frontend/src/events/EventParticipants.tsx +++ b/packages/frontend/src/events/EventParticipants.tsx @@ -18,6 +18,7 @@ import { DoReload, useReload, } from "../utils/useReload.ts"; import { ModalAddParticipants } from "./ModalAddParticipants.tsx"; +import { Link } from "react-router-dom"; interface EventParticipantsProps { event: TEvent @@ -85,7 +86,11 @@ export function EventParticipant(props: EventParticipantsProps) { , { dateTimeToFrenchString(p.joinedDateTime, false) }, { p.isImagePublic ? "Publiques" : "Privées" }, - { p.journey !== undefined ? : undefined }, + + { p.journey !== undefined ? + : + undefined } + , { p.user.id !== props.event.owner.id ? removeParticipant(p.user.id)}/> :