Skip to content

Commit a2a96ec

Browse files
committed
Make bike ghost adding fail earlier
1 parent 10a3c34 commit a2a96ec

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/lib/components/Bike.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
battery?: number|null;
2222
dock: string|null;
2323
disabled?: boolean;
24-
serial: string|null;
24+
serial: string;
2525
station: StationInfo;
2626
}
2727

src/lib/components/ErrorMessage.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { fly } from 'svelte/transition';
55
</script>
66

7-
<div class="flex flex-col pointer-events-none z-50 absolute bottom-10 left-1/2 -translate-x-1/2 items-center gap-2">
7+
<div class="flex flex-col pointer-events-none z-[110] absolute bottom-10 left-1/2 -translate-x-1/2 items-center gap-2">
88
{#each $errorMessages as error (error.id)}
99
<div animate:flip={{ duration: 400 }} transition:fly={{ y: 80 }} class="bg-warning py-2 px-3 font-bold text-sm text-background rounded-xl w-max max-w-[85vw]">
1010
{error.msg}

src/lib/components/StationMenu.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Bike from '$lib/components/Bike.svelte';
33
import BikeSkeleton from '$lib/components/BikeSkeleton.svelte';
44
import { getStationInfo } from '$lib/gira-api/api';
5+
import { IdToSerial } from '$lib/gira-api/bikeMapping';
56
import { currentPos } from '$lib/location';
67
import { selectedStation, stations } from '$lib/map.svelte';
78
import { t } from '$lib/translations';
@@ -49,7 +50,7 @@
4950
return undefined;
5051
});
5152
52-
let bikeInfo:({type:'electric'|'classic', id:string, battery:number|null, dock:string, serial:string}|{id:string})[] = $state([]);
53+
let bikeInfo:({type:'electric'|'classic', id:string, battery:number|null, dock:string, serial:string}|{id:string, serial: string})[] = $state([]);
5354
function isRealBike(bike: typeof bikeInfo[number]): bike is {type:'electric'|'classic', id:string, battery:number|null, dock:string, serial:string} {
5455
return 'type' in bike === true;
5556
}
@@ -182,19 +183,21 @@
182183
const makeExtraBikeFunction = (dismiss: () => void) => {
183184
return async () => {
184185
await tick();
185-
if (bikeIdNumber === null || bikeIdNumber > 10000 || bikeIdNumber < 0) {
186+
if (bikeId === null) {
186187
errorMessages.add(
187188
$t('bike_unlock_invalid_id_error'),
188189
2000,
189190
);
190191
return;
191192
}
192-
if (bikeId) bikeInfo.push({ id: bikeId });
193+
let serial = IdToSerial.get(bikeId);
194+
if (serial) bikeInfo.push({ id: bikeId, serial: serial });
193195
else {
194196
errorMessages.add(
195197
$t('bike_unlock_no_serial_error'),
196198
3000,
197199
);
200+
return;
198201
}
199202
dismiss();
200203
await tick();
@@ -282,7 +285,7 @@
282285
{#if isRealBike(bike)}
283286
<Bike type={bike.type} id={bike.id} battery={bike.battery} dock={bike.dock} serial={bike.serial} disabled={isScrolling} station={station} />
284287
{:else}
285-
<Bike type={null} id={bike.id} battery={null} dock={null} serial={null} disabled={isScrolling} station={station} />
288+
<Bike type={null} id={bike.id} battery={null} dock={null} serial={bike.serial} disabled={isScrolling} station={station} />
286289
{/if}
287290

288291
{/each}

src/lib/trip.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ async function checkTripStarted(serial: string) {
6060
* @param station
6161
* @returns True if the trip was started successfully, false otherwise
6262
*/
63-
export async function tryStartTrip(id: string, serial: string|null, station: StationInfo): Promise<boolean> {
64-
if (serial == null){
65-
serial = IdToSerial.get(id) ?? null;
66-
}
67-
if (serial == null) {
68-
errorMessages.add(get(t)('bike_unlock_no_serial_error'));
69-
reportErrorEvent('bike_unlock_no_serial_error', id);
70-
return false;
71-
}
63+
export async function tryStartTrip(id: string, serial: string, station: StationInfo): Promise<boolean> {
64+
// if (serial == null){
65+
// serial = IdToSerial.get(id) ?? null;
66+
// }
67+
// if (serial == null) {
68+
// errorMessages.add(get(t)('bike_unlock_no_serial_error'));
69+
// reportErrorEvent('bike_unlock_no_serial_error', id);
70+
// return false;
71+
// }
7272
try {
7373
if (get(appSettings).distanceLock) {
7474
const pos = get(currentPos);

0 commit comments

Comments
 (0)