Skip to content

Commit 5dc4d14

Browse files
committed
feat: Feed Selection optimizations
1 parent 2fa8f79 commit 5dc4d14

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/components/Feeds/FeedListView.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Feed } from "@fnndsc/chrisapi";
1+
import type { Feed, FileBrowserFolder } from "@fnndsc/chrisapi";
22
import { ChartDonutUtilization } from "@patternfly/react-charts";
33
import {
44
Button,
@@ -384,17 +384,27 @@ const TableRow: React.FC<TableRowProps> = ({
384384
const navigate = useNavigate();
385385
const { isDarkTheme } = useContext(ThemeContext);
386386

387+
// Add a cache for folder data with proper typing
388+
const folderCache = useRef<FileBrowserFolder | null>(null);
389+
387390
/**
388391
* Track row progress state for background color
389392
*/
390393
const [rowProgress, setRowProgress] = useState<number | null>(null);
391394
const [rowError, setRowError] = useState<boolean>(false);
392395

393396
/**
394-
* Get folder for this feed
397+
* Get folder for this feed - with caching
395398
*/
396399
const getFolderForThisFeed = async () => {
400+
// Return cached data if available
401+
if (folderCache.current) {
402+
return folderCache.current;
403+
}
404+
405+
// Otherwise fetch and cache
397406
const payload = await feed.getFolder();
407+
folderCache.current = payload;
398408
return payload;
399409
};
400410

@@ -455,7 +465,22 @@ const TableRow: React.FC<TableRowProps> = ({
455465
onSelect: async (event) => {
456466
event.stopPropagation();
457467
const isChecked = event.currentTarget.checked;
458-
const payload = await getFolderForThisFeed();
468+
469+
// Only fetch folder data if the checkbox is being checked
470+
// This prevents the delay when simply rendering checkboxes
471+
let payload: FileBrowserFolder | null = null;
472+
if (isChecked) {
473+
payload = await getFolderForThisFeed();
474+
} else if (isSelected) {
475+
// If unchecking, we don't need to fetch again, just use the path
476+
handlers.handleCheckboxChange(
477+
event,
478+
feed.data.folder_path,
479+
null,
480+
"folder",
481+
);
482+
return;
483+
}
459484

460485
/**
461486
* Create a new event object with the captured value

src/components/NewLibrary/utils/longpress.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,18 @@ export default function useLongPress() {
118118
e: React.FormEvent<HTMLInputElement>,
119119
path: string,
120120
payload:
121-
| FileBrowserFolder
122-
| FileBrowserFolderFile
123-
| FileBrowserFolderLinkFile,
121+
| (FileBrowserFolder | FileBrowserFolderFile | FileBrowserFolderLinkFile)
122+
| null, // null is valid for deselection operations
124123
type: string,
125124
) => {
126125
if (e.currentTarget.checked) {
127-
selectFolder(path, type, payload);
126+
// For selection, we need a valid payload
127+
if (payload) {
128+
selectFolder(path, type, payload);
129+
}
128130
} else {
131+
// For deselection, we only need the path
132+
// The payload can be null in this case
129133
deselectFolder(path);
130134
}
131135
};

0 commit comments

Comments
 (0)