refactor: improve connection status and history loading logic
This commit is contained in:
parent
66c349d41f
commit
e551ad7848
4 changed files with 26 additions and 21 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
<div class="message-body">
|
<div class="message-body">
|
||||||
<span class="icon"><i class="fas fa-info-circle" /></span>
|
<span class="icon"><i class="fas fa-info-circle" /></span>
|
||||||
<span>
|
<span>
|
||||||
Connection lost, <NuxtLink class="is-bold" @click.prevent="() => $emit('reconnect')">Click here</NuxtLink>
|
Websocket connection lost, <NuxtLink class="is-bold" @click.prevent="() => $emit('reconnect')">Click here</NuxtLink>
|
||||||
to reconnect.
|
to reconnect.
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -583,7 +583,7 @@ watch(showCompleted, async isShown => {
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (showCompleted.value) {
|
if (showCompleted.value && !paginationInfo.value.isLoaded) {
|
||||||
try {
|
try {
|
||||||
await stateStore.loadPaginated('history', 1, config.app.default_pagination, 'DESC', true)
|
await stateStore.loadPaginated('history', 1, config.app.default_pagination, 'DESC', true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
<template v-if="!isMobile">{{ greetingMessage }}</template>
|
<template v-if="!isMobile">{{ greetingMessage }}</template>
|
||||||
<template v-else>What would you like to download?</template>
|
<template v-else>What would you like to download?</template>
|
||||||
<span class="is-pulled-right">
|
<span class="is-pulled-right">
|
||||||
<span class="icon has-text-info is-pointer mr-2" v-if="!socketStore.isConnected" v-tooltip="'Reload queue'"
|
<span class="icon has-text-info is-pointer mr-2" v-if="!socketStore.isConnected"
|
||||||
@click="async () => await refreshQueue()">
|
v-tooltip="'Reload queue'" @click="async () => await refreshQueue()">
|
||||||
<i class="fas fa-sync-alt" :class="{ 'fa-spin': isRefreshing }" />
|
<i class="fas fa-sync-alt" :class="{ 'fa-spin': isRefreshing }" />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
@ -273,7 +273,6 @@ const refreshQueue = async (): Promise<void> => {
|
||||||
} finally {
|
} finally {
|
||||||
isRefreshing.value = false
|
isRefreshing.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const paginationInfo = computed(() => stateStore.getPagination())
|
const paginationInfo = computed(() => stateStore.getPagination())
|
||||||
|
|
@ -691,10 +690,12 @@ onMounted(async () => {
|
||||||
window.history.replaceState({}, '', url.toString())
|
window.history.replaceState({}, '', url.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (!paginationInfo.value.isLoaded) {
|
||||||
await stateStore.loadPaginated('history', 1, DEFAULT_PAGE_SIZE, 'DESC')
|
try {
|
||||||
} catch (error) {
|
await stateStore.loadPaginated('history', 1, DEFAULT_PAGE_SIZE, 'DESC')
|
||||||
console.error('Failed to load history on mount:', error)
|
} catch (error) {
|
||||||
|
console.error('Failed to load history on mount:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window?.location && '/' !== window.location.pathname) {
|
if (window?.location && '/' !== window.location.pathname) {
|
||||||
|
|
@ -702,7 +703,6 @@ onMounted(async () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Reload history when socket reconnects
|
|
||||||
watch(() => socketStore.isConnected, async (connected) => {
|
watch(() => socketStore.isConnected, async (connected) => {
|
||||||
if (connected && !paginationInfo.value.isLoaded) {
|
if (connected && !paginationInfo.value.isLoaded) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -713,7 +713,6 @@ watch(() => socketStore.isConnected, async (connected) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Function to load more history items
|
|
||||||
const loadMoreHistory = async (): Promise<void> => {
|
const loadMoreHistory = async (): Promise<void> => {
|
||||||
if (paginationInfo.value.isLoading || paginationInfo.value.page >= paginationInfo.value.total_pages) {
|
if (paginationInfo.value.isLoading || paginationInfo.value.page >= paginationInfo.value.total_pages) {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
|
|
||||||
<template v-if="simpleMode">
|
<template v-if="simpleMode">
|
||||||
|
<Connection :status="socket.connectionStatus" @reconnect="() => socket.reconnect()" />
|
||||||
<Simple @show_settings="() => show_settings = true" :class="{ 'settings-open': show_settings }" />
|
<Simple @show_settings="() => show_settings = true" :class="{ 'settings-open': show_settings }" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -12,7 +13,6 @@
|
||||||
<div id="main_container" class="container" :class="{ 'settings-open': show_settings }" v-else>
|
<div id="main_container" class="container" :class="{ 'settings-open': show_settings }" v-else>
|
||||||
<NewVersion v-if="newVersionIsAvailable" />
|
<NewVersion v-if="newVersionIsAvailable" />
|
||||||
<nav class="navbar is-mobile is-dark">
|
<nav class="navbar is-mobile is-dark">
|
||||||
|
|
||||||
<div class="navbar-brand pl-5">
|
<div class="navbar-brand pl-5">
|
||||||
<NuxtLink class="navbar-item is-text-overflow" to="/" @click.prevent="(e: MouseEvent) => changeRoute(e)"
|
<NuxtLink class="navbar-item is-text-overflow" to="/" @click.prevent="(e: MouseEvent) => changeRoute(e)"
|
||||||
v-tooltip="socket.isConnected ? 'Connected' : 'Connecting'" id="top">
|
v-tooltip="socket.isConnected ? 'Connected' : 'Connecting'" id="top">
|
||||||
|
|
@ -157,7 +157,15 @@
|
||||||
</ClientOnly>
|
</ClientOnly>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="footer py-5 mt-6 is-unselectable" v-if="config.is_loaded">
|
<div class="mt-6">
|
||||||
|
<div class="columns is-multiline">
|
||||||
|
<div class="column is-12">
|
||||||
|
<Connection :status="socket.connectionStatus" @reconnect="() => socket.reconnect()" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="footer py-5 is-unselectable" v-if="config.is_loaded">
|
||||||
<div class="columns is-multiline is-variable is-8">
|
<div class="columns is-multiline is-variable is-8">
|
||||||
<div class="column is-12-mobile is-6-tablet">
|
<div class="column is-12-mobile is-6-tablet">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
|
@ -422,20 +430,18 @@ onMounted(async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await config.loadConfig()
|
await config.loadConfig()
|
||||||
} catch {
|
} catch { }
|
||||||
// -- IGNORE --
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const opts = await request('/api/yt-dlp/options')
|
const opts = await request('/api/yt-dlp/options')
|
||||||
if (!opts.ok) {
|
if (opts.ok) {
|
||||||
return
|
config.ytdlp_options = await opts.json() as Array<YTDLPOption>
|
||||||
}
|
}
|
||||||
const data: Array<YTDLPOption> = await opts.json()
|
|
||||||
config.ytdlp_options = data
|
|
||||||
} catch { }
|
} catch { }
|
||||||
|
|
||||||
socket.connect()
|
try {
|
||||||
|
socket.connect()
|
||||||
|
} catch { }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await handleImage(bg_enable.value)
|
await handleImage(bg_enable.value)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue