MCPcopy Create free account
hub / github.com/winfunc/opcode / loadDirectory

Function loadDirectory

src/components/FilePicker.tsx:249–285  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

247 }, [selectedIndex]);
248
249 const loadDirectory = async (path: string) => {
250 try {
251 console.log('[FilePicker] Loading directory:', path);
252
253 // Check cache first and show immediately
254 if (globalDirectoryCache.has(path)) {
255 console.log('[FilePicker] Showing cached contents for:', path);
256 setEntries(globalDirectoryCache.get(path) || []);
257 setIsShowingCached(true);
258 setError(null);
259 } else {
260 // Only show loading if we don't have cached data
261 setIsLoading(true);
262 }
263
264 // Always fetch fresh data in background
265 const contents = await api.listDirectoryContents(path);
266 console.log('[FilePicker] Loaded fresh contents:', contents.length, 'items');
267
268 // Cache the results
269 globalDirectoryCache.set(path, contents);
270
271 // Update with fresh data
272 setEntries(contents);
273 setIsShowingCached(false);
274 setError(null);
275 } catch (err) {
276 console.error('[FilePicker] Failed to load directory:', path, err);
277 console.error('[FilePicker] Error details:', err);
278 // Only set error if we don't have cached data to show
279 if (!globalDirectoryCache.has(path)) {
280 setError(err instanceof Error ? err.message : 'Failed to load directory');
281 }
282 } finally {
283 setIsLoading(false);
284 }
285 };
286
287 const performSearch = async (query: string) => {
288 try {

Callers 2

FilePickerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected