Skip to content

Commit b686561

Browse files
ISSUE-41: Better version UX
1 parent 835f9b2 commit b686561

File tree

8 files changed

+47
-85
lines changed

8 files changed

+47
-85
lines changed

config/services_test.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,5 @@ services:
3838
App\Infrastructure\FileSystem\PermissionChecker:
3939
class: App\Tests\Infrastructure\FileSystem\SuccessfulPermissionChecker
4040

41-
App\Domain\GitHub\GitHub:
42-
class: App\Tests\Domain\GitHub\FakeGitHub
43-
4441
League\Flysystem\FilesystemOperator:
4542
class: App\Tests\Infrastructure\FileSystem\SpyFileSystem

src/Domain/GitHub/GitHub.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Domain/GitHub/LiveGitHub.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Domain/Strava/BuildHtmlVersion/BuildHtmlVersionCommandHandler.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Domain\Strava\BuildHtmlVersion;
44

5-
use App\Domain\GitHub\GitHub;
65
use App\Domain\Measurement\Length\Kilometer;
76
use App\Domain\Measurement\UnitSystem;
87
use App\Domain\Strava\Activity\ActivityHeatmapChartBuilder;
@@ -79,7 +78,6 @@ public function __construct(
7978
private FtpRepository $ftpRepository,
8079
private KeyValueStore $keyValueStore,
8180
private AthleteBirthday $athleteBirthday,
82-
private GitHub $gitHub,
8381
private UnitSystem $unitSystem,
8482
private Environment $twig,
8583
private FilesystemOperator $filesystem,
@@ -196,7 +194,6 @@ public function handle(Command $command): void
196194
'lastUpdate' => $now,
197195
'athleteId' => $athleteId,
198196
'currentAppVersion' => self::APP_VERSION,
199-
'latestAppVersion' => $this->gitHub->getRepoLatestRelease('robiningelbrecht/strava-statistics'),
200197
]),
201198
);
202199

templates/html/index.html.twig

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,16 @@
279279
</svg>
280280
</a>
281281
</div>
282-
{% if currentAppVersion == latestAppVersion %}
283-
<div class="text-xs text-center text-gray-500 dark:text-gray-400">{{ currentAppVersion }}</div>
284-
{% else %}
285-
<div class="text-xs text-center text-gray-500 dark:text-gray-400">{{ currentAppVersion }}
286-
(latest: {{ latestAppVersion }})
287-
</div>
288-
{% endif %}
289-
<div class="text-xs text-center text-gray-500 dark:text-gray-400">Updated
290-
on {{ lastUpdate.format('d-m-Y H:i') }}</div>
282+
<div class="flex justify-center gap-x-1 text-xs text-center text-gray-500 dark:text-gray-400">
283+
<span>{{ currentAppVersion }}</span>
284+
<span class="hidden" data-latest-version data-current-version="{{ currentAppVersion }}">
285+
(latest: <a class="underline"
286+
href="https://github.com/robiningelbrecht/strava-statistics/releases/tag/[LATEST_VERSION]">[LATEST_VERSION]</a>)
287+
</span>
288+
</div>
289+
<div class="text-xs text-center text-gray-500 dark:text-gray-400">
290+
Updated on {{ lastUpdate.format('d-m-Y H:i') }}
291+
</div>
291292
</div>
292293
</aside>
293294
<main class="p-4 md:ml-64 h-auto min-h-screen pt-20 text-gray-900 dark:text-white">
@@ -548,6 +549,20 @@
548549
});
549550
});
550551
}
552+
553+
const updateGithubLatestRelease = async () => {
554+
const $latestVersionEl = document.querySelector('[data-latest-version]');
555+
const currentVersion = $latestVersionEl.getAttribute('data-current-version')
556+
const latestVersion = await (await (await fetch('https://api.github.com/repos/robiningelbrecht/strava-statistics/releases/latest')).json())['name'];
557+
558+
if (currentVersion !== latestVersion) {
559+
const $latestVersionLink = $latestVersionEl.querySelector('a');
560+
$latestVersionLink.setAttribute('href', $latestVersionLink.getAttribute('href').replace('[LATEST_VERSION]', latestVersion));
561+
$latestVersionLink.innerHTML = $latestVersionLink.innerHTML.replace('[LATEST_VERSION]', latestVersion);
562+
$latestVersionEl.classList.remove('hidden');
563+
}
564+
}
565+
updateGithubLatestRelease();
551566
</script>
552567
</body>
553568
</html>

tests/Domain/GitHub/FakeGitHub.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/Domain/Strava/BuildHtmlVersion/__snapshots__/BuildHtmlVersionCommandHandlerTest--testHandle--buildhtmlindex.html.html

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,15 @@
213213
</svg>
214214
</a>
215215
</div>
216-
<div class="text-xs text-center text-gray-500 dark:text-gray-400">v0.2.4
217-
(latest: v0.1.8)
218-
</div>
219-
<div class="text-xs text-center text-gray-500 dark:text-gray-400">Updated
220-
on 17-10-2023 16:15</div>
216+
<div class="flex justify-center gap-x-1 text-xs text-center text-gray-500 dark:text-gray-400">
217+
<span>v0.2.4</span>
218+
<span class="hidden" data-latest-version data-current-version="v0.2.4">
219+
(latest: <a class="underline" href="https://github.com/robiningelbrecht/strava-statistics/releases/tag/%5BLATEST_VERSION%5D">[LATEST_VERSION]</a>)
220+
</span>
221+
</div>
222+
<div class="text-xs text-center text-gray-500 dark:text-gray-400">
223+
Updated on 17-10-2023 16:15
224+
</div>
221225
</div>
222226
</aside>
223227
<main class="p-4 md:ml-64 h-auto min-h-screen pt-20 text-gray-900 dark:text-white">
@@ -469,6 +473,20 @@
469473
});
470474
});
471475
}
476+
477+
const updateGithubLatestRelease = async () => {
478+
const $latestVersionEl = document.querySelector('[data-latest-version]');
479+
const currentVersion = $latestVersionEl.getAttribute('data-current-version')
480+
const latestVersion = await (await (await fetch('https://api.github.com/repos/robiningelbrecht/strava-statistics/releases/latest')).json())['name'];
481+
482+
if (currentVersion !== latestVersion) {
483+
const $latestVersionLink = $latestVersionEl.querySelector('a');
484+
$latestVersionLink.setAttribute('href', $latestVersionLink.getAttribute('href').replace('[LATEST_VERSION]', latestVersion));
485+
$latestVersionLink.innerHTML = $latestVersionLink.innerHTML.replace('[LATEST_VERSION]', latestVersion);
486+
$latestVersionEl.classList.remove('hidden');
487+
}
488+
}
489+
updateGithubLatestRelease();
472490
</script>
473491
</body>
474492
</html>

tests/strava.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)