Simplify file handling: give up trying to execute examples in their folders, just copy all files to /. Breaks autocomplete

This commit is contained in:
ochafik 2023-03-26 23:39:41 +01:00
commit 51b481866f
8 changed files with 90 additions and 52 deletions

View file

@ -4,7 +4,8 @@ import { CSSProperties, useContext } from 'react';
import { TreeSelect } from 'primereact/treeselect';
import TreeNode from 'primereact/treenode';
import { ModelContext, FSContext } from './contexts';
import { isFileWritable } from '../state/model';
// import { isFileWritable } from '../state/model';
import { join } from '../fs/filesystem';
function listFilesAsNodes(fs: FS, path: string, accept?: (path: string) => boolean): TreeNode[] {
const files: [string, string][] = []
@ -13,7 +14,7 @@ function listFilesAsNodes(fs: FS, path: string, accept?: (path: string) => boole
if (name.startsWith('.')) {
continue;
}
const childPath = `${path}/${name}`;
const childPath = join(path, name);//`${path}/${name}`;
if (accept && !accept(childPath)) {
continue;
}
@ -35,7 +36,8 @@ function listFilesAsNodes(fs: FS, path: string, accept?: (path: string) => boole
}
nodes.push({
// icon: path == '/home' ? 'pi-home' : ...
icon: isDirectory ? 'pi pi-folder' : isFileWritable(path) ? 'pi pi-file' : 'pi pi-lock',
// icon: isDirectory ? 'pi pi-folder' : isFileWritable(path) ? 'pi pi-file' : 'pi pi-lock',
icon: isDirectory ? 'pi pi-folder' : 'pi pi-file',
label: name,
data: path,
key: path,
@ -54,7 +56,24 @@ export default function FilePicker({className, style}: {className?: string, styl
const fs = useContext(FSContext);
const fsItems = fs && listFilesAsNodes(fs, '/home')
const fsItems = fs && //listFilesAsNodes(fs, '/home')
[
{
icon: 'pi pi-home',
label: 'User files',
key: '/',
children: listFilesAsNodes(fs, '/'),//
// children: listFilesAsNodes(fs, '/', f => f != librariesFolder && !f.startsWith(`${librariesFolder}/`)),
selectable: false
},
{
icon: 'pi pi-database',
label: 'Builtin libraries',
key: '/libraries',
children: listFilesAsNodes(fs, '/libraries'),
selectable: false
},
] || [];
return (
<TreeSelect