Skip to content

Commit 5704c59

Browse files
fix(copy): use new cdk function instead of extra package (#577)
fixes #253
1 parent ca9865f commit 5704c59

File tree

11 files changed

+44
-68
lines changed

11 files changed

+44
-68
lines changed

Phonebook.Frontend/package-lock.json

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Phonebook.Frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"classlist.js": "1.1.20150312",
5757
"markdown-it": "10.0.0",
5858
"ng2-rx-componentdestroyed": "3.0.1",
59-
"ngx-clipboard": "12.3.1",
6059
"ngx-infinite-scroll": "8.0.1",
6160
"ngx-propagation-stop": "2.0.3",
6261
"ngx-vcard": "2.0.1",

Phonebook.Frontend/src/app/modules/organigram/components/organigram-node/organigram-node.component.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
<mat-card-header>
44
<mat-card-title>
55
<h1>
6-
<mat-icon ngxClipboard [cbContent]="getLink()" (cbOnSuccess)="linkCopiedToast()" (cbOnError)="linkErrorToast()"
7-
class="link pb-pointer">link</mat-icon>
8-
<span>{{node.id + ': ' + node.name}}</span>
6+
<mat-icon [cdkCopyToClipboard]="getLink()" (copied)="copiedToast($event)" class="link pb-pointer">link</mat-icon>
7+
<span>{{ node.id + ': ' + node.name }}</span>
98
</h1>
109
</mat-card-title>
1110
<button mat-icon-button (click)="toggleExpand()" *ngIf="node.children.length != 0" i18n-matTooltip="OrganigramNodeComponent|Tooltip for expanding a Organigram Node@@OrganigramNodeComponentExpandTooltip"
@@ -57,4 +56,4 @@ <h2 i18n="OrganigramNodeComponent|Learners Property@@OrganigramNodeComponentProp
5756
</div>
5857
</mat-card-content>
5958
</mat-card>
60-
</div>
59+
</div>

Phonebook.Frontend/src/app/modules/organigram/components/organigram-node/organigram-node.component.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@ export class OrganigramNodeComponent implements OnInit {
6565
return path;
6666
}
6767

68-
public linkCopiedToast() {
69-
this.store.dispatch(new Navigate(this.generatePath(true)));
70-
this.snackBar.open(
71-
$localize`:OrganigramNodeComponent|First part of the message displayed when copying a link to the node@@OrganigramNodeComponentCopiedFirstPart:Link to` +
72-
' "' +
73-
this.node.name +
74-
'" ' +
75-
$localize`:OrganigramNodeComponent|Second part of the message displayed when copying a link to the node@@OrganigramNodeComponentCopiedSecondPart:copied to clipboard!`,
76-
'',
77-
{ duration: 2000 }
78-
);
79-
}
80-
81-
public linkErrorToast() {
82-
this.snackBar.open(
83-
$localize`:GeneralErrorMessageCopy|Message displayed when copying something went wrong@@GeneralErrorMessageCopy:Couldn't copy to the clipboard, something went wrong. Try again.`,
84-
'',
85-
{ duration: 2000 }
86-
);
68+
public copiedToast(success: boolean) {
69+
if (success) {
70+
this.store.dispatch(new Navigate(this.generatePath(true)));
71+
this.snackBar.open(
72+
$localize`:OrganigramNodeComponent|First part of the message displayed when copying a link to the node@@OrganigramNodeComponentCopiedFirstPart:Link to` +
73+
' "' +
74+
this.node.name +
75+
'" ' +
76+
$localize`:OrganigramNodeComponent|Second part of the message displayed when copying a link to the node@@OrganigramNodeComponentCopiedSecondPart:copied to clipboard!`,
77+
'',
78+
{ duration: 2000 }
79+
);
80+
} else {
81+
this.snackBar.open(
82+
$localize`:GeneralErrorMessageCopy|Message displayed when copying something went wrong@@GeneralErrorMessageCopy:Couldn't copy to the clipboard, something went wrong. Try again.`,
83+
'',
84+
{ duration: 2000 }
85+
);
86+
}
8787
}
8888

8989
public getCurrentRouteAsArray(): string[] {

Phonebook.Frontend/src/app/modules/organigram/organigram.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MatCardModule } from '@angular/material/card';
55
import { MatDividerModule } from '@angular/material/divider';
66
import { MatIconModule } from '@angular/material/icon';
77
import { MatTooltipModule } from '@angular/material/tooltip';
8-
import { ClipboardModule } from 'ngx-clipboard';
8+
import { ClipboardModule } from '@angular/cdk/clipboard';
99
import { OrganigramNodeComponent } from 'src/app/modules/organigram/components/organigram-node/organigram-node.component';
1010
import { OrganigramRoutingModule } from 'src/app/modules/organigram/organigram-routing.module';
1111
import { OrganigramComponent } from 'src/app/modules/organigram/pages/organigram/organigram.component';

Phonebook.Frontend/src/app/modules/rooms/rooms.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { MatSidenavModule } from '@angular/material/sidenav';
1212
import { MatToolbarModule } from '@angular/material/toolbar';
1313
import { MatTooltipModule } from '@angular/material/tooltip';
1414
import { MatTreeModule } from '@angular/material/tree';
15-
import { ClipboardModule } from 'ngx-clipboard';
1615
import { PropagationStopModule } from 'ngx-propagation-stop';
1716
import { FloorComponent } from 'src/app/modules/rooms/components/floor/floor.component';
1817
import { RoomTreeComponent } from 'src/app/modules/rooms/components/room-tree/room-tree.component';
@@ -34,7 +33,6 @@ import { OverviewComponent } from './components/overview/overview.component';
3433
RoomsRoutingModule,
3534
AddFilterModule,
3635
RoomPlanModule,
37-
ClipboardModule,
3836
ActionDrawerModule,
3937
AddressModule,
4038
PropagationStopModule,

Phonebook.Frontend/src/app/shared/components/user/user.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { MatMenuModule } from '@angular/material/menu';
99
import { MatTabsModule } from '@angular/material/tabs';
1010
import { MatTooltipModule } from '@angular/material/tooltip';
1111
import { RouterModule } from '@angular/router';
12-
import { ClipboardModule } from 'ngx-clipboard';
1312
import { PropagationStopModule } from 'ngx-propagation-stop';
1413
import { NgxVcardModule } from 'ngx-vcard';
1514
import { FeatureFlagModule } from 'src/app/modules/feature-flag/feature-flag.module';
@@ -33,7 +32,6 @@ import { PipesModule } from 'src/app/shared/pipes/pipes.module';
3332
AddFilterModule,
3433
RouterModule,
3534
ActionDrawerModule,
36-
ClipboardModule,
3735
ProfilePictureModule,
3836
FeatureFlagModule,
3937
AddressModule,

Phonebook.Frontend/src/app/shared/directives/action-drawer/action-drawer-sheet/action-drawer-sheet.component.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ <h3 mat-line>{{ data.copy }}</h3>
55
<button
66
mat-button
77
propagationStop
8-
ngxClipboard
9-
[cbContent]="data.copy"
10-
(cbOnSuccess)="copySuccessToast()"
11-
(cbOnError)="copyErrorToast()"
8+
[cdkCopyToClipboard]="data.copy"
9+
(copied)="copiedToast($event)"
1210
(click)="closeBottomSheet()"
1311
>
1412
<span i18n="GeneralCopyButton|Copy to Clipboard button@@GeneralCopyButton">Copy to clipboard</span>

Phonebook.Frontend/src/app/shared/directives/action-drawer/action-drawer-sheet/action-drawer-sheet.component.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ export class ActionDrawerSheetComponent {
2020
this.bottomSheetRef.dismiss();
2121
}
2222

23-
public copySuccessToast() {
24-
this.snackBar.open(
25-
$localize`:GeneralSuccessMessageCopy|Message displayed when copying a link is successfully@@GeneralSuccessMessageCopy:Copied to clipboard!`,
26-
'',
27-
{ duration: 2000 }
28-
);
29-
}
30-
31-
public copyErrorToast() {
32-
this.snackBar.open(
33-
$localize`:ErrorMessageCopy|Message displayed if something was not copied succesfully@@GeneralErrorMessageCopy:Couldn't copy to the clipboard, something went wrong. Try again.`,
34-
'',
35-
{ duration: 2000 }
36-
);
23+
public copiedToast(success: boolean) {
24+
if (success) {
25+
this.snackBar.open(
26+
$localize`:GeneralSuccessMessageCopy|Message displayed when copying a link is successfully@@GeneralSuccessMessageCopy:Copied to clipboard!`,
27+
'',
28+
{ duration: 2000 }
29+
);
30+
} else {
31+
this.snackBar.open(
32+
$localize`:ErrorMessageCopy|Message displayed if something was not copied succesfully@@GeneralErrorMessageCopy:Couldn't copy to the clipboard, something went wrong. Try again.`,
33+
'',
34+
{ duration: 2000 }
35+
);
36+
}
3737
}
3838
}

Phonebook.Frontend/src/app/shared/directives/action-drawer/action-drawer.directive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Directive, ElementRef, HostListener, Input } from '@angular/core';
22
import { MatBottomSheet } from '@angular/material/bottom-sheet';
33
import { MatSnackBar } from '@angular/material/snack-bar';
44

5-
import { ClipboardService } from 'ngx-clipboard';
5+
import { Clipboard } from '@angular/cdk/clipboard';
66
import { ActionDrawerSheetComponent } from 'src/app/shared/directives/action-drawer/action-drawer-sheet/action-drawer-sheet.component';
77

88
@Directive({ selector: '[actionDrawer]' })
@@ -12,7 +12,7 @@ export class ActionDrawerDirective {
1212
event.stopPropagation();
1313
// Checks if only one of the actions is true
1414
if (this.copy && !this.tel && !this.mailto) {
15-
this.clipboardService.copyFromContent(this.copy);
15+
this.clipboard.copy(this.copy);
1616
this.snackBar.open(
1717
$localize`:SuccessMessageCopy|Message displayed if something was copied succesfully@@GeneralSuccessMessageCopy:Copied to clipboard!`,
1818
'',
@@ -29,7 +29,7 @@ export class ActionDrawerDirective {
2929
constructor(
3030
el: ElementRef,
3131
private bottomSheet: MatBottomSheet,
32-
private clipboardService: ClipboardService,
32+
private clipboard: Clipboard,
3333
private snackBar: MatSnackBar
3434
) {}
3535

0 commit comments

Comments
 (0)