From 7e660c4bb0be68d90cf26967c0c3cb1fbe224bbe Mon Sep 17 00:00:00 2001
From: Jonas Heinrich <onny@project-insanity.org>
Date: Fri, 8 Jan 2021 20:55:42 +0100
Subject: [PATCH] support browse categories

---
 src/components/ItemSlider.vue | 18 ++++++++++++++++--
 src/services/FyydApi.js       | 10 ++++++++--
 src/views/Browse.vue          |  4 ++--
 src/views/BrowseAll.vue       | 17 +++++++----------
 4 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/src/components/ItemSlider.vue b/src/components/ItemSlider.vue
index f85283f..92fabee 100644
--- a/src/components/ItemSlider.vue
+++ b/src/components/ItemSlider.vue
@@ -28,7 +28,8 @@
 		<div class="podcastSliderWrapper">
 			<div
 				v-show="showPrev"
-				class="navSlider navPrev" />
+				class="navSlider navPrev"
+				@click="moveSlider('left')" />
 			<div
 				id="slider"
 				class="podcastSlider"
@@ -51,7 +52,8 @@
 			</div>
 			<div
 				v-show="showNext"
-				class="navSlider navNext" />
+				class="navSlider navNext"
+				@click="moveSlider('right')" />
 		</div>
 	</div>
 </template>
@@ -95,6 +97,17 @@ export default {
 			}
 		})
 	},
+	methods: {
+		moveSlider(direction) {
+			const slider = this.$el.querySelector('#slider')
+			const sliderPos = slider.scrollLeft
+			if (direction === 'right') {
+				slider.scrollLeft = sliderPos + 350
+			} else {
+				slider.scrollLeft = sliderPos - 350
+			}
+		},
+	},
 }
 
 </script>
@@ -135,6 +148,7 @@ export default {
 		overflow: hidden;
 		overflow-x: auto;
 		scrollbar-width: none;
+		scroll-behavior: smooth;
 
 		&:before {
 			content: '';
diff --git a/src/services/FyydApi.js b/src/services/FyydApi.js
index d511d96..7ceaa4e 100644
--- a/src/services/FyydApi.js
+++ b/src/services/FyydApi.js
@@ -97,7 +97,7 @@ export class FyydApi {
 
 	}
 
-	queryList(listName) {
+	queryList(listName, count = 10) {
 
 		delete axios.defaults.headers.requesttoken
 		let queryURL = ''
@@ -106,9 +106,15 @@ export class FyydApi {
 			queryURL = this.url() + '/feature/podcast/hot'
 		} else if (listName === 'latest') {
 			queryURL = this.url() + '/podcast/latest'
+		} else {
+			queryURL = this.url() + '/category?category_id=' + listName
 		}
 
-		return axios.get(queryURL)
+		return axios.get(queryURL, {
+			params: {
+				count,
+			},
+		})
 			.then(
 				(response) => {
 					return Promise.resolve(response.data)
diff --git a/src/views/Browse.vue b/src/views/Browse.vue
index 7e452a5..70fa030 100644
--- a/src/views/Browse.vue
+++ b/src/views/Browse.vue
@@ -62,9 +62,9 @@ export default {
 
 		async queryPodcastLists() {
 
-			const hotList = await fyydClient.queryList('hot')
+			const hotList = await fyydClient.queryList('hot', 10)
 			this.podcastsHot = hotList.data
-			const latestList = await fyydClient.queryList('latest')
+			const latestList = await fyydClient.queryList('latest', 10)
 			this.podcastsLatest = latestList.data
 			this.loading = false
 
diff --git a/src/views/BrowseAll.vue b/src/views/BrowseAll.vue
index 363bc83..ad97c9f 100644
--- a/src/views/BrowseAll.vue
+++ b/src/views/BrowseAll.vue
@@ -31,9 +31,6 @@
 import ItemGrid from '../components/ItemGrid'
 
 import { FyydApi } from './../services/FyydApi'
-import { ShowApi } from './../services/ShowApi'
-
-const apiClient = new ShowApi()
 const fyydClient = new FyydApi()
 
 export default {
@@ -56,22 +53,22 @@ export default {
 
 		async queryPodcasts() {
 
-			console.log(this.category)
 			let podcasts = null
 			if (this.category === 'hot') {
-				podcasts = await fyydClient.queryList('hot')
+				podcasts = await fyydClient.queryList('hot', 20)
 				this.title = 'Hot podcasts'
 				document.title = 'Hot podcasts - Podcast - Nextcloud'
+				this.podcasts = podcasts.data
 			} else if (this.category === 'new') {
-				podcasts = await fyydClient.queryList('latest')
+				podcasts = await fyydClient.queryList('latest', 20)
 				this.title = 'New podcasts'
 				document.title = 'New podcasts - Podcast - Nextcloud'
+				this.podcasts = podcasts.data
 			} else {
-				const categoryName = apiClient.getCategoryName(this.categoryId)
-				podcasts = await fyydClient.queryList(this.categoryId)
-				this.title = 'Podcasts in ' + categoryName
+				podcasts = await fyydClient.queryList(this.categoryId, 20)
+				this.title = 'Podcasts in ' + podcasts.data.category.title
+				this.podcasts = podcasts.data.podcasts
 			}
-			this.podcasts = podcasts.data
 
 		},
 
-- 
GitLab