Enhance fb sharing

test
dan 2020-03-29 16:03:18 -06:00
parent c2d927788a
commit 875ae030f7
2 changed files with 21 additions and 5 deletions

View File

@ -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);
}

View File

@ -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;