Improve remote sketchbook explorer (#459)

* Refactor remote sketchbook explorer
* sketches sorting
This commit is contained in:
Francesco Stasi
2021-07-22 14:34:10 +02:00
committed by GitHub
parent 4da5d573e4
commit d790266cc8
16 changed files with 592 additions and 613 deletions

View File

@@ -0,0 +1,34 @@
import { FileStat } from '@theia/filesystem/lib/common/files';
import { injectable } from 'inversify';
import { toPosixPath } from '../../create/create-paths';
import { Create } from '../../create/typings';
@injectable()
export class SketchCache {
sketches: Record<string, Create.Sketch> = {};
fileStats: Record<string, FileStat> = {};
init(): void {
// reset the data
this.sketches = {};
this.fileStats = {};
}
addItem(item: FileStat): void {
this.fileStats[item.resource.path.toString()] = item;
}
getItem(path: string): FileStat | null {
return this.fileStats[path] || null;
}
addSketch(sketch: Create.Sketch): void {
const { path } = sketch;
const posixPath = toPosixPath(path);
this.sketches[posixPath] = sketch;
}
getSketch(path: string): Create.Sketch | null {
return this.sketches[path] || null;
}
}