Skip to content

Instantly share code, notes, and snippets.

@achingachris
Created November 25, 2023 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achingachris/288668c2cff1cae1f2419bc01b63c15b to your computer and use it in GitHub Desktop.
Save achingachris/288668c2cff1cae1f2419bc01b63c15b to your computer and use it in GitHub Desktop.
cool_cool_clean_code.ts
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 = {
title: 'Check out this joke!',
text: this.joke,
url: 'https://dadjokes-phi.vercel.app/',
};
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