瀏覽代碼

Save settings

Carsten Porth 6 年之前
父節點
當前提交
6551cbe705
共有 2 個文件被更改,包括 44 次插入6 次删除
  1. 4 4
      app/src/pages/settings/settings.html
  2. 40 2
      app/src/pages/settings/settings.ts

+ 4 - 4
app/src/pages/settings/settings.html

@@ -13,7 +13,7 @@
     <ion-card-content>
       <p>The following hashtags will automatically activate the private mode when liking or writing a tweet.</p>
       <ion-label color="primary" stacked>Keywords:</ion-label>
-      <ion-textarea></ion-textarea>
+      <ion-textarea [(ngModel)]="keywords"></ion-textarea>
     </ion-card-content>
   </ion-card>
 
@@ -23,12 +23,12 @@
       <p>To protect your privacy, all data send to the P2P network will be encrypted. Therefore you need to enter or generate a pair of keys. If you run the app on multiple devices, please enter everywhere the same pair of keys.</p>
       <button ion-button block>Generate keys</button>
       <ion-label color="primary" stacked>Public Key:</ion-label>
-      <ion-textarea></ion-textarea>
+      <ion-textarea [(ngModel)]="privateKey"></ion-textarea>
       <ion-label color="primary" stacked>Private Key:</ion-label>
-      <ion-textarea></ion-textarea>
+      <ion-textarea [(ngModel)]="publicKey"></ion-textarea>
       <p>Under no circumstances share your private key with any other person!</p>
     </ion-card-content>
   </ion-card>
 
-  <button ion-button block>Save</button>
+  <button ion-button block (click)="save()">Save</button>
 </ion-content>

+ 40 - 2
app/src/pages/settings/settings.ts

@@ -1,5 +1,6 @@
 import { Component } from '@angular/core';
-import { NavController } from 'ionic-angular';
+import { NavController, ToastController } from 'ionic-angular';
+import { Storage } from '@ionic/storage';
 
 @Component({
   selector: 'page-settings',
@@ -7,8 +8,45 @@ import { NavController } from 'ionic-angular';
 })
 export class SettingsPage {
 
-  constructor(public navCtrl: NavController) {
+  keywords: string;
+  privateKey: string;
+  publicKey: string;
 
+  constructor(
+    public navCtrl: NavController,
+    public toastCtrl: ToastController,
+    private storage: Storage
+  ) {
+    this.loadValuesFromStorage()
   }
 
+  loadValuesFromStorage() {
+    this.storage.get("privateKey")
+      .then(value => {
+        this.privateKey = value;
+      })
+
+    this.storage.get("publicKey")
+      .then(value => {
+        this.publicKey = value;
+      })
+
+    this.storage.get("keywords")
+      .then(value => {
+        this.keywords = value;
+      })
+  }
+
+  save() {
+    this.storage.set("publicKey", this.publicKey);
+    this.storage.set("privateKey", this.privateKey);
+    this.storage.set("keywords", this.keywords);
+
+    const toast = this.toastCtrl.create({
+      message: 'Successfully saved!',
+      position: 'bottom',
+      duration: 3000
+    });
+    toast.present();
+  }
 }