From 3e62eb8d376f7c19eac8d9a74fba7fc3c591cf99 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Thu, 20 Oct 2022 15:53:32 +0000 Subject: [PATCH] Update routes to use query params, fix caching --- resources/views/tracker.blade.php | 9 ++----- routes/web.php | 40 ++++++++++++++----------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/resources/views/tracker.blade.php b/resources/views/tracker.blade.php index 673f7ba..33f7fcd 100644 --- a/resources/views/tracker.blade.php +++ b/resources/views/tracker.blade.php @@ -65,8 +65,8 @@ @endforeach - @if ($trip->is_active) -

Show all checkins

+ @if (!$showAllCheckins) +

Show all checkins

@endif @@ -141,11 +141,6 @@ ).addTo(map).setZIndexOffset(1000); currLocation.bindPopup('

Current location

').openPopup(); - /* - * Add all checkins link href. - */ - document.getElementById("allCheckinsLink").href = window.location.pathname + '/all'; - /* * Changes the currently-selected popup. */ diff --git a/routes/web.php b/routes/web.php index 7e0b8f7..9c78d25 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,38 +1,34 @@ input('show', null); + /* - * If there is a file in the local cache that is less than 5 hours old, + * If there is a file in the local cache that is less than 3 hours old, * use that. */ - $tripFileName = $tripId ?? config('app.current_trip_id') . '.json'; + $tripFileName = ( $tripId ?? config('app.current_trip_id') ) . '.json'; if (Storage::disk('local')->exists($tripFileName)) { $cachedData = json_decode(Storage::disk('local')->get($tripFileName)); - $cachedDataUpdatedAt = new DateTime($cachedData->trip->updated_at); - $now = new DateTime(); - if (intval(($now->getTimestamp() - $cachedDataUpdatedAt->getTimestamp()) / 3600) <= 5) { - return view('tracker', ['trip' => $cachedData->trip, 'showAllCheckins' => ($showAll === 'all')]); + if ($cachedData->trip->is_active) { + $cachedDataUpdatedAt = new DateTime($cachedData->trip->updated_at); + $now = new DateTime(); + if (intval(($now->getTimestamp() - $cachedDataUpdatedAt->getTimestamp()) / 3600) <= 3) { + return view('tracker', ['trip' => $cachedData->trip, 'showAllCheckins' => ($viewMode === 'all')]); + } + } else { + return view('tracker', ['trip' => $cachedData->trip, 'showAllCheckins' => ($viewMode === 'all')]); } } @@ -61,8 +57,8 @@ Route::get('/{tripId?}/{showAll?}', function ($tripId = null, $showAll = false) } } - return view('tracker', ['trip' => $data->trip, 'showAllCheckins' => ($showAll === 'all')]); + return view('tracker', ['trip' => $data->trip, 'showAllCheckins' => ($viewMode === 'all')]); } else { return 'Something went wrong'; } -}); +})->where('tripId', '[0-9a-z]{20}');