From 3803ca0f73ce7b0b7959f4658bbf69be269833f2 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Wed, 2 Dec 2020 15:52:32 +0100 Subject: [PATCH] cache username in localstorage --- docs/src/demos/Examples/CollaborativeEditing/index.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/src/demos/Examples/CollaborativeEditing/index.vue b/docs/src/demos/Examples/CollaborativeEditing/index.vue index b6a47c64..aa3fcd85 100644 --- a/docs/src/demos/Examples/CollaborativeEditing/index.vue +++ b/docs/src/demos/Examples/CollaborativeEditing/index.vue @@ -61,7 +61,7 @@ export default { data() { return { - currentUser: { + currentUser: JSON.parse(localStorage.getItem('currentUser')) || { name: this.getRandomName(), color: this.getRandomColor(), }, @@ -99,11 +99,15 @@ export default { }), ], }) + + localStorage.setItem('currentUser', JSON.stringify(this.currentUser)) }, methods: { setName() { const name = window.prompt('Name') + .trim() + .substring(0, 32) if (name) { return this.updateCurrentUser({ @@ -115,6 +119,8 @@ export default { updateCurrentUser(attributes) { this.currentUser = { ...this.currentUser, ...attributes } this.editor.chain().focus().user(this.currentUser).run() + + localStorage.setItem('currentUser', JSON.stringify(this.currentUser)) }, getRandomColor() {