From 07041ac8811e3326e34e4f1eb8a1a64b00175401 Mon Sep 17 00:00:00 2001 From: Marcin Macierzanka Date: Fri, 21 Aug 2026 21:45:25 +0200 Subject: [PATCH] feat: show optimistic history queue entries --- frontend/src/components/AddTrackPanel.vue | 5 +++ frontend/src/components/HistoryPanel.vue | 25 ++++++++---- frontend/src/components/QueuePanel.vue | 50 +++++++++++++++++++++-- frontend/src/composables/useBotStatus.ts | 23 ++++++++++- 4 files changed, 89 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/AddTrackPanel.vue b/frontend/src/components/AddTrackPanel.vue index c82f4d0..cfbdc02 100644 --- a/frontend/src/components/AddTrackPanel.vue +++ b/frontend/src/components/AddTrackPanel.vue @@ -2,12 +2,14 @@ import { ref } from 'vue' import { Plus, PlusCircle, Search } from 'lucide-vue-next' import { api } from '@/api/client' +import { useBotStatus } from '@/composables/useBotStatus' import { useToasts } from '@/composables/useToasts' import type { BotStatus } from '@/types/status' const props = defineProps<{ status: BotStatus | null }>() const { notify, run } = useToasts() +const { addPendingTrack, removePendingTrack } = useBotStatus() const query = ref('') const busy = ref(false) @@ -21,7 +23,10 @@ async function submit() { } busy.value = true + const guildId = props.status.active_voice_channel.guild_id + const pendingId = addPendingTrack(guildId, trimmed) const added = await run(() => api.play(trimmed), 'Dodano utwór do kolejki!', 'Błąd dodawania') + removePendingTrack(pendingId) if (added) query.value = '' busy.value = false } diff --git a/frontend/src/components/HistoryPanel.vue b/frontend/src/components/HistoryPanel.vue index a1f4424..a2ba640 100644 --- a/frontend/src/components/HistoryPanel.vue +++ b/frontend/src/components/HistoryPanel.vue @@ -2,6 +2,7 @@ import { computed } from 'vue' import { Clock, History, Plus, RotateCcw } from 'lucide-vue-next' import { api } from '@/api/client' +import { useBotStatus } from '@/composables/useBotStatus' import { useToasts } from '@/composables/useToasts' import { useUploads } from '@/composables/useUploads' import { formatTime } from '@/composables/useTrackProgress' @@ -11,6 +12,7 @@ import type { BotStatus, HistoryTrack } from '@/types/status' const props = defineProps<{ status: BotStatus | null }>() const { notify, run } = useToasts() +const { addPendingTrack, removePendingTrack } = useBotStatus() const { enqueue } = useUploads() const history = computed(() => props.status?.history ?? []) @@ -21,16 +23,21 @@ async function replay(entry: HistoryTrack) { return } - if (entry.is_local) { - const path = entry.filepath ?? entry.url ?? entry.title - await enqueue(path.split(/[\\/]/).pop() ?? path) - return + const pendingId = addPendingTrack(props.status.active_voice_channel.guild_id, entry.title) + try { + if (entry.is_local) { + const path = entry.filepath ?? entry.url ?? entry.title + await enqueue(path.split(/[\\/]/).pop() ?? path) + return + } + if (!entry.url) { + notify('Ten wpis historii nie ma źródła do odtworzenia', 'error') + return + } + await run(() => api.play(entry.url as string), 'Dodano z historii do kolejki!', 'Błąd') + } finally { + removePendingTrack(pendingId) } - if (!entry.url) { - notify('Ten wpis historii nie ma źródła do odtworzenia', 'error') - return - } - await run(() => api.play(entry.url as string), 'Dodano z historii do kolejki!', 'Błąd') } diff --git a/frontend/src/components/QueuePanel.vue b/frontend/src/components/QueuePanel.vue index d1cbf85..482e150 100644 --- a/frontend/src/components/QueuePanel.vue +++ b/frontend/src/components/QueuePanel.vue @@ -1,6 +1,6 @@