add share collection as text

This commit is contained in:
X4Lo committed 2025-02-15 22:44:07 +01:00
1 parent dbb00fdb61
commit 6b7cca1fe9
3 files changed
+45 -10

No files matched your search

@@ -15,21 +15,21 @@ export class CollectionService {
constructor(private http: HttpClient) {}
// get all lists
// get all collections
getCollections(): Observable<Collection[]> {
return this.http.get<Collection[]>(
`${this.backend_apiUrl}/${this.apiAction}`
);
}
// get a list by id
// get a collection by id
getCollection(collectionId: number): Observable<Collection> {
return this.http.get<Collection>(
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
);
}
// Create a new list
// Create a new collection
createCollection(collection: Collection): Observable<Collection> {
return this.http.post<Collection>(
`${this.backend_apiUrl}/${this.apiAction}`,
@@ -64,14 +64,14 @@ export class CollectionService {
);
}
// Delete a list by ID
// Delete a collection by ID
deleteCollection(collectionId: number): Observable<any> {
return this.http.delete(
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
);
}
// Add an entry to a list
// Add an entry to a collection
addEntryToCollection(
collectionId: number,
entryId: number
@@ -82,7 +82,7 @@ export class CollectionService {
);
}
// Update an entry's order in a list
// Update an entry's order in a collection
updateEntryOrder(
collectionId: number,
entryId: number,
@@ -94,7 +94,7 @@ export class CollectionService {
);
}
// Remove an entry from a list
// Remove an entry from a collection
removeEntryFromCollection(
collectionId: number,
entryId: number
@@ -32,7 +32,8 @@
</li>
<li><a class="dropdown-item" (click)="switchViewMode()">Switch View</a></li>
<li><a class="dropdown-item" (click)="deleteCollection()">Delete</a></li>
<li><a class="dropdown-item" (click)="shareScreenshot()">Share (as image)</a></li>
<li><a class="dropdown-item" (click)="shareScreenshot()">Share (Image)</a></li>
<li><a class="dropdown-item" (click)="copyTitles()">Share (Text)</a></li>
<li>
<a class="dropdown-item" *ngIf="!collection.isUserCollection" (click)="refreshCollection()">Refresh
Information
@@ -195,7 +195,7 @@ export class CollectionInfoPageComponent implements OnInit {
this.screenshotService
.capture('gridDiv')
.then((dataUrl) => {
this.copyToClipboard(dataUrl);
this.copyDataUrlToClipboard(dataUrl);
})
.catch((error) => {
console.error('Error capturing screenshot:', error);
@@ -205,7 +205,24 @@ export class CollectionInfoPageComponent implements OnInit {
this.viewMode = oldViewMode;
}
private copyToClipboard(dataUrl: string) {
async copyTitles() {
let str = `${this.collection.name}: \n`;
await this.collection.entries.forEach((entry) => {
const year = new Date(entry.release_date).getFullYear();
if (entry.is_tvseries) {
str += `${entry.title} (${year} - Seasons: ${
entry.seasons.length
})\n`;
} else {
str += `${entry.title} (${year})\n`;
}
});
this.copyTextToClipboard(str);
}
private copyDataUrlToClipboard(dataUrl: string) {
const img = new Image();
img.src = dataUrl;
const canvas = document.createElement('canvas');
@@ -221,6 +238,23 @@ export class CollectionInfoPageComponent implements OnInit {
};
}
private async copyTextToClipboard(text: string): Promise<void> {
try {
// Create a Blob from the text
const blob = new Blob([text], { type: 'text/plain' });
// Create a ClipboardItem with the Blob
const item = new ClipboardItem({ 'text/plain': blob });
// Write the item to the clipboard
await navigator.clipboard.write([item]);
//console.log('Text copied to clipboard successfully!');
} catch (error) {
console.error('Failed to copy text to clipboard:', error);
}
}
refreshCollection() {
this.collectionService.refreshCollection(this.collection.id).subscribe({
next: (data) => {