Directory View Parent Directory Button (#805)

Add a button in the directory view to easily navigate to the parent of
the current directory.
This commit is contained in:
Sylvie Crowe 2024-09-23 19:02:17 -07:00 committed by GitHub
parent 7708db7060
commit 4ff247d2f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -287,7 +287,8 @@ export class PreviewModel implements ViewModel {
return null;
}
const mimeType = util.jotaiLoadableValue(get(this.fileMimeTypeLoadable), "");
if (mimeType == "directory") {
const metaPath = get(this.metaFilePath);
if (mimeType == "directory" && metaPath == "/") {
return null;
}
return {
@ -492,29 +493,24 @@ export class PreviewModel implements ViewModel {
}
async goParentDirectory() {
const blockMeta = globalStore.get(this.blockAtom)?.meta;
const metaPath = globalStore.get(this.metaFilePath);
const fileInfo = await globalStore.get(this.statFile);
if (fileInfo == null) {
return;
this.updateOpenFileModalAndError(false);
return true;
}
let newPath: string = null;
if (!fileInfo.isdir) {
newPath = fileInfo.dir;
} else {
const lastSlash = fileInfo.dir.lastIndexOf("/");
newPath = fileInfo.dir.slice(0, lastSlash);
if (newPath.indexOf("/") == -1) {
return;
}
const conn = globalStore.get(this.connection);
try {
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.dir, ".."], {
route: makeConnRoute(conn),
});
console.log(newFileInfo.path);
this.updateOpenFileModalAndError(false);
this.goHistory(newFileInfo.path);
refocusNode(this.blockId);
} catch (e) {
globalStore.set(this.openFileError, e.message);
console.error("Error opening file", [fileInfo.dir, ".."], e);
}
const updateMeta = historyutil.goHistory("file", metaPath, newPath, blockMeta);
if (updateMeta == null) {
return;
}
updateMeta.edit = false;
const blockOref = WOS.makeORef("block", this.blockId);
services.ObjectService.UpdateObjectMeta(blockOref, updateMeta);
}
goHistoryBack() {