From 875ae030f73dc8fff900e1030f576d679b92ae94 Mon Sep 17 00:00:00 2001 From: dan Date: Sun, 29 Mar 2020 16:03:18 -0600 Subject: [PATCH] Enhance fb sharing --- .../app/components/image/image.component.ts | 19 ++++++++++++++++--- .../share-popup/share-popup.component.ts | 7 +++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Client/src/app/components/image/image.component.ts b/Client/src/app/components/image/image.component.ts index 3a13395..1569d22 100644 --- a/Client/src/app/components/image/image.component.ts +++ b/Client/src/app/components/image/image.component.ts @@ -1,7 +1,8 @@ import { BibleVerseService } from './../../services/bible-verse.service'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, Inject } from '@angular/core'; import { MatDialogConfig, MatDialog } from '@angular/material'; import { SharePopupComponent } from '../popups/share-popup/share-popup.component'; +import { DOCUMENT } from '@angular/platform-browser'; @Component({ selector: 'image-component', @@ -12,7 +13,7 @@ export class ImageComponent implements OnInit { public shareUrl: string; - constructor(private dialog: MatDialog) { } + constructor(private dialog: MatDialog, @Inject(DOCUMENT) private document) { } ngOnInit() { // this.bibleVerseService.randomVerse().subscribe( @@ -23,8 +24,20 @@ export class ImageComponent implements OnInit { } public share() { + let port = this.document.location.port ? ":"+this.document.location.port : ""; + let baseUrl = this.document.location.protocol +'//'+ this.document.location.hostname + port let opts = new MatDialogConfig; - opts.data = { relativeUrl: '/covid', title: 'Coronavirus Anxiety', description: 'Ecouragement in uncertain times' }; + opts.data = { + prefix: 'o', + otherData: { + imageUrl: baseUrl + '/static/media/images/covid_fb_share.jpg', + imageWidth: 750, + imageHeight: 404, + title: 'Coronavirus Anxiety?', + description: 'The cure for coronavirus anxiety', + url: baseUrl + '/covid' + } + }; let dialog = this.dialog.open(SharePopupComponent, opts); } diff --git a/Client/src/app/components/popups/share-popup/share-popup.component.ts b/Client/src/app/components/popups/share-popup/share-popup.component.ts index 017f054..2fa760a 100644 --- a/Client/src/app/components/popups/share-popup/share-popup.component.ts +++ b/Client/src/app/components/popups/share-popup/share-popup.component.ts @@ -30,8 +30,11 @@ export class SharePopupComponent implements OnInit { this.id = data.id; let port = this.document.location.port ? ":"+this.document.location.port : ""; this.shareUrl = this.document.location.protocol +'//'+ this.document.location.hostname + port + this.shareBaseUrl + data.prefix + this.id; - if (this.data.relativeUrl) { - this.shareUrl = this.document.location.protocol + '//' + this.document.location.hostname + port + this.data.relativeUrl; + if (this.data.prefix === 'o') { + const shareData = encodeURIComponent(JSON.stringify(this.data.otherData)); + console.log(shareData); + this.shareUrl = this.document.location.protocol + '//' + this.document.location.hostname + port + this.shareBaseUrl + data.prefix + shareData; + console.log(this.shareUrl); } this.facebookIframeUrl = this.urlPartA + this.shareUrl + this.urlPartB; this.twitterUrl = this.twitterPartA + data.title + " - " + data.description + "&url=" + this.shareUrl;