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 sessions = ref<ChatSession[]>([]);
|
||||
const activeSessionId = ref<number | null>(null);
|
||||
const composerKey = ref(0);
|
||||
const messages = ref<DisplayMessage[]>([]);
|
||||
const drawerOpen = ref(false);
|
||||
const sending = ref(false);
|
||||
@@ -127,6 +128,7 @@ async function loadSessions() {
|
||||
|
||||
async function createSession() {
|
||||
if (sessionOperationPending.value) return;
|
||||
composerKey.value += 1;
|
||||
const existingBlank = sessions.value.find((session) => session.messageCount === 0);
|
||||
if (existingBlank) {
|
||||
await selectSession(existingBlank.id);
|
||||
@@ -643,7 +645,7 @@ async function copyText(text: string) {
|
||||
@retry="retryMessage"
|
||||
@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
|
||||
:open="drawerOpen"
|
||||
:sessions="sessions"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
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 { 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(() => {
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user