Skip to content

Commit

Permalink
refactor: create reusable component for shorts, lives and videos tab
Browse files Browse the repository at this point in the history
  • Loading branch information
arjitcodes committed Oct 27, 2024
1 parent b4c7c69 commit 0aa62ec
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 124 deletions.
10 changes: 5 additions & 5 deletions zimui/src/components/channel/tabs/LivesTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import { useMainStore } from '@/stores/main'
import { computed } from 'vue'
import LivesGridTab from './LivesGridTab.vue'
import TabView from '@/views/TabView.vue'
const main = useMainStore()
const hideTabs = computed(() => main.channel?.livesPlaylist)
const livesAvailable = computed(() => main.channel?.livesPlaylist)
</script>

<template>
<div v-if="hideTabs">
<lives-grid-tab />
<div v-if="livesAvailable">
<tab-view :playlist-label="'livesPlaylist'" :playlist-type="'Lives'" />
</div>
<div v-else>
<p style="text-align:center">No Live available</p>
<p style="text-align: center">No Live available</p>
</div>
</template>
52 changes: 0 additions & 52 deletions zimui/src/components/channel/tabs/ShortsGridTab.vue

This file was deleted.

13 changes: 8 additions & 5 deletions zimui/src/components/channel/tabs/ShortsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
import { useMainStore } from '@/stores/main'
import { computed } from 'vue'
import ShortsGridTab from './ShortsGridTab.vue'
import TabView from '@/views/TabView.vue'
const main = useMainStore()
const hideTabs = computed(() => main.channel?.shortsPlaylist)
const shortsAvailable = computed(() => main.channel?.shortsPlaylist)
</script>

<template>
<div v-if="hideTabs">
<shorts-grid-tab />
<div v-if="shortsAvailable">
<tab-view
:playlist-label="'shortsPlaylist'"
:playlist-type="'Shorts'"
/>
</div>
<div v-else>
<p style="text-align:center">No short available</p>
<p style="text-align: center">No short available</p>
</div>
</template>
52 changes: 0 additions & 52 deletions zimui/src/components/channel/tabs/VideosGridTab.vue

This file was deleted.

10 changes: 6 additions & 4 deletions zimui/src/components/channel/tabs/VideosTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import { useMainStore } from '@/stores/main'
import { computed } from 'vue'
import VideosGridTab from './VideosGridTab.vue'
import TabView from '@/views/TabView.vue'
const main = useMainStore()
const hideTabs = computed(() => main.channel?.longVideosPlaylist)
const videosAvailable = computed(() => main.channel?.longVideosPlaylist)
</script>

<template>
<div v-if="hideTabs">
<videos-grid-tab />
<div v-if="videosAvailable">
<tab-view
:playlist-label="'longVideosPlaylist'"
:playlist-type="'Videos'" />
</div>
<div v-else>
<p style="text-align:center">No Video available</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,30 @@ const videos = ref<VideoPreview[]>([])
const playlist = ref<Playlist>()
const isLoading = ref(true)
// Watch for changes in the main playlist
const props = defineProps({
playlistLabel: {
type: String,
required: true
},
playlistType: {
type: String,
required: true
}
})
// Watch for changes in the playlist
watch(
() => main.channel?.mainPlaylist,
() => main.channel?.[props.playlistLabel],
() => {
fetchData()
}
)
// Fetch the videos for the main playlist
// Fetch the videos for the playlist
const fetchData = async function () {
if (main.channel?.shortsPlaylist) {
if (main.channel?.[props.playlistLabel]) {
try {
const resp = await main.fetchPlaylist(main.channel?.livesPlaylist)
const resp = await main.fetchPlaylist(main.channel?.[props.playlistLabel])
if (resp) {
playlist.value = resp
videos.value = resp.videos
Expand All @@ -48,6 +59,12 @@ onMounted(() => {
<v-progress-circular class="d-inline" indeterminate></v-progress-circular>
</div>
<div v-else>
<video-grid v-if="videos" :videos="videos" :playlist-slug="main.channel?.livessPlaylist" />
<tab-info
:title="[props.playlistType]+' from '+main.channel?.title"
:count="playlist?.videosCount || 0"
:count-text="playlist?.videos.length === 1 ? 'video' : 'videos'"
icon="mdi-video-outline"
/>
<video-grid v-if="videos" :videos="videos" :playlist-slug="main.channel?.[props.playlistLabel]" />
</div>
</template>

0 comments on commit 0aa62ec

Please sign in to comment.