forked from tanner/qotnews
refactor: Iterate through stories in order for prioritized updates
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -36,7 +36,7 @@ function Feed({ updateCache }) {
|
|||||||
let currentStories = Array.isArray(stories) ? [...stories] : [];
|
let currentStories = Array.isArray(stories) ? [...stories] : [];
|
||||||
let preloadedCount = 0;
|
let preloadedCount = 0;
|
||||||
|
|
||||||
for (const newStory of [...newApiStories].reverse()) {
|
for (const [index, newStory] of newApiStories.entries()) {
|
||||||
try {
|
try {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10-second timeout
|
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10-second timeout
|
||||||
@@ -59,9 +59,10 @@ function Feed({ updateCache }) {
|
|||||||
if (existingStoryIndex > -1) {
|
if (existingStoryIndex > -1) {
|
||||||
currentStories.splice(existingStoryIndex, 1);
|
currentStories.splice(existingStoryIndex, 1);
|
||||||
}
|
}
|
||||||
currentStories.unshift(newStory);
|
currentStories.splice(index, 0, newStory);
|
||||||
|
|
||||||
localStorage.setItem('stories', JSON.stringify(currentStories));
|
localStorage.setItem('stories', JSON.stringify(currentStories));
|
||||||
|
setStories(currentStories);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let errorMessage;
|
let errorMessage;
|
||||||
if (error.name === 'AbortError') {
|
if (error.name === 'AbortError') {
|
||||||
|
|||||||
Reference in New Issue
Block a user