Luca448 commited on
Commit
5ada30a
·
1 Parent(s): c99371f

Savestate: Implement 2-step translate-and-add button flow in Schnelleingabe

Browse files
Files changed (2) hide show
  1. index.html +1 -1
  2. src/views/vocabulary-modal.js +40 -35
index.html CHANGED
@@ -74,7 +74,7 @@
74
  </head>
75
  <body class="dark-theme in-chat-view">
76
 
77
- <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.297</div>
78
 
79
  <!-- SVG Filters for Liquid Glass Refraction -->
80
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
 
74
  </head>
75
  <body class="dark-theme in-chat-view">
76
 
77
+ <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.298</div>
78
 
79
  <!-- SVG Filters for Liquid Glass Refraction -->
80
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
src/views/vocabulary-modal.js CHANGED
@@ -46,11 +46,10 @@ export function showVocabularyModal() {
46
  <div class="vocabulary-actions">
47
  <button class="vocabulary-btn cancel" id="voc-cancel">Abbrechen</button>
48
  <button class="vocabulary-btn submit" id="voc-submit">
49
- <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
50
- <line x1="12" y1="5" x2="12" y2="19"></line>
51
- <line x1="5" y1="12" x2="19" y2="12"></line>
52
  </svg>
53
- Hinzufügen
54
  </button>
55
  </div>
56
 
@@ -126,16 +125,42 @@ Nur das rohe JSON:`;
126
  const word = input.value.trim();
127
  if (!word) return;
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  submitBtn.disabled = true;
130
  loading.classList.add('active');
131
 
132
  try {
133
  let parsed = currentTranslationResult;
134
-
135
- // If we don't have a cached preview for the exact word, fetch it now
136
- if (!parsed || currentPreviewWord !== word) {
137
- parsed = await fetchAITranslation(word);
138
- }
139
 
140
  // 2. Save to Vault (Flashcard DB)
141
  let decks = db.getDecks();
@@ -186,36 +211,16 @@ Nur das rohe JSON:`;
186
 
187
  input.addEventListener('input', () => {
188
  const word = input.value.trim();
189
- clearTimeout(debounceTimeout);
190
-
191
- if (!word) {
192
- previewContainer.style.display = 'none';
193
- currentTranslationResult = null;
194
- currentPreviewWord = '';
195
- return;
196
- }
197
 
198
  if (word !== currentPreviewWord) {
199
- currentPreviewWord = word;
200
  currentTranslationResult = null;
 
 
201
 
202
- debounceTimeout = setTimeout(async () => {
203
- previewContainer.style.display = 'block';
204
- previewText.innerHTML = '<span style="opacity: 0.5; font-size: 14px; font-weight: normal;">KI denkt nach...</span>';
205
-
206
- try {
207
- const parsed = await fetchAITranslation(word);
208
- // Only update if the user hasn't typed something else in the meantime
209
- if (input.value.trim() === word) {
210
- currentTranslationResult = parsed;
211
- previewText.innerHTML = parsed.back;
212
- }
213
- } catch (error) {
214
- if (input.value.trim() === word) {
215
- previewText.innerHTML = '<span style="color: #ff3b30; font-size: 14px;">Fehler</span>';
216
- }
217
- }
218
- }, 800);
219
  }
220
  });
221
 
 
46
  <div class="vocabulary-actions">
47
  <button class="vocabulary-btn cancel" id="voc-cancel">Abbrechen</button>
48
  <button class="vocabulary-btn submit" id="voc-submit">
49
+ <svg id="voc-submit-icon" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
50
+ <circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path>
 
51
  </svg>
52
+ <span id="voc-submit-text">Übersetzen</span>
53
  </button>
54
  </div>
55
 
 
125
  const word = input.value.trim();
126
  if (!word) return;
127
 
128
+ if (!currentTranslationResult || currentPreviewWord !== word) {
129
+ // MODE 1: TRANSLATE
130
+ submitBtn.disabled = true;
131
+ document.getElementById('voc-submit-text').innerText = 'Übersetze...';
132
+
133
+ previewContainer.style.display = 'block';
134
+ previewText.innerHTML = '<span style="opacity: 0.5; font-size: 14px; font-weight: normal;">KI denkt nach...</span>';
135
+
136
+ try {
137
+ const parsed = await fetchAITranslation(word);
138
+ if (input.value.trim() === word) {
139
+ currentTranslationResult = parsed;
140
+ currentPreviewWord = word;
141
+ previewText.innerHTML = parsed.back;
142
+
143
+ // Switch to "Hinzufügen" mode
144
+ document.getElementById('voc-submit-text').innerText = 'Hinzufügen';
145
+ document.getElementById('voc-submit-icon').innerHTML = '<line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line>';
146
+ submitBtn.disabled = false;
147
+ }
148
+ } catch (error) {
149
+ if (input.value.trim() === word) {
150
+ previewText.innerHTML = '<span style="color: #ff3b30; font-size: 14px;">Fehler</span>';
151
+ document.getElementById('voc-submit-text').innerText = 'Übersetzen';
152
+ submitBtn.disabled = false;
153
+ }
154
+ }
155
+ return;
156
+ }
157
+
158
+ // MODE 2: SAVE
159
  submitBtn.disabled = true;
160
  loading.classList.add('active');
161
 
162
  try {
163
  let parsed = currentTranslationResult;
 
 
 
 
 
164
 
165
  // 2. Save to Vault (Flashcard DB)
166
  let decks = db.getDecks();
 
211
 
212
  input.addEventListener('input', () => {
213
  const word = input.value.trim();
 
 
 
 
 
 
 
 
214
 
215
  if (word !== currentPreviewWord) {
 
216
  currentTranslationResult = null;
217
+ currentPreviewWord = '';
218
+ previewContainer.style.display = 'none';
219
 
220
+ // Revert button to "Übersetzen" mode
221
+ document.getElementById('voc-submit-text').innerText = 'Übersetzen';
222
+ document.getElementById('voc-submit-icon').innerHTML = '<circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path>';
223
+ submitBtn.disabled = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  }
225
  });
226