Skip to content
Permalink
Browse files

chapter5.5: Save and load memos from firestore

  • Loading branch information...
yysaki committed Aug 20, 2018
1 parent ec0f3fc commit 5d89a7c7cea411c76ed6ca960c42f9a780dfc8c3
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/components/Editor.vue
@@ -10,6 +10,7 @@
</div>
<button class="addMemoBtn" @click="addMemo">メモの追加</button>
<button class="deleteMemoBtn" v-if="memos.length > 1" @click="deleteMemo">選択中のメモを削除</button>
<button class="saveMemosBtn" @click="saveMemos">メモの保存</button>
</div>
<textarea class="markdown" v-model="memos[selectedIndex].markdown"></textarea>
<div class="preview" v-html="preview()"></div>
@@ -32,6 +33,19 @@ export default {
selectedIndex: 0
};
},
created: function() {
var self = this;
firebase
.firestore()
.collection('memos')
.doc(this.user.uid)
.get()
.then(function(doc) {
if (doc.exists) {
self.memos = doc.data().val;
}
});
},
methods: {
logout: function() {
firebase.auth().signOut();
@@ -47,6 +61,13 @@ export default {
this.selectedIndex--;
}
},
saveMemos: function() {
firebase
.firestore()
.collection('memos')
.doc(this.user.uid)
.set({val: this.memos});
},
selectMemo: function(index) {
this.selectedIndex = index;
},

0 comments on commit 5d89a7c

Please sign in to comment.
You can’t perform that action at this time.