collection share using screenshot pt1

This commit is contained in:
X4Lo committed 2024-08-29 19:00:46 +01:00
1 parent 3aa59eec16
commit 28f304faa2
4 files changed
+90 -8

No files matched your search

@@ -28,6 +28,7 @@
</li>
<li><a class="dropdown-item" href="javascript:;" (click)="switchViewMode()">Switch View</a></li>
<li><a class="dropdown-item" href="javascript:;" (click)="deleteCollection()">Delete</a></li>
<li><a class="dropdown-item" href="javascript:;" (click)="shareScreenshot()">Share (as image)</a></li>
</ul>
</div>
</div>
@@ -40,7 +41,8 @@
<div *ngIf="collection.description != ''">{{collection.description}}</div>
<hr>
<!-- ! grid -->
<div *ngIf="viewMode == 'grid'">
<div id="gridDiv" *ngIf="viewMode == 'grid'">
<h1 *ngIf="screenMode">{{collection.name}}</h1>
<app-userCollection-entry-grid [entries]="collection.entries"
[collectionId]="getListId()"></app-userCollection-entry-grid>
</div>
@@ -7,6 +7,7 @@ import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry
import { CollectionEditModalComponent } from '../collection-edit-modal/collection-edit-modal.component';
import { MatDialog } from '@angular/material/dialog';
import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component';
import { ScreenshotService } from '../../../../core/services/screenshot.service';
@Component({
selector: 'app-userCollection-info-page',
@@ -20,10 +21,12 @@ export class UserCollectionInfoPageComponent implements OnInit {
updatedAt: string = '';
viewMode: string = 'grid';
screenMode: boolean = false;
constructor(
private route: ActivatedRoute,
private userCollectionService: UserCollectionService,
private screenshotService: ScreenshotService,
private datePipe: DatePipe,
public dialog: MatDialog,
private router: Router
@@ -31,7 +34,7 @@ export class UserCollectionInfoPageComponent implements OnInit {
ngOnInit(): void {
const id = this.route.snapshot.paramMap.get('id');
if (id == null) return;
if (id == null) return; // todo redirect if no id is provided
this.userCollectionService.getCollection(id.toString()).subscribe(
(data) => {
@@ -40,10 +43,10 @@ export class UserCollectionInfoPageComponent implements OnInit {
this.createdAt = this.getCreatedDate()?.toString() || '';
this.updatedAt = this.getUpdatedAt()?.toString() || '';
console.log(
`Collection "${this.collection.name}" received:`,
this.collection
);
// console.log(
// `Collection "${this.collection.name}" received:`,
// this.collection
// );
},
(error) => {
console.error('Error occurred:', error);
@@ -170,4 +173,35 @@ export class UserCollectionInfoPageComponent implements OnInit {
}
});
}
shareScreenshot() {
this.screenMode = true;
const oldViewMode = this.viewMode;
this.viewMode = 'grid';
this.screenshotService.capture('gridDiv').then(dataUrl => {
this.copyToClipboard(dataUrl);
}).catch(error => {
console.error('Error capturing screenshot:', error);
});
this.screenMode = false;
this.viewMode = oldViewMode;
}
private copyToClipboard(dataUrl: string) {
const img = new Image();
img.src = dataUrl;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
img.onload = () => {
canvas.width = img.width;
canvas.height = img.height;
ctx!.drawImage(img, 0, 0);
canvas.toBlob(blob => {
const item = new ClipboardItem({ 'image/png': blob as Blob });
navigator.clipboard.write([item]);
});
};
}
}