feat: add file view (#1064)

This commit is contained in:
Aman Harwara
2022-06-06 21:30:51 +05:30
committed by GitHub
parent c20f0ad78b
commit 92024ec7ca
33 changed files with 661 additions and 382 deletions

View File

@@ -30,6 +30,7 @@ export class FilesController extends AbstractViewController {
allFiles: FileItem[] = []
attachedFiles: FileItem[] = []
showFileContextMenu = false
showProtectedOverlay = false
fileContextMenuLocation: FileContextMenuLocation = { x: 0, y: 0 }
override deinit(): void {
@@ -52,9 +53,12 @@ export class FilesController extends AbstractViewController {
showFileContextMenu: observable,
fileContextMenuLocation: observable,
showProtectedOverlay: observable,
reloadAllFiles: action,
reloadAttachedFiles: action,
setShowFileContextMenu: action,
setShowProtectedOverlay: action,
setFileContextMenuLocation: action,
})
@@ -79,6 +83,10 @@ export class FilesController extends AbstractViewController {
this.showFileContextMenu = enabled
}
setShowProtectedOverlay = (enabled: boolean) => {
this.showProtectedOverlay = enabled
}
setFileContextMenuLocation = (location: FileContextMenuLocation) => {
this.fileContextMenuLocation = location
}
@@ -404,9 +412,15 @@ export class FilesController extends AbstractViewController {
setProtectionForFiles = async (protect: boolean, files: FileItem[]) => {
if (protect) {
await this.application.mutator.protectItems(files)
const protectedItems = await this.application.mutator.protectItems(files)
if (protectedItems) {
this.setShowProtectedOverlay(true)
}
} else {
await this.application.mutator.unprotectItems(files, ChallengeReason.UnprotectFile)
const unprotectedItems = await this.application.mutator.unprotectItems(files, ChallengeReason.UnprotectFile)
if (unprotectedItems) {
this.setShowProtectedOverlay(false)
}
}
}

View File

@@ -92,6 +92,8 @@ export class NavigationController extends AbstractViewController {
setContextMenuClickLocation: action,
setContextMenuPosition: action,
setContextMenuMaxHeight: action,
isInFilesView: computed,
})
this.disposers.push(
@@ -257,6 +259,10 @@ export class NavigationController extends AbstractViewController {
}
}
public get isInFilesView(): boolean {
return this.selectedUuid === SystemViewId.Files
}
public get allLocalRootTags(): SNTag[] {
if (this.editing_ instanceof SNTag && this.application.items.isTemplateItem(this.editing_)) {
return [this.editing_, ...this.rootTags]