Skip to content

Commit 466d343

Browse files
authored
Merge pull request #64 from koushik-dev/develop
share community button #56
2 parents 81f34c3 + 1072ead commit 466d343

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

src/app/pages/main/components/sidenav/sidenav.component.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
<i class="fas fa-link" aria-hidden="true"></i>
2525
</a>
2626
</mat-chip>
27+
<mat-chip class="social social-share">
28+
<span (click)="onShare()" (keyup.enter)="onShare()" class="community-share" tabindex="0">
29+
Share
30+
<i class="fa fa-share-alt" aria-hidden="true"></i>
31+
</span>
32+
<span (click)="onCopy()" (keyup.enter)="onCopy()" class="community-copy" tabindex="0">
33+
Copy URL
34+
<i class="fa fa-copy" aria-hidden="true"></i>
35+
</span>
36+
</mat-chip>
2737
</mat-chip-list>
2838
</div>
2939
</header>
@@ -88,4 +98,17 @@
8898
</span>
8999
</a>
90100
</ng-template>
101+
<ng-template #emptyCommunityTwitter>
102+
<a class="social-buttons__button social-button social-button--twitter" aria-label="Twitter">
103+
<span class="social-button__inner">
104+
<i class="fab fa-twitter"></i>
105+
</span>
106+
</a>
107+
</ng-template>
108+
<ng-template #linkCopied>
109+
<p class="community-link-copied">
110+
Link Copied!
111+
<button mat-raised-button (click)="onCloseSnackBar()">Dismiss</button>
112+
</p>
113+
</ng-template>
91114
</mat-sidenav-container>

src/app/pages/main/components/sidenav/sidenav.component.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,28 @@ mat-form-field {
7979
.community-detail-container {
8080
padding: 60px 25px 0 25px;
8181
}
82+
83+
.community-copy {
84+
display: block;
85+
}
86+
.community-share {
87+
display: none;
88+
}
89+
90+
.community-link-copied {
91+
display: flex;
92+
justify-content: space-between;
93+
align-items: center;
94+
margin: 0;
95+
font-weight: 900;
96+
color: white;
97+
}
98+
99+
@media (max-width: 599px) {
100+
.community-copy {
101+
display: none;
102+
}
103+
.community-share {
104+
display: block;
105+
}
106+
}
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { Communities, Community } from '@shared/interfaces';
2-
import { Component, EventEmitter, Input, Output } from '@angular/core';
2+
import { Component, EventEmitter, Input, Output, TemplateRef, ViewChild } from '@angular/core';
3+
import { Clipboard } from '@angular/cdk/clipboard';
4+
import { MatSnackBar } from '@angular/material/snack-bar';
35

46
@Component({
57
selector: 'ngcommunity-sidenav',
68
templateUrl: './sidenav.component.html',
79
styleUrls: ['./sidenav.component.scss'],
810
})
911
export class SidenavComponent {
12+
constructor(private clipboard: Clipboard, private snackBar: MatSnackBar) {}
1013
@Input() community: Community;
1114
@Input() communities: Communities;
1215

1316
@Output()
1417
selected = new EventEmitter<Community>();
1518
@Output()
1619
closeInfo = new EventEmitter<void>();
20+
@ViewChild('linkCopied') copied: TemplateRef<any>;
1721

1822
onSelected(selected: Community) {
1923
this.selected.emit(selected);
@@ -22,4 +26,28 @@ export class SidenavComponent {
2226
onCloseInfo() {
2327
this.closeInfo.emit();
2428
}
29+
30+
onShare() {
31+
const nav = window.navigator as any;
32+
if (nav.share) {
33+
nav
34+
.share({
35+
title: this.community.name,
36+
url: location.href,
37+
})
38+
.then(() => console.log('Successful share'))
39+
.catch(error => console.error('Error sharing', error));
40+
}
41+
}
42+
43+
onCopy() {
44+
this.clipboard.copy(location.href);
45+
this.snackBar.openFromTemplate(this.copied, {
46+
duration: 2000
47+
});
48+
}
49+
50+
onCloseSnackBar() {
51+
this.snackBar.dismiss();
52+
}
2553
}

src/app/shared/shared.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
2323
import { MatToolbarModule } from '@angular/material/toolbar';
2424
import { NgModule } from '@angular/core';
2525
import { ScrollingModule } from '@angular/cdk/scrolling';
26+
import { ClipboardModule } from '@angular/cdk/clipboard';
2627

2728
const CORE_MODULES = [BrowserAnimationsModule, CommonModule, FormsModule, ReactiveFormsModule];
2829

@@ -45,6 +46,7 @@ const MATERIAL_MODULES = [
4546
MatDividerModule,
4647
ScrollingModule,
4748
MatChipsModule,
49+
ClipboardModule
4850
];
4951

5052
@NgModule({

src/styles.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ a {
120120
&.social-linkedin {
121121
background-color: #0077b4;
122122
}
123+
&.social-share {
124+
background-color: blue;
125+
}
123126
}
124127

125128
mat-sidenav-container mat-sidenav-content header i {

0 commit comments

Comments
 (0)