Luca448 commited on
Commit
03d066e
·
1 Parent(s): c20f1e2

Savestate: Frontend Routing & Vokabel-Schnelleingabe Modal implementiert

Browse files
.superpowers/sdd/progress.md CHANGED
Binary files a/.superpowers/sdd/progress.md and b/.superpowers/sdd/progress.md differ
 
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.262</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.263</div>
78
 
79
  <!-- SVG Filters for Liquid Glass Refraction -->
80
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
src/app.js CHANGED
@@ -5,6 +5,7 @@ import { authService } from './services/auth-service.js';
5
  import { syncManager } from './services/sync-service.js';
6
  import { ttsService } from './services/tts-service.js';
7
  import { appShortcutsService } from './services/app-shortcuts-service.js';
 
8
  window.ttsService = ttsService;
9
 
10
  window.appPrompt = function(message) {
@@ -1192,4 +1193,17 @@ document.addEventListener('DOMContentLoaded', () => {
1192
  window.location.reload();
1193
  }
1194
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
1195
  });
 
5
  import { syncManager } from './services/sync-service.js';
6
  import { ttsService } from './services/tts-service.js';
7
  import { appShortcutsService } from './services/app-shortcuts-service.js';
8
+ import { showVocabularyModal } from './views/vocabulary-modal.js';
9
  window.ttsService = ttsService;
10
 
11
  window.appPrompt = function(message) {
 
1193
  window.location.reload();
1194
  }
1195
  });
1196
+
1197
+ // Handle App Shortcuts and Intents (Task 3)
1198
+ window.addEventListener('appShortcutAction', (e) => {
1199
+ if (e.detail && e.detail.shortcutId === 'add_vocabulary') {
1200
+ showVocabularyModal();
1201
+ }
1202
+ });
1203
+
1204
+ // Also catch if it was launched directly and stored in window
1205
+ if (window.pendingAppShortcut === 'add_vocabulary') {
1206
+ showVocabularyModal();
1207
+ window.pendingAppShortcut = null;
1208
+ }
1209
  });
