Created
November 24, 2023 11:36
-
-
Save achingachris/20786b0c9ffc8ceada008ec6637321fc to your computer and use it in GitHub Desktop.
using pwa fire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { JokesService } from './jokes.service'; | |
import { pwa } from 'pwafire'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'], | |
}) | |
export class AppComponent { | |
joke = 'Click the Button to Generate a Joke'; | |
jokeCopied = false; | |
title = 'Dad jokes'; | |
constructor(private jokeService: JokesService) {} | |
fetchJoke(): void { | |
this.jokeService.getJoke().subscribe((data: any) => { | |
this.joke = data.joke; | |
}); | |
} | |
async copyJoke(joke: string) { | |
try { | |
const res = await pwa.copyText(joke); | |
this.jokeCopied = res.ok; | |
setTimeout(() => (this.jokeCopied = false), 5000); | |
} catch (error) { | |
console.log(error); | |
} | |
} | |
async shareJoke() { | |
const shareOptions: pwa.ShareOptions = { | |
title: 'Check out this joke!', | |
text: this.joke, | |
url: 'https://www.linkedin.com/in/chrisachinga/' | |
}; | |
try { | |
await pwa.Share(shareOptions); | |
} catch (error) { | |
console.log(error); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment