fix: refresh voice config only on chat lifecycle
This commit is contained in:
@@ -15,6 +15,7 @@ import type { ChatMessage as ApiMessage, ChatSession, PeriodicReport, PracticeRe
|
|||||||
const user = ref<UserProfile | null>(null);
|
const user = ref<UserProfile | null>(null);
|
||||||
const sessions = ref<ChatSession[]>([]);
|
const sessions = ref<ChatSession[]>([]);
|
||||||
const activeSessionId = ref<number | null>(null);
|
const activeSessionId = ref<number | null>(null);
|
||||||
|
const composerKey = ref(0);
|
||||||
const messages = ref<DisplayMessage[]>([]);
|
const messages = ref<DisplayMessage[]>([]);
|
||||||
const drawerOpen = ref(false);
|
const drawerOpen = ref(false);
|
||||||
const sending = ref(false);
|
const sending = ref(false);
|
||||||
@@ -127,6 +128,7 @@ async function loadSessions() {
|
|||||||
|
|
||||||
async function createSession() {
|
async function createSession() {
|
||||||
if (sessionOperationPending.value) return;
|
if (sessionOperationPending.value) return;
|
||||||
|
composerKey.value += 1;
|
||||||
const existingBlank = sessions.value.find((session) => session.messageCount === 0);
|
const existingBlank = sessions.value.find((session) => session.messageCount === 0);
|
||||||
if (existingBlank) {
|
if (existingBlank) {
|
||||||
await selectSession(existingBlank.id);
|
await selectSession(existingBlank.id);
|
||||||
@@ -643,7 +645,7 @@ async function copyText(text: string) {
|
|||||||
@retry="retryMessage"
|
@retry="retryMessage"
|
||||||
@feedback="openFeedback"
|
@feedback="openFeedback"
|
||||||
/>
|
/>
|
||||||
<ChatComposer :loading="sending" :disabled="!activeSessionId || loadingSession" @send="send" @stop="stop" />
|
<ChatComposer :key="composerKey" :loading="sending" :disabled="!activeSessionId || loadingSession" @send="send" @stop="stop" />
|
||||||
<SessionDrawer
|
<SessionDrawer
|
||||||
:open="drawerOpen"
|
:open="drawerOpen"
|
||||||
:sessions="sessions"
|
:sessions="sessions"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Mic, Send, Square, X } from "@lucide/vue";
|
import { Mic, Send, Square, X } from "@lucide/vue";
|
||||||
import { nextTick, onMounted, onUnmounted, ref } from "vue";
|
import { nextTick, onMounted, ref } from "vue";
|
||||||
|
|
||||||
import { useVoiceRecorder } from "../composables/useVoiceRecorder";
|
import { useVoiceRecorder } from "../composables/useVoiceRecorder";
|
||||||
import { api, transcribeVoice } from "../services/api";
|
import { api, transcribeVoice } from "../services/api";
|
||||||
@@ -47,23 +47,8 @@ async function refreshVoiceConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshVoiceConfigWhenVisible() {
|
|
||||||
if (document.visibilityState === "visible") void refreshVoiceConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
let voiceConfigTimer: number | undefined;
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
void refreshVoiceConfig();
|
void refreshVoiceConfig();
|
||||||
window.addEventListener("focus", refreshVoiceConfigWhenVisible);
|
|
||||||
document.addEventListener("visibilitychange", refreshVoiceConfigWhenVisible);
|
|
||||||
voiceConfigTimer = window.setInterval(refreshVoiceConfigWhenVisible, 30_000);
|
|
||||||
});
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
window.removeEventListener("focus", refreshVoiceConfigWhenVisible);
|
|
||||||
document.removeEventListener("visibilitychange", refreshVoiceConfigWhenVisible);
|
|
||||||
if (voiceConfigTimer !== undefined) window.clearInterval(voiceConfigTimer);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
|
|||||||
Reference in New Issue
Block a user