-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add archive/delete actions to file context menu
- Loading branch information
1 parent
031abce
commit 30c45d6
Showing
8 changed files
with
175 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/app/file-context-menu-actions/file-context-menu-actions.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<a mat-menu-item rel="noopener noreferrer" target="_blank" href="{{file().file_url}}"> | ||
<mat-icon>open_in_new</mat-icon> | ||
<span>Open in New Tab</span> | ||
</a> | ||
@if (downloadService.canShare) { | ||
<button mat-menu-item (click)="shareFile()"> | ||
<mat-icon>share</mat-icon> | ||
<span>Share</span> | ||
</button> | ||
} | ||
<button mat-menu-item (click)="saveFile()"> | ||
<mat-icon>get_app</mat-icon> | ||
<span>Download</span> | ||
</button> | ||
<mat-divider></mat-divider> | ||
@if (fullFile$ | async; as fullFile) { | ||
|
||
@if (fullFile.is_inbox) { | ||
<button mat-menu-item (click)="archiveFile()"> | ||
<mat-icon>archive</mat-icon> | ||
<span>Archive</span> | ||
</button> | ||
} @else { | ||
<button mat-menu-item (click)="unarchiveFile()"> | ||
<mat-icon>move_to_inbox</mat-icon> | ||
<span>Return to Inbox</span> | ||
</button> | ||
} | ||
@if (!fullFile.is_trashed) { | ||
<button mat-menu-item (click)="deleteFile()"> | ||
<mat-icon>delete</mat-icon> | ||
<span>Delete</span> | ||
</button> | ||
} @else { | ||
<button mat-menu-item (click)="undeleteFile()"> | ||
<mat-icon>restore_from_trash</mat-icon> | ||
<span>Undelete</span> | ||
</button> | ||
} | ||
} @else { | ||
<button mat-menu-item disabled> | ||
<span>Loading...</span> | ||
</button> | ||
<button mat-menu-item disabled> | ||
<span>Loading...</span> | ||
</button> | ||
} |
Empty file.
23 changes: 23 additions & 0 deletions
23
src/app/file-context-menu-actions/file-context-menu-actions.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { FileContextMenuActionsComponent } from './file-context-menu-actions.component'; | ||
|
||
describe('FileContextMenuContentComponent', () => { | ||
let component: FileContextMenuActionsComponent; | ||
let fixture: ComponentFixture<FileContextMenuActionsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [FileContextMenuActionsComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(FileContextMenuActionsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
src/app/file-context-menu-actions/file-context-menu-actions.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Component, input } from '@angular/core'; | ||
import { HydrusFileDownloadService } from '../hydrus-file-download.service'; | ||
import { HydrusFilesService } from '../hydrus-files.service'; | ||
import { HydrusBasicFile } from '../hydrus-file'; | ||
import { toObservable } from '@angular/core/rxjs-interop'; | ||
import { firstValueFrom, switchMap } from 'rxjs'; | ||
import { MatSnackBar } from '@angular/material/snack-bar'; | ||
import { ErrorService } from '../error.service'; | ||
|
||
@Component({ | ||
selector: 'app-file-context-menu-actions', | ||
templateUrl: './file-context-menu-actions.component.html', | ||
styleUrl: './file-context-menu-actions.component.scss' | ||
}) | ||
export class FileContextMenuActionsComponent { | ||
|
||
constructor( | ||
public downloadService: HydrusFileDownloadService, | ||
private filesService: HydrusFilesService, | ||
private snackbar: MatSnackBar, | ||
private errorService: ErrorService | ||
) { | ||
} | ||
|
||
file = input.required<HydrusBasicFile>(); | ||
|
||
fullFile$ = toObservable(this.file).pipe( | ||
switchMap(f => this.filesService.getFileByHash(f.hash)) | ||
) | ||
|
||
saveFile() { | ||
this.downloadService.saveFile(this.file()); | ||
} | ||
|
||
shareFile() { | ||
this.downloadService.shareFile(this.file()); | ||
} | ||
|
||
async deleteFile(){ | ||
try { | ||
await firstValueFrom(this.filesService.deleteFile(this.file().hash)); | ||
const snackbarRef = this.snackbar.open('File sent to trash', 'Undo', { | ||
duration: 2000 | ||
}); | ||
snackbarRef.onAction().subscribe(() => { | ||
this.undeleteFile() | ||
}) | ||
} catch (error) { | ||
this.errorService.handleHydrusError(error); | ||
} | ||
} | ||
|
||
async undeleteFile(){ | ||
try { | ||
await firstValueFrom(this.filesService.undeleteFile(this.file().hash)); | ||
const snackbarRef = this.snackbar.open('File removed from trash', 'Undo', { | ||
duration: 2000 | ||
}); | ||
snackbarRef.onAction().subscribe(() => { | ||
this.deleteFile() | ||
}) | ||
} catch (error) { | ||
this.errorService.handleHydrusError(error); | ||
} | ||
} | ||
|
||
async archiveFile(){ | ||
try { | ||
await firstValueFrom(this.filesService.archiveFile(this.file().hash)) | ||
const snackbarRef = this.snackbar.open('File archived', 'Undo', { | ||
duration: 2000 | ||
}); | ||
snackbarRef.onAction().subscribe(() => { | ||
this.unarchiveFile() | ||
}) | ||
} catch (error) { | ||
this.errorService.handleHydrusError(error); | ||
} | ||
} | ||
|
||
async unarchiveFile(){ | ||
try { | ||
await firstValueFrom(this.filesService.unarchiveFile(this.file().hash)); | ||
const snackbarRef = this.snackbar.open('File moved to inbox', 'Undo', { | ||
duration: 2000 | ||
}); | ||
snackbarRef.onAction().subscribe(() => { | ||
this.archiveFile() | ||
}) | ||
} catch (error) { | ||
this.errorService.handleHydrusError(error); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters