···412412413413 // Handle load more button click
414414 const handleLoadMore = async () => {
415415- if (did && serviceEndpoint && Object.keys(collectionCursors).length > 0) {
415415+ setFetchingMore(true);
416416+417417+ // First check if we already have more records locally that we can show
418418+ if (hasMoreRecordsLocally) {
419419+ console.log("Loading more records from local cache");
420420+ // Simply increase the number of displayed records
421421+ const currentDisplayCount = filteredRecords.length;
422422+ const nextBatchSize = 25;
423423+424424+ // Store the new count so our filteredRecords computation shows more records
425425+ setRecords(prev => {
426426+ // Create a dummy array of the right length to control how many records are shown
427427+ return Array(currentDisplayCount + nextBatchSize).fill(null);
428428+ });
429429+430430+ setFetchingMore(false);
431431+ }
432432+ // If we've displayed all local records but have cursors to fetch more from the API
433433+ else if (hasMoreRecordsRemotely) {
434434+ console.log("Fetching more records from API");
416435 // Only load more from collections that have cursors and are selected
417436 const collectionsToLoad = selectedCollections.filter(collection => collectionCursors[collection]);
418437419438 if (collectionsToLoad.length > 0) {
420439 await fetchCollectionRecords(did, serviceEndpoint, collectionsToLoad, true);
440440+ } else {
441441+ setFetchingMore(false);
421442 }
443443+ } else {
444444+ console.log("No more records to load");
445445+ setFetchingMore(false);
422446 }
423447 };
424448425425- // Filter records for timeline display based on selected collections
426426- const filteredRecords = records.filter(record =>
449449+ // Filter ALL chart records based on selected collections
450450+ const filteredChartRecords = allRecordsForChart.filter(record =>
427451 selectedCollections.includes(record.collection)
428452 );
429453430430- // Filter ALL chart records based on selected collections - this is what the chart will use
431431- const filteredChartRecords = allRecordsForChart.filter(record =>
432432- selectedCollections.includes(record.collection)
433433- );
454454+ // For timeline display, directly use the chart records but limit to most recent 25
455455+ // This ensures we always show the most recent records for the selected collections
456456+ // regardless of what was initially loaded in the records state
457457+ const filteredRecords = filteredChartRecords
458458+ .sort((a, b) => {
459459+ // Sort by timestamp (newest first)
460460+ const aTime = useRkeyTimestamp ? a.rkeyTimestamp : a.contentTimestamp;
461461+ const bTime = useRkeyTimestamp ? b.rkeyTimestamp : b.contentTimestamp;
462462+ return new Date(bTime) - new Date(aTime);
463463+ })
464464+ .slice(0, fetchingMore ? records.length : 25); // Show 25 records initially, more when loading more
434465435435- // Check if more records can be loaded
436436- const canLoadMore = Object.keys(collectionCursors).some(collection =>
466466+ // Check if more records can be loaded - either from API or from our existing dataset
467467+ const hasMoreRecordsLocally = filteredChartRecords.length > filteredRecords.length;
468468+ const hasMoreRecordsRemotely = Object.keys(collectionCursors).some(collection =>
437469 selectedCollections.includes(collection)
438470 );
471471+ const canLoadMore = hasMoreRecordsLocally || hasMoreRecordsRemotely;
439472440473 return (
441474 <div className="collections-feed-container">
···668701 </div>
669702 )}
670703671671- {filteredRecords.length > 0 && canLoadMore && (
704704+ {filteredRecords.length > 0 && (
672705 <div className="load-more-container">
673673- <button
674674- className="load-more-button"
675675- onClick={handleLoadMore}
676676- disabled={fetchingMore}
677677- >
678678- {fetchingMore ? 'Loading...' : 'Load More Records'}
679679- </button>
706706+ <div className="records-count">
707707+ Showing {filteredRecords.length} of {filteredChartRecords.length} records
708708+ </div>
709709+710710+ {canLoadMore && (
711711+ <button
712712+ className="load-more-button"
713713+ onClick={handleLoadMore}
714714+ disabled={fetchingMore}
715715+ >
716716+ {fetchingMore ? 'Loading...' : 'Load More Records'}
717717+ </button>
718718+ )}
680719 </div>
681720 )}
682721 </>