diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-22 19:34:10 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-22 19:34:10 +0200 |
| commit | 18c3a1df700c3454c0cc19103c3665bc8d731ffa (patch) | |
| tree | 45d542b11ffafc1f2928f339bd33836013e63229 /src | |
| parent | a19b16923b1e190ffc31c58acbf0651760abd4ac (diff) | |
| download | DevHive-Angular-18c3a1df700c3454c0cc19103c3665bc8d731ffa.tar DevHive-Angular-18c3a1df700c3454c0cc19103c3665bc8d731ffa.tar.gz DevHive-Angular-18c3a1df700c3454c0cc19103c3665bc8d731ffa.zip | |
Implemented post share button, which copies the post link to the clipboard (thanks to ngxClipboard module)
Diffstat (limited to 'src')
| -rw-r--r-- | src/app/app.module.ts | 4 | ||||
| -rw-r--r-- | src/app/components/post/post.component.html | 6 | ||||
| -rw-r--r-- | src/app/components/post/post.component.ts | 22 |
3 files changed, 28 insertions, 4 deletions
diff --git a/src/app/app.module.ts b/src/app/app.module.ts index cd796c2..47651d4 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,6 +6,7 @@ import { MatInputModule } from '@angular/material/input'; import { MatButtonModule } from '@angular/material/button'; import { MatFormFieldModule } from '@angular/material/form-field'; import { HttpClientModule } from '@angular/common/http'; +import { ClipboardModule } from 'ngx-clipboard'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -54,7 +55,8 @@ import { NavbarComponent } from './components/navbar/navbar.component'; MatInputModule, MatButtonModule, HttpClientModule, - RouterModule + RouterModule, + ClipboardModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/components/post/post.component.html b/src/app/components/post/post.component.html index 48f1d01..65bc73a 100644 --- a/src/app/components/post/post.component.html +++ b/src/app/components/post/post.component.html @@ -1,6 +1,6 @@ <app-loading *ngIf="!loaded"></app-loading> -<section class="card flex-row" [hidden]="loaded"> +<section class="card flex-row" [hidden]="loaded" (mouseleave)="resetShareBtn()"> <aside class="left-pane"> <img class="author-picture round-image hover-half-opacity" [src]="user.profilePictureURL" (click)="goToAuthorProfile()"> </aside> @@ -61,11 +61,11 @@ <button class="padding-small lighter-hover click-effect border-radius-smaller" *ngIf="loggedInAuthor" (click)="toggleEditing()"> <img src="/assets/icons/tabler-icon-edit.svg"> </button> - <button class="flexible padding-small lighter-hover click-effect border-radius-smaller" (click)="goToPostPage()"> + <button class="flexible padding-small lighter-hover click-effect border-radius-smaller" (click)="goToPostPage()"> <img src="/assets/icons/tabler-icon-message-2.svg"> Comment </button> - <button class="flexible padding-small lighter-hover click-effect border-radius-smaller" (click)="goToPostPage()"> + <button #share ngxClipboard [cbContent]="getPostLink()" class="flexible padding-small lighter-hover click-effect border-radius-smaller" (click)="showCopiedMessage()"> <img src="/assets/icons/tabler-icon-link.svg"> Share </button> diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index e1d435d..fb6f262 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -2,6 +2,7 @@ import { AfterViewInit, Component, ElementRef, Input, OnInit, Renderer2, ViewChi import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { Guid } from 'guid-typescript'; +import { AppConstants } from 'src/app/app-constants.module'; import { CloudinaryService } from 'src/app/services/cloudinary.service'; import { PostService } from 'src/app/services/post.service'; import { RatingService } from 'src/app/services/rating.service'; @@ -24,6 +25,9 @@ export class PostComponent implements OnInit, AfterViewInit { @Input() paramId: string; @ViewChild('upvote') upvoteBtn: ElementRef; @ViewChild('downvote') downvoteBtn: ElementRef; + @ViewChild('share') shareBtn: ElementRef; + private _defaultShareBtnInnerHTML: string; + private _linkShared = false; // For optimisation purposes public loggedIn = false; public loggedInAuthor = false; public editingPost = false; @@ -107,6 +111,8 @@ export class PostComponent implements OnInit, AfterViewInit { this.changeColorOfVoteButton(isLike, !isLike); } }); + + this._defaultShareBtnInnerHTML = this.shareBtn.nativeElement.innerHTML; } goToAuthorProfile(): void { @@ -213,4 +219,20 @@ export class PostComponent implements OnInit, AfterViewInit { this._renderer.setStyle(this.upvoteBtn.nativeElement, 'backgroundColor', (isUpvoted) ? 'var(--upvote-highlight)' : 'inherit'); this._renderer.setStyle(this.downvoteBtn.nativeElement, 'backgroundColor', (isDownvoted) ? 'var(--downvote-highlight)' : 'inherit'); } + + resetShareBtn(): void { + if (this._linkShared) { + this._renderer.setProperty(this.shareBtn.nativeElement, 'innerHTML', this._defaultShareBtnInnerHTML); + this._linkShared = false; + } + } + + showCopiedMessage(): void { + this._renderer.setProperty(this.shareBtn.nativeElement, 'innerHTML', 'Link copied to clipboard!'); + this._linkShared = true; + } + + getPostLink(): string { + return AppConstants.API_POST_URL + '/' + this.paramId; + } } |
