forked from tanner/qotnews
feat: Show preload progress on fetch failure
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -31,6 +31,7 @@ function Feed({ updateCache }) {
|
||||
}
|
||||
|
||||
let currentStories = Array.isArray(stories) ? [...stories] : [];
|
||||
let preloadedCount = 0;
|
||||
|
||||
for (const newStory of [...newApiStories].reverse()) {
|
||||
try {
|
||||
@@ -48,6 +49,7 @@ function Feed({ updateCache }) {
|
||||
await localForage.setItem(fullStory.id, fullStory);
|
||||
console.log('Preloaded story:', fullStory.id, fullStory.title);
|
||||
updateCache(fullStory.id, fullStory);
|
||||
preloadedCount++;
|
||||
|
||||
const existingStoryIndex = currentStories.findIndex(s => s.id === newStory.id);
|
||||
if (existingStoryIndex > -1) {
|
||||
@@ -57,10 +59,10 @@ function Feed({ updateCache }) {
|
||||
} catch (error) {
|
||||
let errorMessage;
|
||||
if (error.name === 'AbortError') {
|
||||
errorMessage = `The request to fetch story '${newStory.title}' (${newStory.id}) timed out after 10 seconds. Your connection may be unstable.`;
|
||||
errorMessage = `The request to fetch story '${newStory.title}' (${newStory.id}) timed out after 10 seconds. Your connection may be unstable. (${preloadedCount} / ${newApiStories.length} stories preloaded)`;
|
||||
console.log('Fetch timed out for story:', newStory.id);
|
||||
} else {
|
||||
errorMessage = `An error occurred while fetching story '${newStory.title}' (ID: ${newStory.id}): ${error.toString()}.`;
|
||||
errorMessage = `An error occurred while fetching story '${newStory.title}' (ID: ${newStory.id}): ${error.toString()}. (${preloadedCount} / ${newApiStories.length} stories preloaded)`;
|
||||
console.log('Fetch failed for story:', newStory.id, error);
|
||||
}
|
||||
setError(errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user