Skip to content

Commit

Permalink
adding a photo on capacitor share (#2120)
Browse files Browse the repository at this point in the history
* adding a photo on capacitor share

* setMetaTags before for sharing purpose

* add metaTag at root of the app and change the title based on the page that user is on

* reset metaTag on page changing
  • Loading branch information
yzlucas authored Nov 2, 2024
1 parent dea54c9 commit e81ca72
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8 deletions.
24 changes: 22 additions & 2 deletions client/wfnews-war/src/main/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
} from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { DomSanitizer, Meta, Title } from '@angular/platform-browser';
import { NavigationEnd, Router } from '@angular/router';
import { AppConfigService, TokenService } from '@wf1/core-ui';
import {
RouterLink,
Expand All @@ -37,6 +37,7 @@ import {
} from '@app/services/capacitor-service';
import { CommonUtilityService } from '@app/services/common-utility.service';
import { App, URLOpenListenerEvent } from '@capacitor/app';
import { filter } from 'rxjs/operators';

export const ICON = {
ADVISORIES: 'advisories',
Expand Down Expand Up @@ -156,6 +157,8 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewInit {
protected capacitorService: CapacitorService,
protected commonUtilityService: CommonUtilityService,
protected zone: NgZone,
protected titleService: Title,
protected metaService: Meta,
) {
}

Expand Down Expand Up @@ -269,6 +272,23 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewInit {
},
);
}

this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => {
this.setDefaultMetaTags();
});
}

setDefaultMetaTags(){
const imageUrl = this.appConfigService.getConfig().application.baseUrl.toString() + 'assets/images/share-wildfire.png';
this.titleService.setTitle('BC Wildfire Service');

this.metaService.updateTag({ property: 'og:title', content: 'BC Wildfire Service' });
this.metaService.updateTag({ property: 'og:image', content: imageUrl });
this.metaService.updateTag({ property: 'og:site_name', content: 'BC Wildfire Service' });
this.metaService.updateTag({ name: 'twitter:card', content: 'summary_large_image' });
this.metaService.updateTag({ name: 'twitter:site', content: '@BCGovFireInfo' });
}

initializeDeepLinks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as L from 'leaflet';
import { setDisplayColor } from '@app/utils';
import { WatchlistService } from '@app/services/watchlist-service';
import { CommonUtilityService } from '@app/services/common-utility.service';
import { Meta } from '@angular/platform-browser';

export class AreaRestriction {
public name: string;
Expand Down Expand Up @@ -58,7 +59,8 @@ export class AreaRestrictionsFullDetailsComponent implements OnInit {
private publishedIncidentService: PublishedIncidentService,
private route: Route,
private watchlistService: WatchlistService,
private commonUtilityService: CommonUtilityService
private commonUtilityService: CommonUtilityService,
private metaService: Meta,
) {}

async ngOnInit(): Promise<void> {
Expand All @@ -68,6 +70,7 @@ export class AreaRestrictionsFullDetailsComponent implements OnInit {
returnExtent: false,
});
this.initMap();
this.metaService.updateTag({ property: 'og:title', content: this.restrictionData?.name });
}

async initMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AppConfigService } from '@wf1/core-ui';
import * as L from 'leaflet';
import { HttpClient } from '@angular/common/http';
import { CommonUtilityService } from '@app/services/common-utility.service';
import { Meta } from '@angular/platform-browser';

export class BanProhibition {
public id: string;
Expand Down Expand Up @@ -41,7 +42,8 @@ export class BansFullDetailsComponent implements OnInit {
private publishedIncidentService: PublishedIncidentService,
private httpClient: HttpClient,
private route: Route,
private commonUtilityService: CommonUtilityService
private commonUtilityService: CommonUtilityService,
private metaService: Meta,
) {}

async ngOnInit(): Promise<void> {
Expand All @@ -51,6 +53,7 @@ export class BansFullDetailsComponent implements OnInit {
returnExtent: false,
});
this.initMap();
this.metaService.updateTag({ property: 'og:title', content: `Fire Ban on ${this.banData.description} Open Fires`});
}

async initMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as L from 'leaflet';
import { ResourcesRoutes, setDisplayColor, displayDangerRatingDescription } from '@app/utils';
import { AGOLService } from '@app/services/AGOL-service';
import { CommonUtilityService } from '@app/services/common-utility.service';
import { Meta } from '@angular/platform-browser';

@Component({
selector: 'wfnews-danger-rating-full-details',
Expand All @@ -28,11 +29,13 @@ export class DangerRatingFullDetailsComponent implements OnInit {
private publishedIncidentService: PublishedIncidentService,
private route: Route,
private agolService: AGOLService,
private commonUtilityService: CommonUtilityService
private commonUtilityService: CommonUtilityService,
private metaService: Meta,
) {}

async ngOnInit(): Promise<void> {
this.initMap();
this.metaService.updateTag({ property: 'og:title', content: `${this.rating} Danger Rating`});
}

dangerDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AppConfigService } from '@wf1/core-ui';
import * as esri from 'esri-leaflet';
import L from 'leaflet';
import { setDisplayColor } from '../../../utils';
import { Meta } from '@angular/platform-browser';

export class EvacData {
public name: string;
Expand Down Expand Up @@ -52,7 +53,7 @@ export class EvacAlertFullDetailsComponent implements OnInit {
protected router: Router,
private watchlistService: WatchlistService,
private commonUtilityService: CommonUtilityService,

private metaService: Meta,
) { }

async ngOnInit(): Promise<void> {
Expand All @@ -62,6 +63,7 @@ export class EvacAlertFullDetailsComponent implements OnInit {
returnExtent: false,
});
this.initMap();
this.metaService.updateTag({ property: 'og:title', content: `Evacuation Alert for ${this.evacData.name}`});
}

async initMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
setDisplayColor
} from '../../../utils';
import { ContactUsDialogComponent } from '../../admin-incident-form/contact-us-dialog/contact-us-dialog.component';
import { Meta } from '@angular/platform-browser';

@Component({
selector: 'incident-header-panel',
Expand Down Expand Up @@ -121,6 +122,7 @@ export class IncidentHeaderPanelComponent implements AfterViewInit, OnInit {
private commonUtilityService: CommonUtilityService,
private http: HttpClient,
private cdr: ChangeDetectorRef,
private metaService: Meta,

) {
/* Empty, just here for injection */
Expand All @@ -147,6 +149,7 @@ export class IncidentHeaderPanelComponent implements AfterViewInit, OnInit {
}
}
}
this.metaService.updateTag({ property: 'og:title', content: `${this.incident?.incidentName}`});
}

ngAfterViewInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ShareDialogComponent } from '@app/components/admin-incident-form/share-
import { MatDialog } from '@angular/material/dialog';
import { Capacitor, CapacitorHttp } from '@capacitor/core';
import { map } from 'rxjs/operators';
import { Meta, Title } from '@angular/platform-browser';

const MAX_CACHE_AGE = 30 * 1000;

Expand Down Expand Up @@ -50,6 +51,9 @@ export class CommonUtilityService {
private capacitorService: CapacitorService,
private router: Router,
private dialog: MatDialog,
private titleService: Title,
private metaService: Meta,

) {
setTimeout(() => (this.rofService = injector.get(ReportOfFireService)));
}
Expand Down Expand Up @@ -361,11 +365,14 @@ export class CommonUtilityService {
shareMobile(shareTitle: string) {
const currentUrl = this.appConfigService.getConfig().application.baseUrl.toString() + this.router.url.slice(1);
// contents of the share is out of scope for wfnews-2403. Enhancment should be available in wfnews-2422
const imageUrl = this.appConfigService.getConfig().application.baseUrl.toString() + '/assets/images/share-wildfire.png';

Share.share({
title: shareTitle,
text: 'Share the incident update!',
text: 'Share the incident update',
url: currentUrl,
dialogTitle: 'Share Wildfire News Link'
dialogTitle: 'Share Wildfire News Link',
files: [imageUrl]
}).then(() => {
console.log('Sharing successful');
}).catch(err => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e81ca72

Please sign in to comment.