write-tweet.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Component } from "@angular/core";
  2. import {
  3. IonicPage,
  4. NavController,
  5. NavParams,
  6. AlertController
  7. } from "ionic-angular";
  8. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  9. import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
  10. /**
  11. * Generated class for the WriteTweetPage page.
  12. *
  13. * See https://ionicframework.com/docs/components/#navigation for more info on
  14. * Ionic pages and navigation.
  15. */
  16. @IonicPage()
  17. @Component({
  18. selector: "page-write-tweet",
  19. templateUrl: "write-tweet.html"
  20. })
  21. export class WriteTweetPage {
  22. tweet: FormGroup;
  23. constructor(
  24. public navCtrl: NavController,
  25. public navParams: NavParams,
  26. private formBuilder: FormBuilder,
  27. private twitter: TwitterApiProvider,
  28. private alertCtrl: AlertController
  29. ) {
  30. this.tweet = this.formBuilder.group({
  31. text: ["", Validators.maxLength(140)],
  32. p2p: [false]
  33. });
  34. }
  35. ionViewDidLoad() {}
  36. get tweetCharProgress() {
  37. let progress = 1 - this.tweet.value["text"].length / 140;
  38. let radius = 8;
  39. let circumference = Math.PI * radius * 2;
  40. return progress * circumference;
  41. }
  42. submitTweet() {
  43. if (this.tweet.value.p2p) {
  44. this.alertCtrl
  45. .create({
  46. title: "Private Mode",
  47. subTitle:
  48. "Your tweet will be encrypted and send to the private network. TODO!",
  49. buttons: ["OK"]
  50. })
  51. .present();
  52. } else {
  53. this.twitter.tweet(this.tweet.value["text"]);
  54. }
  55. this.navCtrl.pop();
  56. }
  57. }