feat: add share option in detail views

This commit is contained in:
2023-11-14 14:31:27 +01:00
parent f618725598
commit 04e275e967
7 changed files with 46 additions and 0 deletions

View File

@@ -106,6 +106,7 @@ import {SemesterDetailContentComponent} from './types/semester/semester-detail-c
import {SemesterListItemComponent} from './types/semester/semester-list-item.component';
import {VideoDetailContentComponent} from './types/video/video-detail-content.component';
import {VideoListItemComponent} from './types/video/video-list-item.component';
import {ShareButtonComponent} from './elements/share-button.component';
/**
* Module for handling data
@@ -180,6 +181,7 @@ import {VideoListItemComponent} from './types/video/video-list-item.component';
BookDetailContentComponent,
PeriodicalListItemComponent,
PeriodicalDetailContentComponent,
ShareButtonComponent,
],
imports: [
CommonModule,

View File

@@ -20,6 +20,7 @@
</ion-buttons>
<ion-title>{{ 'data.detail.TITLE' | translate }}</ion-title>
<ion-buttons [slot]="isModal ? 'start' : 'primary'">
<stapps-share-button *ngIf="item" [title]="'name' | thingTranslate: item"></stapps-share-button>
<stapps-favorite-button *ngIf="item" [item]="$any(item)"></stapps-favorite-button>
</ion-buttons>
<ion-buttons slot="end" *ngIf="isModal">

View File

@@ -0,0 +1,33 @@
import {Component, Input} from '@angular/core';
import {ToastController} from '@ionic/angular';
import {environment} from '../../../../environments/environment';
@Component({
selector: 'stapps-share-button',
templateUrl: 'share-button.html',
styleUrls: ['share-button.scss'],
})
export class ShareButtonComponent {
canShare = false;
@Input({required: true}) title: string;
@Input() url: string;
constructor(readonly toastController: ToastController) {}
share(): boolean {
const url = this.url ?? new URL(window.location.pathname, `https://${environment.app_host}`);
if (navigator.share) {
void navigator.share({
url: url.toString(),
text: this.title,
});
return false;
} else {
void navigator.clipboard.writeText(`${this.title}\n${url}`);
return true;
}
}
}

View File

@@ -0,0 +1,4 @@
<ion-button size="small" fill="clear" (click)="share() && toast.present()">
<ion-icon size="24" slot="icon-only" name="share" ios="ios_share"></ion-icon>
</ion-button>
<ion-toast [message]="'toast.TITLE_COPIED' | translate" #toast [duration]="2000"></ion-toast>

View File

@@ -25,6 +25,9 @@
},
"settings": "Einstellungen"
},
"toast": {
"TITLE_COPIED": "In die Zwischenablage kopiert"
},
"app": {
"ui": {
"CLOSE": "Schließen",

View File

@@ -25,6 +25,9 @@
},
"settings": "Settings"
},
"toast": {
"TITLE_COPIED": "Copied to clipboard"
},
"app": {
"ui": {
"CLOSE": "Close",