Skip to content

Commit 89d5bee

Browse files
Y-RyuZUclaude
andcommitted
refactor: clean up settings dialog and improve code quality
- Remove BackupSettings and UISettings sections from settings dialog - Fix React hooks order issue in LLMSettings component - Add missing mock handlers for logging commands in E2E tests - Move console.log statements to development-only mode - Remove duplicate progress callbacks to prevent redundant updates - Fix ESLint warnings for unused parameters This simplifies the settings interface by removing unused sections and improves code quality with better error handling and cleaner logs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f6db345 commit 89d5bee

File tree

13 files changed

+61
-83
lines changed

13 files changed

+61
-83
lines changed

src/__tests__/e2e/backup-system-e2e.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ describe('Backup System E2E Tests', () => {
120120
]
121121
};
122122

123+
// Handle logging commands
124+
case 'log_translation_start':
125+
case 'log_translation_statistics':
126+
case 'log_translation_process':
127+
case 'log_translation_completion':
128+
case 'log_error':
129+
case 'log_file_operation':
130+
// Mock logging - just return success
131+
return;
132+
123133
default:
124134
throw new Error(`Unknown command: ${command}`);
125135
}

src/components/settings/backup-settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface BackupSettingsProps {
1010
setConfig: (config: AppConfig) => void;
1111
}
1212

