-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp_file
More file actions
130 lines (114 loc) · 5.99 KB
/
temp_file
File metadata and controls
130 lines (114 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
async function updateInteractiveDemo(code) {
// If our enhanced component function exists, use it
if (typeof window.updateInteractiveDemo === 'function' && window.updateInteractiveDemo !== updateInteractiveDemo) {
return window.updateInteractiveDemo(code);
} else {
try {
console.log("Generating interactive demo for code length:", code ? code.length : 0);
// Get current language and concept
const language = document.getElementById('language-selector').value || 'python';
const concept = document.getElementById('concept-selector').value || 'general';
// If no code is provided but we have a concept, try to load example code for that concept
if ((!code || code.length < 30) && concept !== 'general') {
try {
// Dynamically import the concept examples
console.log("Attempting to import ConceptExamples.js from updateInteractiveDemo");
const module = await import('/static/js/components/ConceptExamples.js');
// Get example code for the concept
const exampleCode = module.getConceptExamples(concept, language);
if (exampleCode) {
code = exampleCode;
console.log(`Used example code for ${concept} in ${language} for interactive demo`);
}
} catch (e) {
console.warn('Error loading concept examples for interactive demo:', e);
}
}
// Detect if code is authentication-related for better demo selection
const isAuthRelated = code && (
code.toLowerCase().includes('login') ||
code.toLowerCase().includes('password') ||
code.toLowerCase().includes('authenticate') ||
code.toLowerCase().includes('credentials')
);
console.log(`Code type detected: ${isAuthRelated ? 'Authentication-related' : 'Standard'}, Language: ${language}, Concept: ${concept}`);
// Show loading indicator in the GUI demo section
const guiDemoRoot = document.getElementById('gui-demo-root');
if (guiDemoRoot) {
const guiDemoContent = guiDemoRoot.querySelector('.panel-content');
if (guiDemoContent) {
guiDemoContent.innerHTML = `
<div class="loading-spinner-container">
<div class="loading-spinner"></div>
<p>Generating interactive GUI demonstration...</p>
</div>
`;
}
}
// Get interactive demo from API
const response = await fetch('/api/realworld/demo', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
code,
language,
concept
})
});
if (!response.ok) {
throw new Error(`Failed to fetch interactive demo: ${response.status} ${response.statusText}`);
}
const data = await response.json();
console.log("Received demo data with html length:", data.demo_html ? data.demo_html.length : 0);
// Update the GUI Demo section in the right panel
if (guiDemoRoot) {
const guiDemoContent = guiDemoRoot.querySelector('.panel-content');
if (guiDemoContent) {
if (data.demo_html) {
guiDemoContent.innerHTML = data.demo_html;
console.log("Updated GUI demo content");
// Execute any scripts in the demo HTML
executeScripts(guiDemoContent);
} else {
guiDemoContent.innerHTML = '<div class="empty-state">No GUI demo available for this code.</div>';
}
}
}
// Also update the popup interactive demo panel if it exists
const interactiveDemo = document.querySelector('.interactive-demo');
if (interactiveDemo) {
if (data.demo_html) {
interactiveDemo.innerHTML = data.demo_html;
// Execute any scripts in the demo HTML
executeScripts(interactiveDemo);
} else {
interactiveDemo.innerHTML = '<div class="empty-state">No interactive demo available for this code.</div>';
}
}
// Also update the interactive demo container for the modal
const demoContainer = document.getElementById('interactive-demo-container');
if (demoContainer) {
const demoContent = demoContainer.querySelector('.panel-content');
if (demoContent && data.demo_html) {
demoContent.innerHTML = data.demo_html;
// Execute any scripts in the demo HTML
executeScripts(demoContent);
}
}
// Return the data for chaining
return data;
} catch (error) {
console.error('Error updating interactive demo:', error);
// Set fallback content
const guiDemoRoot = document.getElementById('gui-demo-root');
if (guiDemoRoot) {
const guiDemoContent = guiDemoRoot.querySelector('.panel-content');
if (guiDemoContent) {
guiDemoContent.innerHTML = '<div class="error-message">Could not load GUI demo.</div>';
}
}
}
}
}