mirror of
https://github.com/koel/koel
synced 2024-11-10 14:44:13 +00:00
fix: better handling of YouTube video loading failure
This commit is contained in:
parent
31154abbea
commit
27ef78098f
1 changed files with 10 additions and 3 deletions
|
@ -9,12 +9,17 @@
|
|||
<Btn v-if="!loading" small @click.prevent="loadMore">Load More</Btn>
|
||||
</template>
|
||||
|
||||
<p v-if="loading" class="nope">Loading…</p>
|
||||
<p v-if="loading">Loading…</p>
|
||||
|
||||
<p v-if="somethingWrong">
|
||||
Failed to load videos.
|
||||
<a @click.prevent="loadMore" href="#">Try again</a>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { defineAsyncComponent, ref, toRefs, watch } from 'vue'
|
||||
import { computed, defineAsyncComponent, ref, toRefs, watch } from 'vue'
|
||||
import { youTubeService } from '@/services'
|
||||
import { useErrorHandler } from '@/composables'
|
||||
|
||||
|
@ -35,7 +40,7 @@ const loadMore = async () => {
|
|||
try {
|
||||
const result = await youTubeService.searchVideosBySong(song.value, nextPageToken)
|
||||
nextPageToken = result.nextPageToken
|
||||
videos.value.push(...result.items)
|
||||
videos.value.push(...(result.items || []))
|
||||
} catch (error: unknown) {
|
||||
useErrorHandler().handleHttpError(error)
|
||||
} finally {
|
||||
|
@ -43,6 +48,8 @@ const loadMore = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
const somethingWrong = computed(() => !loading.value && videos.value.length === 0)
|
||||
|
||||
watch(song, () => {
|
||||
videos.value = []
|
||||
nextPageToken = ''
|
||||
|
|
Loading…
Reference in a new issue