src/styles/vocabulary-modal.css ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .vocabulary-modal-overlay {
2
+ position: fixed;
3
+ inset: 0;
4
+ background: rgba(0, 0, 0, 0.6);
5
+ backdrop-filter: blur(20px);
6
+ -webkit-backdrop-filter: blur(20px);
7
+ z-index: 10000;
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+ padding: 20px;
12
+ opacity: 0;
13
+ transition: opacity 0.3s ease;
14
+ }
15
+
16
+ .vocabulary-modal-overlay.show {
17
+ opacity: 1;
18
+ }
19
+
20
+ .vocabulary-modal {
21
+ width: 100%;
22
+ max-width: 400px;
23
+ background: rgba(30, 30, 35, 0.85);
24
+ border: 1px solid rgba(255, 255, 255, 0.1);
25
+ border-radius: 24px;
26
+ padding: 24px;
27
+ box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
28
+ transform: translateY(20px) scale(0.95);
29
+ transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
30
+ position: relative;
31
+ overflow: hidden;
32
+ }
33
+
34
+ .vocabulary-modal-overlay.show .vocabulary-modal {
35
+ transform: translateY(0) scale(1);
36
+ }
37
+
38
+ .vocabulary-modal-header {
39
+ display: flex;
40
+ align-items: center;
41
+ gap: 12px;
42
+ margin-bottom: 20px;
43
+ }
44
+
45
+ .vocabulary-modal-icon {
46
+ width: 40px;
47
+ height: 40px;
48
+ border-radius: 12px;
49
+ background: linear-gradient(135deg, rgba(182, 120, 242, 0.4), rgba(138, 83, 230, 0.4));
50
+ display: flex;
51
+ align-items: center;
52
+ justify-content: center;
53
+ color: #fff;
54
+ box-shadow: inset 0 1px 0 rgba(255,255,255,0.2);
55
+ }
56
+
57
+ .vocabulary-modal-title {
58
+ font-size: 18px;
59
+ font-weight: 600;
60
+ color: #fff;
61
+ margin: 0;
62
+ }
63
+
64
+ .vocabulary-modal-subtitle {
65
+ font-size: 13px;
66
+ color: rgba(255, 255, 255, 0.6);
67
+ margin: 2px 0 0 0;
68
+ }
69
+
70
+ .vocabulary-input-container {
71
+ position: relative;
72
+ margin-bottom: 24px;
73
+ }
74
+
75
+ .vocabulary-input {
76
+ width: 100%;
77
+ background: rgba(0, 0, 0, 0.4);
78
+ border: 1px solid rgba(255, 255, 255, 0.1);
79
+ border-radius: 16px;
80
+ padding: 16px;
81
+ color: #fff;
82
+ font-size: 18px;
83
+ outline: none;
84
+ transition: border-color 0.2s, box-shadow 0.2s;
85
+ box-sizing: border-box;
86
+ }
87
+
88
+ .vocabulary-input:focus {
89
+ border-color: #b678f2;
90
+ box-shadow: 0 0 0 3px rgba(182, 120, 242, 0.2);
91
+ }
92
+
93
+ .vocabulary-input::placeholder {
94
+ color: rgba(255, 255, 255, 0.3);
95
+ }
96
+
97
+ .vocabulary-actions {
98
+ display: flex;
99
+ gap: 12px;
100
+ }
101
+
102
+ .vocabulary-btn {
103
+ flex: 1;
104
+ padding: 14px;
105
+ border-radius: 14px;
106
+ border: none;
107
+ font-size: 15px;
108
+ font-weight: 600;
109
+ cursor: pointer;
110
+ transition: all 0.2s;
111
+ display: flex;
112
+ align-items: center;
113
+ justify-content: center;
114
+ gap: 8px;
115
+ }
116
+
117
+ .vocabulary-btn.cancel {
118
+ background: rgba(255, 255, 255, 0.05);
119
+ color: white;
120
+ }
121
+
122
+ .vocabulary-btn.cancel:active {
123
+ background: rgba(255, 255, 255, 0.1);
124
+ }
125
+
126
+ .vocabulary-btn.submit {
127
+ background: #b678f2;
128
+ color: white;
129
+ box-shadow: 0 4px 12px rgba(182, 120, 242, 0.3);
130
+ }
131
+
132
+ .vocabulary-btn.submit:active {
133
+ transform: scale(0.98);
134
+ }
135
+
136
+ .vocabulary-btn.submit:disabled {
137
+ opacity: 0.5;
138
+ pointer-events: none;
139
+ }
140
+
141
+ .vocabulary-loading {
142
+ position: absolute;
143
+ inset: 0;
144
+ background: rgba(30, 30, 35, 0.9);
145
+ border-radius: 24px;
146
+ display: flex;
147
+ flex-direction: column;
148
+ align-items: center;
149
+ justify-content: center;
150
+ opacity: 0;
151
+ pointer-events: none;
152
+ transition: opacity 0.3s;
153
+ z-index: 10;
154
+ }
155
+
156
+ .vocabulary-loading.active {
157
+ opacity: 1;
158
+ pointer-events: all;
159
+ }
160
+
161
+ .voc-skel-wrapper {
162
+ width: 80%;
163
+ margin-top: 16px;
164
+ }
src/views/vocabulary-modal.js ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { db } from '../db/database.js';
2
+ import { aiRouter } from '../ai/router.js';
3
+
4
+ export function showVocabularyModal() {
5
+ // Prevent duplicate modals
6
+ if (document.getElementById('vocabulary-modal-overlay')) {
7
+ return;
8
+ }
9
+
10
+ // Inject CSS if not present
11
+ if (!document.getElementById('vocabulary-modal-css')) {
12
+ const link = document.createElement('link');
13
+ link.id = 'vocabulary-modal-css';
14
+ link.rel = 'stylesheet';
15
+ link.href = '/src/styles/vocabulary-modal.css';
16
+ document.head.appendChild(link);
17
+ }
18
+
19
+ const overlay = document.createElement('div');
20
+ overlay.id = 'vocabulary-modal-overlay';
21
+ overlay.className = 'vocabulary-modal-overlay';
22
+
23
+ overlay.innerHTML = `
24
+ <div class="vocabulary-modal">
25
+ <div class="vocabulary-modal-header">
26
+ <div class="vocabulary-modal-icon">
27
+ <svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
28
+ <path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20"></path>
29
+ </svg>
30
+ </div>
31
+ <div>
32
+ <h3 class="vocabulary-modal-title">Schnelleingabe</h3>
33
+ <p class="vocabulary-modal-subtitle">Wort in beliebiger Sprache</p>
34
+ </div>
35
+ </div>
36
+
37
+ <div class="vocabulary-input-container">
38
+ <input type="text" id="voc-input" class="vocabulary-input" placeholder="z. B. 'abundant'" autocomplete="off" />
39
+ </div>
40
+
41
+ <div class="vocabulary-actions">
42
+ <button class="vocabulary-btn cancel" id="voc-cancel">Abbrechen</button>
43
+ <button class="vocabulary-btn submit" id="voc-submit">
44
+ <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
45
+ <line x1="12" y1="5" x2="12" y2="19"></line>
46
+ <line x1="5" y1="12" x2="19" y2="12"></line>
47
+ </svg>
48
+ Hinzufügen
49
+ </button>
50
+ </div>
51
+
52
+ <div class="vocabulary-loading" id="voc-loading">
53
+ <div class="voc-loader-text" style="color: white; font-weight: 500; margin-bottom: 12px;">KI übersetzt...</div>
54
+ <div class="voc-skel-wrapper">
55
+ <div class="gemini-skel-line" style="height: 12px; border-radius: 6px; margin-bottom: 8px;"></div>
56
+ <div class="gemini-skel-line" style="height: 12px; border-radius: 6px; width: 60%;"></div>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ `;
61
+
62
+ document.body.appendChild(overlay);
63
+
64
+ // Force reflow for transition
65
+ overlay.offsetHeight;
66
+ overlay.classList.add('show');
67
+
68
+ const input = document.getElementById('voc-input');
69
+ const cancelBtn = document.getElementById('voc-cancel');
70
+ const submitBtn = document.getElementById('voc-submit');
71
+ const loading = document.getElementById('voc-loading');
72
+
73
+ // Auto-Focus
74
+ setTimeout(() => input.focus(), 100);
75
+
76
+ const closeModal = () => {
77
+ overlay.classList.remove('show');
78
+ setTimeout(() => overlay.remove(), 300);
79
+ };
80
+
81
+ const submitVocab = async () => {
82
+ const word = input.value.trim();
83
+ if (!word) return;
84
+
85
+ submitBtn.disabled = true;
86
+ loading.classList.add('active');
87
+
88
+ try {
89
+ // 1. Ask AI to translate and format as JSON
90
+ const prompt = \`Übersetze das folgende Wort oder den Satz in die englische Sprache (oder ins Deutsche, falls es Englisch ist). Antworte AUSSCHLIESSLICH mit einem validen JSON-Objekt. Keine Markdown-Formatierung wie \`\`\`json. Nur das rohe JSON: {"front": "\${word}", "back": "Übersetzung"}\`;
91
+
92
+ const response = await aiRouter.sendMessage(prompt, {
93
+ model: db.getSetting('model') || 'gemini-1.5-flash'
94
+ });
95
+
96
+ let jsonStr = response.trim();
97
+ if (jsonStr.startsWith('\`\`\`json')) {
98
+ jsonStr = jsonStr.replace(/\`\`\`json/g, '').replace(/\`\`\`/g, '').trim();
99
+ }
100
+
101
+ let parsed = null;
102
+ try {
103
+ parsed = JSON.parse(jsonStr);
104
+ } catch (e) {
105
+ // Fallback if parsing fails
106
+ parsed = { front: word, back: response.replace(/\{|\}/g, '').trim() };
107
+ }
108
+
109
+ // 2. Save to Vault (Flashcard DB)
110
+ let decks = db.getDecks();
111
+ let schnelldeck = decks.find(d => d.title === 'Schnelleingabe' || d.title === 'Inbox');
112
+ if (!schnelldeck) {
113
+ schnelldeck = db.createDeck('Schnelleingabe', 'Automatisch gespeicherte Vokabeln aus der Schnelleingabe');
114
+ }
115
+
116
+ db.addFlashcard(schnelldeck.id, parsed.front, parsed.back);
117
+
118
+ // Show success
119
+ loading.innerHTML = \`
120
+ <div style="width: 48px; height: 48px; background: #34c759; border-radius: 24px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px;">
121
+ <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="white" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
122
+ <polyline points="20 6 9 17 4 12"></polyline>
123
+ </svg>
124
+ </div>
125
+ <div style="color: white; font-weight: 500;">Gespeichert!</div>
126
+ \`;
127
+
128
+ setTimeout(() => {
129
+ closeModal();
130
+ }, 1000);
131
+
132
+ } catch (error) {
133
+ console.error("Vokabel konnte nicht gespeichert werden:", error);
134
+ loading.innerHTML = \`
135
+ <div style="color: #ff3b30; font-weight: 500; margin-bottom: 8px;">Fehler aufgetreten</div>
136
+ <button class="vocabulary-btn cancel" onclick="document.getElementById('voc-loading').classList.remove('active'); document.getElementById('voc-submit').disabled = false;">Zurück</button>
137
+ \`;
138
+ }
139
+ };
140
+
141
+ cancelBtn.addEventListener('click', closeModal);
142
+ submitBtn.addEventListener('click', submitVocab);
143
+ input.addEventListener('keydown', (e) => {
144
+ if (e.key === 'Enter') submitVocab();
145
+ if (e.key === 'Escape') closeModal();
146
+ });
147
+
148
+ // Close on overlay click
149
+ overlay.addEventListener('click', (e) => {
150
+ if (e.target === overlay) closeModal();
151
+ });
152
+ }