From 7b4c39499aa0ea9c00b39d6a0e2ed5713fff0c88 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Wed, 23 Oct 2024 13:42:56 +0200 Subject: [PATCH] refactor: :construction: wip --- lib/Controller/MetricsController.php | 14 ++++-- package.json | 4 +- src/components/Feed/Favorite.vue | 22 ++++----- src/components/Sidebar/Subscription.vue | 63 ++++++++---------------- src/components/Sidebar/Subscriptions.vue | 8 +-- src/store/subscriptions.ts | 34 ++++--------- src/utils/types.ts | 12 +---- src/views/Home.vue | 4 +- 8 files changed, 62 insertions(+), 99 deletions(-) diff --git a/lib/Controller/MetricsController.php b/lib/Controller/MetricsController.php index 40ec199..f668130 100644 --- a/lib/Controller/MetricsController.php +++ b/lib/Controller/MetricsController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace OCA\RePod\Controller; use OCA\GPodderSync\Core\PodcastData\PodcastDataReader; +use OCA\GPodderSync\Core\PodcastData\PodcastMetrics; use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader; use OCA\RePod\AppInfo\Application; use OCA\RePod\Service\UserService; @@ -30,14 +31,19 @@ class MetricsController extends Controller #[NoCSRFRequired] #[FrontpageRoute(verb: 'GET', url: '/metrics')] public function index(): JSONResponse { - $subscriptions = $this->podcastMetricsReader->metrics($this->userService->getUserUID()); + $metrics = $this->podcastMetricsReader->metrics($this->userService->getUserUID()); + usort($metrics, fn (PodcastMetrics $a, PodcastMetrics $b) => $b->getListenedSeconds() <=> $a->getListenedSeconds()); + $subscriptions = []; + + foreach ($metrics as $metric) { + $subscription = $metric->toArray(); - foreach ($subscriptions as $id => $subscription) { try { - $subscriptions[$id]['data'] = $this->podcastDataReader->getCachedOrFetchPodcastData($subscription->getUrl(), $this->userService->getUserUID()); + $subscription['data'] = $this->podcastDataReader->getCachedOrFetchPodcastData($metric->getUrl(), $this->userService->getUserUID()); } catch (\Exception $e) { - continue; } + + $subscriptions[] = $subscription; } return new JSONResponse($subscriptions); diff --git a/package.json b/package.json index 3f838b5..b6e8ebc 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "dev": "vite --mode development build", "dev:watch": "vite --mode development build --watch", "watch": "npm run dev:watch", - "lint": "eslint src", - "lint:fix": "eslint src --fix", + "lint": "vue-tsc && eslint src", + "lint:fix": "vue-tsc && eslint src --fix", "stylelint": "stylelint src/**/*.vue src/**/*.scss src/**/*.css", "stylelint:fix": "stylelint src/**/*.vue src/**/*.scss src/**/*.css --fix" }, diff --git a/src/components/Feed/Favorite.vue b/src/components/Feed/Favorite.vue index fa3c5a5..dcad203 100644 --- a/src/components/Feed/Favorite.vue +++ b/src/components/Feed/Favorite.vue @@ -1,15 +1,15 @@