import * as React from "bloatless-react"; import StorageModel, { PATH_COMPONENT_SEPARATOR, } from "../../Model/Global/storageModel"; import StorageViewModel from "../../ViewModel/Global/storageViewModel"; export function DirectoryItemList( storageViewModel: StorageViewModel, pathString: string = PATH_COMPONENT_SEPARATOR ) { // converter const StringToDirectoryItemList: React.StateItemConverter = ( pathString: string ) => DirectoryItemList(storageViewModel, pathString); // data const path = StorageModel.stringToPathComponents(pathString); const fileName = StorageModel.getFileName(path); const items = new React.ListState(); const style = `text-indent: ${path.length}rem`; // methods function loadItems() { items.clear(); const directoryItems = storageViewModel.storageModel.list(path); for (const directoryItem of directoryItems) { const itemPath = [...path, directoryItem]; const pathString = StorageModel.pathComponentsToString(...itemPath); items.add(pathString); } } function select() { storageViewModel.selectedPath.value = pathString; } // handlers storageViewModel.lastDeletedItemPath.subscribe((lastDeletedItemPath) => { if (!items.value.has(lastDeletedItemPath)) return; select(); setTimeout(() => loadItems(), 50); }); // state const isSelected = React.createProxyState( [storageViewModel.selectedPath], () => storageViewModel.selectedPath.value == pathString ); isSelected.subscribe(() => { if (isSelected.value == false) return; loadItems(); }); return (
); }