Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iti2 #592

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft

iti2 #592

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bb17afe
Premier test du ontrip mode : prometteur :)
laem Sep 9, 2024
4637e17
Nouveau gain de place verticale pour le mode itinéraire
laem Sep 12, 2024
0ef56a6
Début de la gestion de date pour ontrip
laem Sep 12, 2024
e3bfd2c
Petit gain de place entre les modes de transport et la date
laem Sep 12, 2024
bab34eb
Gestion automatique du choix entre onTrip et preTrip
laem Sep 12, 2024
ccaa38c
On ne garde que les connections motis avec un transport en commun
laem Sep 12, 2024
4a029e5
Désambiguation du "dans" : ça inclut la marche
laem Sep 12, 2024
52ca4c2
Gestion de l'apparition du temps de trajet en secondes
laem Sep 12, 2024
fe57b20
Bug sur la différence de temps qui déclenche le "maintenant"
laem Sep 12, 2024
efdbe4d
Diminution du min_connection_count
laem Sep 12, 2024
f5aadb0
Notre photon pour la reverse géoloc aussi, et message d'attente
laem Sep 12, 2024
c94c752
Marqueur au clic
laem Sep 12, 2024
f9e97e2
Test de vibration sans succès
laem Sep 12, 2024
5a7f6f9
Sur le mode transport, la date avant le contenu !
laem Sep 12, 2024
89e28b5
Police bold manquante ; noms de ligne de transport en commun en bold
laem Sep 12, 2024
3deb565
Largeur minimum de la frise transport en commun
laem Sep 12, 2024
baddaa2
Début des options d'itinéraire
laem Sep 12, 2024
a489b22
:bug: Bug pour des rivières qui n'ont pas de polygone.
laem Sep 13, 2024
bde4aec
L'estimation en langage humain de la durée ne rentrait pas
laem Sep 13, 2024
75c9751
Choix du nombre de correspondances
laem Sep 13, 2024
2b3ce06
Début d'intégration du mode de transport de début
laem Sep 13, 2024
a9b4b59
0 corresp. = direct seulement
laem Sep 19, 2024
f7bd430
WIP encodage des modes et du temps dans l'URL
laem Sep 19, 2024
7464068
Début d'implémentation des étapes de l'itinéraire
laem Sep 19, 2024
c50292d
Perfection des disques de station
laem Sep 20, 2024
ffd56e6
"Marcher jusqu'à la fin"
laem Sep 20, 2024
0e58267
Ajustements de la feuille de route
laem Sep 20, 2024
b1765b2
Meilleure aération des arrêts pour les noms de stations à 2 lignes
laem Sep 20, 2024
7b1ba7c
Erreur dans le choix de la dernière station d'un transport
laem Sep 20, 2024
f848cad
Rétablissement du TER
laem Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/ClickedPoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default function ClickedPoint({
geocodedClickedPoint: { latitude, longitude, data },
geolocation,
}) {
console.log('clickedPoint', latitude, longitude, data)
if (latitude && longitude && !data) return <p>Géolocation en cours...</p>
console.log('lightgreen clickedPoint', latitude, longitude, data)
const origin = geolocation
if (!data)
return (
Expand Down
1 change: 1 addition & 0 deletions app/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export default function Container({
containerRef,
trackedSnap,
setTrackedSnap,
geocodedClickedPoint,
}}
/>
</ContentWrapper>
Expand Down
3 changes: 3 additions & 0 deletions app/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import useDrawItinerary from './itinerary/useDrawItinerary'
import useDrawPanoramaxPosition, {
useAddPanoramaxLayer,
} from './effects/useDrawPanoramaxPosition'
import useDrawRightClickMarker from './effects/useDrawRightClickMarker'

if (process.env.NEXT_PUBLIC_MAPTILER == null) {
throw new Error('You have to configure env NEXT_PUBLIC_MAPTILER, see README')
Expand Down Expand Up @@ -78,6 +79,7 @@ export default function Map({
quickSearchFeatures,
trackedSnap,
panoramaxPosition,
geocodedClickedPoint,
}) {
const isMobile = useMediaQuery('(max-width: 800px)')
const mapContainerRef = useRef(null)
Expand Down Expand Up @@ -337,6 +339,7 @@ export default function Map({
zoom
)
*/
useDrawRightClickMarker(map, geocodedClickedPoint)

/* Abandoned code that should be revived. Traveling with train + bike is an
* essential objective of Cartes */
Expand Down
31 changes: 31 additions & 0 deletions app/effects/useDrawRightClickMarker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Marker } from 'maplibre-gl'
import { useEffect } from 'react'

export default function useDrawRightClickMarker(map, geocodedClickedPoint) {
useEffect(() => {
if (!map || !geocodedClickedPoint) return

console.log('lightgreen marker', geocodedClickedPoint)

const lon = geocodedClickedPoint.longitude,
lat = geocodedClickedPoint.latitude

if (!lon || !lat) return
const marker = new Marker({
color: 'var(--color)',
//draggable: true,
})
.setLngLat([lon, lat])
.addTo(map)

// Apple Maps has a nice haptic vibration feedback.
// https://il.ly/tech/vibrate-mobile-phone-web-vibration-api#vibration-api-browser-support
// I don't think this is much supported. Test Android Firefox, Bromite,
// Lineageos navigator, iOS firefox, iOS safari : no one works.
// navigator.vibrate(200)

return () => {
marker.remove()
}
}, [map, geocodedClickedPoint])
}
2 changes: 1 addition & 1 deletion app/effects/useDrawTransit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function useDrawTransit(map, transit, selectedConnection, date) {
source: id,
layout: {
'symbol-placement': 'line',
'text-font': ['Roboto Regular', 'Noto Sans Regular'],
'text-font': ['Roboto Bold', 'Noto Sans Bold'],
'text-field': '{name}', // part 2 of this is how to do it
'text-transform': 'uppercase',
'text-size': 16,
Expand Down
10 changes: 7 additions & 3 deletions app/effects/useGeocodeRightClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ export default function useGeocodeRightClick(stringClickedPoint) {
}
const clickedPoint = stringClickedPoint.split('|')

const latitude = +clickedPoint[0],
longitude = +clickedPoint[1]

setData({ latitude, longitude, data: null })
const doFetch = async () => {
const request = await fetch(
`https://photon.komoot.io/reverse?lon=${clickedPoint[1]}&lat=${clickedPoint[0]}`
`https://serveur.cartes.app/photon/reverse?lon=${clickedPoint[1]}&lat=${clickedPoint[0]}`
)
const json = await request.json()

const result = {
latitude: +clickedPoint[0],
longitude: +clickedPoint[1],
latitude,
longitude,
data: json,
}
setData(result)
Expand Down
122 changes: 86 additions & 36 deletions app/itinerary/DateSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { DialogButton } from '../UI'
import { useInterval } from 'usehooks-ts'
import Link from 'next/link'
import Image from 'next/image'
import { nowStamp, stamp } from './transit/motisRequest'
import calendarIcon from '@/public/calendar.svg'

export const initialDate = (type = 'date') => {
const stringDate = new Date().toLocaleString('fr')
Expand All @@ -17,54 +19,98 @@ export const initialDate = (type = 'date') => {
return day + 'T' + hour.slice(0, -3)
}

export const isDateNow = (date) => {
const now = nowStamp()
const dateStamp = stamp(date)

const difference = dateStamp - now

console.log('lightgreen diff in minutes', difference / 60)
return difference < 60 * 10 // 10 minutes
}

// Can be type date (day + hour) or type day
export default function DateSelector({ date, type = 'date' }) {
const [notNow, setNotNow] = useState(false)
const defaultDate = initialDate(type)
const [localDate, setLocalDate] = useState(date || defaultDate)
const setSearchParams = useSetSearchParams()

const hideDate = !notNow && isDateNow(date)

return (
<div
css={`
margin-top: 0.2rem;
display: flex;
align-items: center;
> input {
margin-right: 0.4rem !important;
font-size: 110%;
height: 1.4rem;
padding: 0 0.2rem;
color: var(--darkerColor);
border: 2px solid var(--darkColor);
border-radius: 0.15rem;
}
justify-content: end;
`}
>
<input
type={type === 'date' ? 'datetime-local' : 'date'}
id="date"
name="date"
value={localDate}
min={defaultDate}
onChange={(e) => {
const value = e.target.value
// changing e.g. the weekday starting with the 0 diigt with the keyboard will make value '' on firefox, LOL
if (value !== '') setLocalDate(e.target.value)
}}
/>
{date !== localDate && (
<DialogButton
onClick={() =>
setSearchParams(
type === 'date'
? { date: encodeDate(localDate) }
: { day: encodeDate(localDate) }
)
}
{' '}
{hideDate ? (
<span
css={`
font-size: 100%;
display: flex;
align-items: center;
button {
margin: 0;
padding: 0;
}
`}
>
OK
</DialogButton>
Maintenant{' '}
<button
onClick={() => setNotNow(true)}
title="Changer le moment du départ "
>
<Image
src={calendarIcon}
alt="Icône d'un agenda"
css="width: 1.6rem; height: auto; vertical-align: sub; margin-left: .2rem"
/>
</button>
</span>
) : (
<>
<input
css={`
margin-right: 0.4rem !important;
font-size: 110%;
height: 1.4rem;
padding: 0 0.2rem;
color: var(--darkerColor);
border: 2px solid var(--darkColor);
border-radius: 0.15rem;
`}
type={type === 'date' ? 'datetime-local' : 'date'}
id="date"
name="date"
value={localDate}
min={defaultDate}
onChange={(e) => {
const value = e.target.value
// changing e.g. the weekday starting with the 0 diigt with the keyboard will make value '' on firefox, LOL
if (value !== '') setLocalDate(e.target.value)
}}
/>
{date !== localDate && (
<DialogButton
onClick={() =>
setSearchParams(
type === 'date'
? { date: encodeDate(localDate) }
: { day: encodeDate(localDate) }
)
}
css={`
font-size: 100%;
`}
>
OK
</DialogButton>
)}
</>
)}
{type === 'date' && (
<UpdateDate
Expand All @@ -79,12 +125,16 @@ export default function DateSelector({ date, type = 'date' }) {
}

const newTimestamp = () => new Date().getTime() / 1000

const UpdateDate = ({ date, updateDate }) => {
const [now, setNow] = useState(newTimestamp())

useInterval(() => {
setNow(newTimestamp())
}, 5 * 1000)
useInterval(
() => {
setNow(newTimestamp())
},
5 * 1000 // every 5 seconds
)
const isOutdated = now - new Date(date).getTime() / 1000 > 10

if (!isOutdated) return null
Expand Down
7 changes: 6 additions & 1 deletion app/itinerary/Itinerary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ export default function Itinerary({
<div>
<ol
css={`
margin-top: 0.1rem;
margin-left: 0;
padding-left: 0;
list-style-type: none;
display: flex;
align-items: center;
justify-content: space-evenly;
justify-content: start;
gap: 1rem;
width: 80%;
li {
margin: 0 0.4rem;
}
Expand Down
6 changes: 1 addition & 5 deletions app/itinerary/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ export default function Steps({
const allez = steps.map((step) => step?.key).join('->')

return (
<section
css={`
margin: 0 0 1rem 0;
`}
>
<section>
<AddStepButton
url={setSearchParams({ allez: '->' + allez }, true)}
title={'Ajouter un point comme départ'}
Expand Down
12 changes: 5 additions & 7 deletions app/itinerary/transit/BestConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ export default function BestConnection({ bestConnection }) {
.
</p>
<p>
⌚️{' '}
{capitalise0(
bestConnection.nextDepartures
.slice(0, 4)
.map((departure) => departure.toLowerCase())
.join(', ')
)}
⌚️ Partir{' '}
{bestConnection.nextDepartures
.slice(0, 4)
.map((departure) => departure.toLowerCase())
.join(', ')}
.
</p>
</div>
Expand Down
Loading