This commit is contained in:
2026-04-20 13:03:29 -04:00
parent 505c7e612c
commit f50a176252
2 changed files with 75 additions and 27 deletions

View File

@@ -1,10 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted, onUnmounted } from 'vue'; import { ref, computed, onMounted, onUnmounted } from 'vue';
import { storeToRefs } from 'pinia';
import { ChevronDown, Check, ArrowRightLeft, Trash2, FileText, Plus, Loader2, Send, User, Type, Copy, Save } from 'lucide-vue-next'; import { ChevronDown, Check, ArrowRightLeft, Trash2, FileText, Plus, Loader2, Send, User, Type, Copy, Save } from 'lucide-vue-next';
import { listen } from '@tauri-apps/api/event'; import { listen } from '@tauri-apps/api/event';
import { useSettingsStore, LANGUAGES, SPEAKER_IDENTITY_OPTIONS, TONE_REGISTER_OPTIONS } from '../stores/settings'; import { useSettingsStore, LANGUAGES, SPEAKER_IDENTITY_OPTIONS, TONE_REGISTER_OPTIONS } from '../stores/settings';
import { useHistoryStore } from '../stores/history'; import { useHistoryStore } from '../stores/history';
import { useLogsStore } from '../stores/logs'; import { useLogsStore } from '../stores/logs';
import { useTranslationWorkspaceStore } from '../stores/translation-workspace';
import { cn } from '../lib/utils'; import { cn } from '../lib/utils';
import { useClipboard } from '../composables/useClipboard'; import { useClipboard } from '../composables/useClipboard';
import { import {
@@ -12,7 +14,6 @@ import {
extractAssistantContent, extractAssistantContent,
resolveModelConfig, resolveModelConfig,
tryParseEvaluationResult, tryParseEvaluationResult,
type EvaluationResult,
type TranslationChunkEvent, type TranslationChunkEvent,
type TranslationPayload, type TranslationPayload,
} from '../lib/translation-service'; } from '../lib/translation-service';
@@ -20,7 +21,21 @@ import {
const settings = useSettingsStore(); const settings = useSettingsStore();
const historyStore = useHistoryStore(); const historyStore = useHistoryStore();
const logsStore = useLogsStore(); const logsStore = useLogsStore();
const workspaceStore = useTranslationWorkspaceStore();
const { activeCopyId, copyWithFeedback } = useClipboard(); const { activeCopyId, copyWithFeedback } = useClipboard();
const {
sourceText,
context,
targetText,
isTranslating,
currentHistoryId,
evaluationResult,
isEvaluating,
isRefining,
selectedSuggestionIds,
appliedSuggestionIds,
activeStreamRequestId,
} = storeToRefs(workspaceStore);
const sourceDropdownOpen = ref(false); const sourceDropdownOpen = ref(false);
const targetDropdownOpen = ref(false); const targetDropdownOpen = ref(false);
@@ -57,26 +72,6 @@ const handleGlobalClick = (e: MouseEvent) => {
onMounted(() => window.addEventListener('click', handleGlobalClick)); onMounted(() => window.addEventListener('click', handleGlobalClick));
onUnmounted(() => window.removeEventListener('click', handleGlobalClick)); onUnmounted(() => window.removeEventListener('click', handleGlobalClick));
const sourceText = ref('');
const context = ref('');
const targetText = ref('');
const isTranslating = ref(false);
const currentHistoryId = ref<string | null>(null);
const evaluationResult = ref<EvaluationResult | null>(null);
const isEvaluating = ref(false);
const isRefining = ref(false);
const selectedSuggestionIds = ref<number[]>([]);
const appliedSuggestionIds = ref<number[]>([]);
const activeStreamRequestId = ref<string | null>(null);
const toggleSuggestion = (id: number) => {
if (!selectedSuggestionIds.value) selectedSuggestionIds.value = [];
const index = selectedSuggestionIds.value.indexOf(id);
if (index > -1) selectedSuggestionIds.value.splice(index, 1);
else selectedSuggestionIds.value.push(id);
};
let unlisten: (() => void) | null = null; let unlisten: (() => void) | null = null;
onMounted(async () => { onMounted(async () => {
unlisten = await listen<TranslationChunkEvent>('translation-chunk', (event) => { unlisten = await listen<TranslationChunkEvent>('translation-chunk', (event) => {
@@ -110,17 +105,17 @@ const swapLanguages = () => {
}; };
const clearSource = () => { const clearSource = () => {
sourceText.value = ''; workspaceStore.clearWorkspace();
targetText.value = ''; };
evaluationResult.value = null;
const toggleSuggestion = (id: number) => {
workspaceStore.toggleSuggestion(id);
}; };
const evaluateTranslation = async () => { const evaluateTranslation = async () => {
if (!targetText.value) return; if (!targetText.value) return;
isEvaluating.value = true; isEvaluating.value = true;
evaluationResult.value = null; workspaceStore.resetEvaluationState();
selectedSuggestionIds.value = [];
appliedSuggestionIds.value = [];
const modelConfig = resolveModelConfig({ const modelConfig = resolveModelConfig({
apiBaseUrl: settings.apiBaseUrl, apiBaseUrl: settings.apiBaseUrl,

View File

@@ -0,0 +1,53 @@
import { ref } from 'vue';
import { defineStore } from 'pinia';
import type { EvaluationResult } from '../lib/translation-service';
export const useTranslationWorkspaceStore = defineStore('translationWorkspace', () => {
const sourceText = ref('');
const context = ref('');
const targetText = ref('');
const isTranslating = ref(false);
const currentHistoryId = ref<string | null>(null);
const evaluationResult = ref<EvaluationResult | null>(null);
const isEvaluating = ref(false);
const isRefining = ref(false);
const selectedSuggestionIds = ref<number[]>([]);
const appliedSuggestionIds = ref<number[]>([]);
const activeStreamRequestId = ref<string | null>(null);
const resetEvaluationState = () => {
evaluationResult.value = null;
selectedSuggestionIds.value = [];
appliedSuggestionIds.value = [];
};
const clearWorkspace = () => {
sourceText.value = '';
targetText.value = '';
resetEvaluationState();
};
const toggleSuggestion = (id: number) => {
const index = selectedSuggestionIds.value.indexOf(id);
if (index > -1) selectedSuggestionIds.value.splice(index, 1);
else selectedSuggestionIds.value.push(id);
};
return {
sourceText,
context,
targetText,
isTranslating,
currentHistoryId,
evaluationResult,
isEvaluating,
isRefining,
selectedSuggestionIds,
appliedSuggestionIds,
activeStreamRequestId,
resetEvaluationState,
clearWorkspace,
toggleSuggestion,
};
});