Spaces:
Paused
Paused
Fix(UI/Backend): completely remove delete confirmation logic for instant optimistic UI updates and replace static Wikipedia image fallback with dynamic AI generated image to fix repeating images
Browse files- index.html +1 -1
- server/news-service.js +6 -4
- src/views/news/news-view.js +9 -22
index.html
CHANGED
|
@@ -51,7 +51,7 @@
|
|
| 51 |
</head>
|
| 52 |
<body class="dark-theme in-chat-view">
|
| 53 |
|
| 54 |
-
<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.3.
|
| 55 |
|
| 56 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 57 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
|
|
|
| 51 |
</head>
|
| 52 |
<body class="dark-theme in-chat-view">
|
| 53 |
|
| 54 |
+
<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.3.21</div>
|
| 55 |
|
| 56 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 57 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
server/news-service.js
CHANGED
|
@@ -237,17 +237,19 @@ async function runGenerationCycle(simulateError = false) {
|
|
| 237 |
});
|
| 238 |
|
| 239 |
// Try to fetch a Wikipedia image for the topic
|
| 240 |
-
|
|
|
|
| 241 |
try {
|
| 242 |
-
const
|
|
|
|
| 243 |
const searchData = await searchWiki.json();
|
| 244 |
if (searchData.query && searchData.query.search && searchData.query.search.length > 0) {
|
| 245 |
const bestTitle = searchData.query.search[0].title;
|
| 246 |
-
const imgRes = await fetch(`https://de.wikipedia.org/w/api.php?action=query&titles=${encodeURIComponent(bestTitle)}&prop=pageimages&format=json&pithumbsize=800`);
|
| 247 |
const imgData = await imgRes.json();
|
| 248 |
const pages = imgData.query.pages;
|
| 249 |
const pageId = Object.keys(pages)[0];
|
| 250 |
-
if (pages[pageId].thumbnail && pages[pageId].thumbnail.source) {
|
| 251 |
imageUrl = pages[pageId].thumbnail.source;
|
| 252 |
}
|
| 253 |
}
|
|
|
|
| 237 |
});
|
| 238 |
|
| 239 |
// Try to fetch a Wikipedia image for the topic
|
| 240 |
+
const seed = Math.floor(Math.random() * 100000);
|
| 241 |
+
let imageUrl = `https://image.pollinations.ai/prompt/${encodeURIComponent(topic + ' high quality professional photo')}?width=800&height=600&nologo=true&seed=${seed}`; // Fallback pollinations image
|
| 242 |
try {
|
| 243 |
+
const wikiHeaders = { 'User-Agent': 'SchoolMindApp/1.0 (contact@schoolmind.ai)' };
|
| 244 |
+
const searchWiki = await fetch(`https://de.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(topic)}&format=json&utf8=`, { headers: wikiHeaders });
|
| 245 |
const searchData = await searchWiki.json();
|
| 246 |
if (searchData.query && searchData.query.search && searchData.query.search.length > 0) {
|
| 247 |
const bestTitle = searchData.query.search[0].title;
|
| 248 |
+
const imgRes = await fetch(`https://de.wikipedia.org/w/api.php?action=query&titles=${encodeURIComponent(bestTitle)}&prop=pageimages&format=json&pithumbsize=800`, { headers: wikiHeaders });
|
| 249 |
const imgData = await imgRes.json();
|
| 250 |
const pages = imgData.query.pages;
|
| 251 |
const pageId = Object.keys(pages)[0];
|
| 252 |
+
if (pages[pageId] && pages[pageId].thumbnail && pages[pageId].thumbnail.source) {
|
| 253 |
imageUrl = pages[pageId].thumbnail.source;
|
| 254 |
}
|
| 255 |
}
|
src/views/news/news-view.js
CHANGED
|
@@ -491,31 +491,18 @@ export class NewsView {
|
|
| 491 |
deleteArticleBtn.addEventListener('click', async () => {
|
| 492 |
if (!this.activeArticle) return;
|
| 493 |
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
if (document.getElementById('delete-article-btn')) {
|
| 501 |
-
const btn = document.getElementById('delete-article-btn');
|
| 502 |
-
btn.classList.remove('confirming');
|
| 503 |
-
btn.style.background = 'rgba(255,107,107,0.2)';
|
| 504 |
-
btn.style.color = '#ff6b6b';
|
| 505 |
-
btn.innerHTML = '<svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>';
|
| 506 |
-
}
|
| 507 |
-
}, 3000);
|
| 508 |
-
return;
|
| 509 |
}
|
|
|
|
|
|
|
| 510 |
|
| 511 |
-
const id = this.activeArticle.id;
|
| 512 |
try {
|
| 513 |
-
|
| 514 |
-
if (res.ok) {
|
| 515 |
-
this.articles = this.articles.filter(a => a.id !== id);
|
| 516 |
-
this.activeArticle = null;
|
| 517 |
-
this.render();
|
| 518 |
-
}
|
| 519 |
} catch (e) {
|
| 520 |
console.error('Fehler beim Löschen', e);
|
| 521 |
}
|
|
|
|
| 491 |
deleteArticleBtn.addEventListener('click', async () => {
|
| 492 |
if (!this.activeArticle) return;
|
| 493 |
|
| 494 |
+
const id = this.activeArticle.id;
|
| 495 |
+
|
| 496 |
+
// Optimistic UI update
|
| 497 |
+
const articleIndex = this.articles.findIndex(a => a.id === id);
|
| 498 |
+
if (articleIndex > -1) {
|
| 499 |
+
this.articles.splice(articleIndex, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
}
|
| 501 |
+
this.activeArticle = null;
|
| 502 |
+
this.render();
|
| 503 |
|
|
|
|
| 504 |
try {
|
| 505 |
+
await fetch(getApiUrl(`/api/news/${id}`), { method: 'DELETE' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
} catch (e) {
|
| 507 |
console.error('Fehler beim Löschen', e);
|
| 508 |
}
|