fix(front): get widget data ready when components are loaded and refresh them on change
This commit is contained in:
parent
ea873d4438
commit
8c2c406637
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Track, Listening } from '~/types'
|
import type { Track, Listening } from '~/types'
|
||||||
|
|
||||||
import { ref, reactive, watch } from 'vue'
|
import { ref, reactive, watch, onMounted } from 'vue'
|
||||||
import { useStore } from '~/store'
|
import { useStore } from '~/store'
|
||||||
import { clone } from 'lodash-es'
|
import { clone } from 'lodash-es'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
@ -53,6 +53,7 @@ const count = ref(0)
|
||||||
const nextPage = ref<string | null>(null)
|
const nextPage = ref<string | null>(null)
|
||||||
|
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
|
|
||||||
const fetchData = async (url = props.url) => {
|
const fetchData = async (url = props.url) => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
|
@ -70,13 +71,17 @@ const fetchData = async (url = props.url) => {
|
||||||
? response.data.results.map((track: Track) => ({ track }))
|
? response.data.results.map((track: Track) => ({ track }))
|
||||||
: response.data.results
|
: response.data.results
|
||||||
|
|
||||||
objects.push(...newObjects)
|
objects.splice(0, objects.length, ...newObjects)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
useErrorHandler(error as Error)
|
useErrorHandler(error as Error)
|
||||||
}
|
} finally {
|
||||||
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchData()
|
||||||
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => store.state.moderation.lastUpdate,
|
() => store.state.moderation.lastUpdate,
|
||||||
|
@ -104,7 +109,7 @@ watch(() => props.websocketHandlers.includes('Listen'), (to) => {
|
||||||
console.log('Updated cover URL:', coverUrl.value);
|
console.log('Updated cover URL:', coverUrl.value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}, { immediate: true });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -119,7 +124,7 @@ watch(() => props.websocketHandlers.includes('Listen'), (to) => {
|
||||||
</h2>
|
</h2>
|
||||||
<Spacer :size="8" />
|
<Spacer :size="8" />
|
||||||
<Alert
|
<Alert
|
||||||
v-if="count === 0"
|
v-if="!isLoading && count === 0"
|
||||||
blue
|
blue
|
||||||
align-items="center"
|
align-items="center"
|
||||||
>
|
>
|
||||||
|
@ -127,7 +132,6 @@ watch(() => props.websocketHandlers.includes('Listen'), (to) => {
|
||||||
<i class="bi bi-search" />
|
<i class="bi bi-search" />
|
||||||
{{ t('components.audio.track.Widget.empty.noResults') }}
|
{{ t('components.audio.track.Widget.empty.noResults') }}
|
||||||
</h4>
|
</h4>
|
||||||
<Loader v-if="isLoading" />
|
|
||||||
</Alert>
|
</Alert>
|
||||||
<Section
|
<Section
|
||||||
v-if="count > 0"
|
v-if="count > 0"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Library } from '~/types'
|
import type { Library } from '~/types'
|
||||||
|
|
||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive, onMounted, watch } from 'vue'
|
||||||
import { useStore } from '~/store'
|
import { useStore } from '~/store'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ const fetchData = async (url = props.url) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
params: {
|
params: {
|
||||||
page_size: 6
|
page_size: 3
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -52,7 +52,13 @@ const fetchData = async (url = props.url) => {
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
fetchData()
|
fetchData()
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(() => props.url, () => {
|
||||||
|
fetchData()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in New Issue