Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Implement infinite scrolling for storage dashboard and fetch 200 items per request

Joshen Lim1b8e9bd42c8f
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js
index 68460fa6627..d3477176aa9 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js
@@ -240,11 +240,7 @@ const FileExplorerColumn = ({
onSelectItemMove,
}}
ItemComponent={FileExplorerRow}
- getItemSize={(index) => {
- if (index !== 0 && index === columnItems.length) return 85
- return 37
- }}
- // Scaffold props for infinite loading
+ getItemSize={(index) => (index !== 0 && index === columnItems.length ? 85 : 37)}
hasNextPage={column.status !== STORAGE_ROW_STATUS.LOADING && column.hasMoreItems}
isLoadingNextPage={column.isLoadingMoreItems}
onLoadNextPage={() => onColumnLoadMore(index, column)}
diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js
index c8c1f13ad6e..82c3d6dae8e 100644
--- a/studio/localStores/storageExplorer/StorageExplorerStore.js
+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js
@@ -42,7 +42,7 @@ export const useStorageExplorerStore = () => {
return useContext(StorageExplorerContext)
}
-const LIMIT = 5
+const LIMIT = 200
const OFFSET = 0
const DEFAULT_EXPIRY = 10 * 365 * 24 * 60 * 60 // in seconds, default to 1 year
const PREVIEW_SIZE_LIMIT = 10000000 // 10MB
@@ -942,8 +942,6 @@ class StorageExplorerStore {
.from(this.selectedBucket.name)
.list(prefix, options, parameters)
- console.log('Initial fetch', prefix, options, items)
-
if (showLoading) {
this.updateRowStatus(folderName, STORAGE_ROW_STATUS.READY, index)
}
@@ -976,15 +974,24 @@ class StorageExplorerStore {
}
const parameters = { signal: this.abortController.signal }
- console.log('fetchMoreFolderContents', { column, prefix, options })
-
const { data: items, error } = await this.supabaseClient.storage
.from(this.selectedBucket.name)
.list(prefix, options, parameters)
if (!error) {
- // [Joshen] WE LEFT OFF HERE
- console.log('Fetched more', items)
+ // Add items to column
+ const formattedItems = this.formatFolderItems(items)
+ this.columns = this.columns.map((col, idx) => {
+ if (idx === index) {
+ return {
+ ...col,
+ items: col.items.concat(formattedItems),
+ isLoadingMoreItems: false,
+ hasMoreItems: items.length === LIMIT,
+ }
+ }
+ return col
+ })
}
}
@@ -1023,6 +1030,8 @@ class StorageExplorerStore {
id: null,
name: idx === 0 ? this.selectedBucket.name : pathsWithEmptyPrefix[idx],
items: formattedItems,
+ hasMoreItems: formattedItems.length === LIMIT,
+ isLoadingMoreItems: false,
}
})