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; return null;
} }
const mimeType = util.jotaiLoadableValue(get(this.fileMimeTypeLoadable), ""); const mimeType = util.jotaiLoadableValue(get(this.fileMimeTypeLoadable), "");
if (mimeType == "directory") { const metaPath = get(this.metaFilePath);
if (mimeType == "directory" && metaPath == "/") {
return null; return null;
} }
return { return {
@ -492,29 +493,24 @@ export class PreviewModel implements ViewModel {
} }
async goParentDirectory() { async goParentDirectory() {
const blockMeta = globalStore.get(this.blockAtom)?.meta;
const metaPath = globalStore.get(this.metaFilePath);
const fileInfo = await globalStore.get(this.statFile); const fileInfo = await globalStore.get(this.statFile);
if (fileInfo == null) { if (fileInfo == null) {
return; this.updateOpenFileModalAndError(false);
return true;
} }
let newPath: string = null; const conn = globalStore.get(this.connection);
if (!fileInfo.isdir) { try {
newPath = fileInfo.dir; const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.dir, ".."], {
} else { route: makeConnRoute(conn),
const lastSlash = fileInfo.dir.lastIndexOf("/"); });
newPath = fileInfo.dir.slice(0, lastSlash); console.log(newFileInfo.path);
if (newPath.indexOf("/") == -1) { this.updateOpenFileModalAndError(false);
return; 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() { goHistoryBack() {