this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix logic for cached statuses

+14 -15
+14 -15
src/pages/status.jsx
··· 46 46 useEffect(() => { 47 47 setUIState('loading'); 48 48 49 - const containsStatus = statuses.find((s) => s.id === id); 50 - if (!containsStatus) { 51 - // Case 1: On first load, or when navigating to a status that's not cached at all 52 - setStatuses([{ id }]); 49 + const cachedStatuses = store.session.getJSON('statuses-' + id); 50 + if (cachedStatuses) { 51 + // Case 1: It's cached, let's restore them to make it snappy 52 + const reallyCachedStatuses = cachedStatuses.filter( 53 + (s) => states.statuses.has(s.id), 54 + // Some are not cached in the global state, so we need to filter them out 55 + ); 56 + setStatuses(reallyCachedStatuses); 53 57 } else { 54 - const cachedStatuses = store.session.getJSON('statuses-' + id); 55 - if (cachedStatuses) { 56 - // Case 2: Looks like we've cached this status before, let's restore them to make it snappy 57 - const reallyCachedStatuses = cachedStatuses.filter( 58 - (s) => snapStates.statuses.has(s.id), 59 - // Some are not cached in the global state, so we need to filter them out 60 - ); 61 - setStatuses(reallyCachedStatuses); 62 - } else { 63 - // Case 3: Unknown state, could be a sub-comment. Let's slice off all descendant statuses after the hero status to be safe because they are custom-rendered with sub-comments etc 64 - const heroIndex = statuses.findIndex((s) => s.id === id); 58 + const heroIndex = statuses.findIndex((s) => s.id === id); 59 + if (heroIndex !== -1) { 60 + // Case 2: It's in current statuses. Slice off all descendant statuses after the hero status to be safe 65 61 const slicedStatuses = statuses.slice(0, heroIndex + 1); 66 62 setStatuses(slicedStatuses); 63 + } else { 64 + // Case 3: Not cached and not in statuses, let's start from scratch 65 + setStatuses([{ id }]); 67 66 } 68 67 } 69 68