From 5d126c2cbaa34ad73ced3f2c57e1d4e9c06b2219 Mon Sep 17 00:00:00 2001 From: Phan An Date: Thu, 13 Jun 2024 16:46:13 +0200 Subject: [PATCH] feat(podcast): sort podcasts --- app/Http/Resources/PodcastResource.php | 1 + app/Models/PodcastUserPivot.php | 1 + app/Repositories/PodcastRepository.php | 2 +- app/Repositories/SongRepository.php | 2 +- .../js/__tests__/factory/podcastFactory.ts | 1 + .../js/components/podcast/PodcastItem.vue | 16 +++- .../components/podcast/PodcastListSorter.vue | 77 +++++++++++++++++++ .../components/screens/PodcastListScreen.vue | 24 ++++-- .../assets/js/components/song/SongList.vue | 18 ++--- .../js/components/song/SongListSorter.vue | 11 ++- resources/assets/js/types.d.ts | 3 + 11 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 resources/assets/js/components/podcast/PodcastListSorter.vue diff --git a/app/Http/Resources/PodcastResource.php b/app/Http/Resources/PodcastResource.php index 2bf90463..b3b11e2d 100644 --- a/app/Http/Resources/PodcastResource.php +++ b/app/Http/Resources/PodcastResource.php @@ -52,6 +52,7 @@ class PodcastResource extends JsonResource /** @var PodcastUserPivot $pivot */ $pivot = $this->podcast->subscribers->sole('id', $user->id)->pivot; $data['subscribed_at'] = $pivot->created_at; + $data['last_played_at'] = $pivot->updated_at; $data['state'] = $pivot->state->toArray(); } diff --git a/app/Models/PodcastUserPivot.php b/app/Models/PodcastUserPivot.php index d31e032c..de79d379 100644 --- a/app/Models/PodcastUserPivot.php +++ b/app/Models/PodcastUserPivot.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\Pivot; /** * @property Carbon $created_at + * @property Carbon $updated_at * @property PodcastState $state */ class PodcastUserPivot extends Pivot diff --git a/app/Repositories/PodcastRepository.php b/app/Repositories/PodcastRepository.php index 2b9eb9b5..857ad60f 100644 --- a/app/Repositories/PodcastRepository.php +++ b/app/Repositories/PodcastRepository.php @@ -17,7 +17,7 @@ class PodcastRepository extends Repository /** @return Collection */ public function getAllByUser(User $user): Collection { - return $user->podcasts; + return $user->podcasts()->orderByPivot('updated_at', 'desc')->get(); } /** @return Collection */ diff --git a/app/Repositories/SongRepository.php b/app/Repositories/SongRepository.php index 915a95d2..9c0dca8a 100644 --- a/app/Repositories/SongRepository.php +++ b/app/Repositories/SongRepository.php @@ -37,7 +37,7 @@ class SongRepository extends Repository return Song::query(type: PlayableType::SONG, user: $scopedUser ?? $this->auth->user()) ->accessible() ->withMeta() - ->latest('songs.created_at') + ->latest() ->limit($count) ->get(); } diff --git a/resources/assets/js/__tests__/factory/podcastFactory.ts b/resources/assets/js/__tests__/factory/podcastFactory.ts index eb1f3ec1..5a017c63 100644 --- a/resources/assets/js/__tests__/factory/podcastFactory.ts +++ b/resources/assets/js/__tests__/factory/podcastFactory.ts @@ -11,6 +11,7 @@ export default (faker: Faker): Podcast => { description: faker.lorem.paragraph(), author: faker.name.findName(), subscribed_at: faker.date.past().toISOString(), + created_at: faker.date.past().toISOString(), state: { current_episode: null, progresses: {} diff --git a/resources/assets/js/components/podcast/PodcastItem.vue b/resources/assets/js/components/podcast/PodcastItem.vue index 1e9e2764..9696996a 100644 --- a/resources/assets/js/components/podcast/PodcastItem.vue +++ b/resources/assets/js/components/podcast/PodcastItem.vue @@ -10,7 +10,15 @@

{{ podcast.title }}

-

{{ podcast.author }}

+

+ {{ podcast.author }} + +

@@ -20,10 +28,16 @@