forked from tanner/qotnews
fix: Always fetch full story and update existing in feed
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -21,13 +21,8 @@ function Feed({ updateCache }) {
|
|||||||
if (!updated) return;
|
if (!updated) return;
|
||||||
|
|
||||||
let currentStories = Array.isArray(stories) ? [...stories] : [];
|
let currentStories = Array.isArray(stories) ? [...stories] : [];
|
||||||
const existingStoryIds = new Set(currentStories.map(s => s.id));
|
|
||||||
|
|
||||||
for (const newStory of [...newApiStories].reverse()) {
|
for (const newStory of [...newApiStories].reverse()) {
|
||||||
if (existingStoryIds.has(newStory.id)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const storyRes = await fetch('/api/' + newStory.id);
|
const storyRes = await fetch('/api/' + newStory.id);
|
||||||
if (!storyRes.ok) throw new Error('Story fetch failed');
|
if (!storyRes.ok) throw new Error('Story fetch failed');
|
||||||
@@ -38,6 +33,10 @@ function Feed({ updateCache }) {
|
|||||||
console.log('Preloaded story:', fullStory.id, fullStory.title);
|
console.log('Preloaded story:', fullStory.id, fullStory.title);
|
||||||
updateCache(fullStory.id, fullStory);
|
updateCache(fullStory.id, fullStory);
|
||||||
|
|
||||||
|
const existingStoryIndex = currentStories.findIndex(s => s.id === newStory.id);
|
||||||
|
if (existingStoryIndex > -1) {
|
||||||
|
currentStories.splice(existingStoryIndex, 1);
|
||||||
|
}
|
||||||
currentStories.unshift(newStory);
|
currentStories.unshift(newStory);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Skipping story due to fetch error', newStory.id, error);
|
console.log('Skipping story due to fetch error', newStory.id, error);
|
||||||
|
|||||||
Reference in New Issue
Block a user