13-
export function BackupSettings({ config, setConfig }: BackupSettingsProps) {
13+
export function BackupSettings({ }: BackupSettingsProps) {
1414
const { t } = useAppTranslation();
1515

1616
return (

src/components/settings/llm-settings.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ export function LLMSettings({ config, setConfig }: LLMSettingsProps) {
2020
const { t, ready } = useAppTranslation();
2121
const [showApiKey, setShowApiKey] = useState(false);
2222

23-
// Don't render until translations are loaded
24-
if (!ready) {
25-
return <div className="animate-pulse h-96 bg-muted rounded-lg" />;
26-
}
27-
2823
// Initialize apiKeys if not present
2924
if (!config.llm.apiKeys) {
3025
config.llm.apiKeys = {
@@ -98,6 +93,11 @@ export function LLMSettings({ config, setConfig }: LLMSettingsProps) {
9893
}
9994
}, [config, setConfig]);
10095

96+
// Don't render until translations are loaded
97+
if (!ready) {
98+
return <div className="animate-pulse h-96 bg-muted rounded-lg" />;
99+
}
100+
101101
// Get provider display name
102102
const getProviderDisplayName = (provider: string) => {
103103
switch (provider) {

src/components/settings/settings-dialog.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { Card, CardContent } from "@/components/ui/card";
99
import { LLMSettings } from "@/components/settings/llm-settings";
1010
import { TranslationSettings } from "@/components/settings/translation-settings";
1111
import { PathSettings } from "@/components/settings/path-settings";
12-
import { UISettings } from "@/components/settings/ui-settings";
13-
import { BackupSettings } from "@/components/settings/backup-settings";
1412
import { useAppStore } from "@/lib/store";
1513
import { ConfigService } from "@/lib/services/config-service";
1614
import { FileService } from "@/lib/services/file-service";
@@ -124,12 +122,6 @@ export function SettingsDialog() {
124122
{/* Path Settings */}
125123
<PathSettings config={config} onSelectDirectory={handleSelectDirectory} />
126124

127-
{/* UI Settings */}
128-
<UISettings config={config} setConfig={setConfig} />
129-
130-
{/* Backup Settings */}
131-
<BackupSettings config={config} setConfig={setConfig} />
132-
133125
{/* Reset Button */}
134126
<Card>
135127
<CardContent className="pt-6">

src/components/tabs/common/translation-tab.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ export function TranslationTab({
162162

163163
// Log the selection type for debugging
164164
if (selected.startsWith("NATIVE_DIALOG:")) {
165-
console.log("Native dialog was used!");
165+
if (process.env.NODE_ENV === 'development') {
166+
console.log("Native dialog was used!");
167+
}
166168
} else {
167-
console.log("Mock dialog was used!");
168-
// Only show warning in development mode
169169
if (process.env.NODE_ENV === 'development') {
170+
console.log("Mock dialog was used!");
170171
setError("Warning: Mock dialog was used instead of native dialog");
171172
}
172173
}
@@ -247,6 +248,8 @@ export function TranslationTab({
247248
// Reset cancellation flag
248249
wasCancelledRef.current = false;
249250

251+
// Reset translation state immediately
252+
resetTranslationState();
250253
setTranslating(true);
251254
setProgress(0);
252255
setWholeProgress(0);
@@ -286,13 +289,9 @@ export function TranslationTab({
286289
// Token-based chunking configuration
287290
useTokenBasedChunking: config.translation.useTokenBasedChunking,
288291
maxTokensPerChunk: config.translation.maxTokensPerChunk,
289-
fallbackToEntryBased: config.translation.fallbackToEntryBased,
290-
onProgress: (job) => {
291-
// Update individual job progress (bounded 0-100)
292-
const boundedProgress = Math.max(0, Math.min(100, job.progress || 0));
293-
console.log(`[TranslationTab] onProgress called: ${boundedProgress}%`);
294-
setProgress(boundedProgress);
295-
}
292+
fallbackToEntryBased: config.translation.fallbackToEntryBased
293+
// Remove onProgress callback to prevent duplicate updates
294+
// Progress is now handled directly by translation-runner.ts
296295
});
297296

298297
// Store the translation service in the ref
@@ -466,11 +465,6 @@ export function TranslationTab({
466465
<p className="text-sm text-muted-foreground">
467466
{t('progress.wholeProgress')} {wholeProgress}%
468467
</p>
469-
{process.env.NODE_ENV === 'development' && (
470-
<p className="text-xs text-gray-500">
471-
Debug: wholeProgress = {wholeProgress}
472-
</p>
473-
)}
474468
</div>
475469
</div>
476470
<div className="flex items-center gap-2">
@@ -575,7 +569,7 @@ export function TranslationTab({
575569
.filter(t => t.id === target.id)
576570
.length > 1;
577571

578-
if (duplicateIds) {
572+
if (duplicateIds && process.env.NODE_ENV === 'development') {
579573
console.log(`重複したtarget.id: ${target.id} ${target.name}`);
580574
}
581575

src/components/tabs/custom-files-tab.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export function CustomFilesTab() {
109109
const totalFiles = sortedTargets.length;
110110
setTotalChunks(totalFiles); // Track at file level
111111
setTotalCustomFiles(totalFiles);
112-
console.log(`CustomFilesTab: Set totalCustomFiles to ${totalFiles} for custom files-level progress tracking`);
113112

114113
// Create jobs for all files
115114
const jobs: Array<{

src/components/tabs/guidebooks-tab.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ export function GuidebooksTab() {
110110

111111
// Set total guidebooks for progress tracking
112112
setTotalGuidebooks(sortedTargets.length);
113-
console.log(`GuidebooksTab: Set totalGuidebooks to ${sortedTargets.length} for guidebook-level progress tracking`);
114113

115114
// Prepare jobs and count total chunks
116115
let totalChunksCount = 0;
@@ -168,7 +167,6 @@ export function GuidebooksTab() {
168167
// Ensure totalChunks is set correctly, fallback to jobs.length if calculation failed
169168
const finalTotalChunks = totalChunksCount > 0 ? totalChunksCount : jobs.length;
170169
setTotalChunks(finalTotalChunks);
171-
console.log(`GuidebooksTab: Set totalChunks to ${finalTotalChunks} for ${jobs.length} jobs`);
172170

173171
// Set currentJobId to the first job's ID immediately (enables cancel button promptly)
174172
if (jobs.length > 0) {

src/components/tabs/mods-tab.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export function ModsTab() {
120120
) => {
121121
// Sort targets alphabetically by name for predictable processing order
122122
const sortedTargets = [...selectedTargets].sort((a, b) => a.name.localeCompare(b.name));
123-
console.log(`ModsTab: Processing ${sortedTargets.length} mods in alphabetical order:`, sortedTargets.map(t => t.name));
124123
// Always set resource packs directory to <selectedDirectory>/resourcepacks
125124
const resourcePacksDir = selectedDirectory.replace(/[/\\]+$/, "") + "/resourcepacks";
126125

@@ -189,11 +188,9 @@ export function ModsTab() {
189188

190189
// Use mod-level progress tracking: denominator = total mods, numerator = completed mods
191190
setTotalMods(sortedTargets.length);
192-
console.log(`ModsTab: Set totalMods to ${sortedTargets.length} for mod-level progress tracking`);
193191

194192
// Set chunk tracking for progress calculation
195193
setTotalChunks(totalChunksCount);
196-
console.log(`ModsTab: Set totalChunks to ${totalChunksCount} for chunk-level progress tracking`);
197194

198195
// Set currentJobId to the first job's ID immediately (enables cancel button promptly)
199196
if (jobs.length > 0) {
@@ -265,7 +262,6 @@ export function ModsTab() {
265262
packPath: resourcePackDir,
266263
sessionPath: sessionPath
267264
});
268-
console.log(`Backed up resource pack: ${resourcePackDir}`);
269265
} catch (error) {
270266
console.error('Failed to backup resource pack:', error);
271267
// Don't fail the translation if backup fails

src/components/tabs/quests-tab.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ export function QuestsTab() {
139139

140140
// Set total quests for progress tracking
141141
setTotalQuests(sortedTargets.length);
142-
console.log(`QuestsTab: Set totalQuests to ${sortedTargets.length} for quest-level progress tracking`);
143-
const totalQuests = sortedTargets.length;
142+
const totalQuests = sortedTargets.length;
144143
setTotalChunks(totalQuests); // For quests, we track at file level instead of chunk level
145144

146145
// Generate session ID for this translation
@@ -164,8 +163,7 @@ export function QuestsTab() {
164163
files: snbtFiles,
165164
sessionPath: sessionPath
166165
});
167-
console.log(`Backed up ${snbtFiles.length} SNBT files`);
168-
} catch (error) {
166+
} catch (error) {
169167
console.error('Failed to backup SNBT files:', error);
170168
// Continue with translation even if backup fails
171169
}

src/components/ui/translation-history-dialog.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const formatSessionId = (id: string) => {
5454
// Format: YYYY-MM-DD_HH-MM-SS
5555
const match = id.match(/(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})/);
5656
if (match) {
57-
const [_, year, month, day, hour, minute, second] = match;
57+
const [, year, month, day, hour, minute, second] = match;
5858
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
5959
}
6060
return id;
@@ -64,7 +64,7 @@ const formatSessionId = (id: string) => {
6464
const parseSessionId = (id: string): Date => {
6565
const match = id.match(/(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})/);
6666
if (match) {
67-
const [_, year, month, day, hour, minute, second] = match;
67+
const [, year, month, day, hour, minute, second] = match;
6868
return new Date(parseInt(year), parseInt(month) - 1, parseInt(day), parseInt(hour), parseInt(minute), parseInt(second));
6969
}
7070
return new Date();
@@ -164,7 +164,7 @@ function SessionRow({ sessionSummary, onToggle, minecraftDir, updateSession }: {
164164
}) {
165165
const { t } = useAppTranslation();
166166

167-
const loadSummary = async () => {
167+
const loadSummary = useCallback(async () => {
168168
if (sessionSummary.summary) return;
169169

170170
updateSession(sessionSummary.sessionId, { loading: true });
@@ -192,13 +192,13 @@ function SessionRow({ sessionSummary, onToggle, minecraftDir, updateSession }: {
192192
loading: false
193193
});
194194
}
195-
};
195+
}, [sessionSummary.sessionId, sessionSummary.summary, updateSession, minecraftDir]);
196196

197197
useEffect(() => {
198198
if (sessionSummary.expanded && !sessionSummary.summary && !sessionSummary.loading) {
199199
loadSummary();
200200
}
201-
}, [sessionSummary.expanded]);
201+
}, [sessionSummary.expanded, sessionSummary.summary, sessionSummary.loading, loadSummary]);
202202

203203
return (
204204
<>

0 commit comments

Comments
 (0)