show users count

This commit is contained in:
Philipp Kühn
2019-05-04 20:40:18 +02:00
parent 7cad96ee3c
commit 03cb2d4c75
2 changed files with 51 additions and 1 deletions

View File

@@ -1,6 +1,14 @@
<template> <template>
<div class="editor"> <div class="editor">
<editor-content class="editor__content" :editor="editor" v-if="editor && !loading" /> <div class="message">
With the Collaboration Extension it's possible for several users to work on a document at the same time. To make this possible, client-side and server-side code is required. This example shows this using a <a href="https://glitch.com/edit/#!/tiptap-sockets" target="_blank">socket server</a>. Try it out below:
</div>
<template v-if="editor && !loading">
<div class="count">
{{ count }} {{ count === 1 ? 'user' : 'users' }} connected
</div>
<editor-content class="editor__content" :editor="editor" />
</template>
<em v-else> <em v-else>
Connecting to socket server … Connecting to socket server …
</em> </em>
@@ -22,6 +30,7 @@ export default {
loading: true, loading: true,
editor: null, editor: null,
socket: null, socket: null,
count: 0,
} }
}, },
@@ -51,6 +60,10 @@ export default {
], ],
}) })
}, },
setCount(count) {
this.count = count
},
}, },
mounted() { mounted() {
@@ -60,6 +73,8 @@ export default {
.on('init', data => this.onInit(data)) .on('init', data => this.onInit(data))
// send all updates to the collaboration extension // send all updates to the collaboration extension
.on('update', data => this.editor.extensions.options.collaboration.update(data)) .on('update', data => this.editor.extensions.options.collaboration.update(data))
// get count of connected users
.on('getCount', count => this.setCount(count))
}, },
beforeDestroy() { beforeDestroy() {
@@ -67,3 +82,29 @@ export default {
}, },
} }
</script> </script>
<style lang="scss">
@import "~variables";
.count {
display: flex;
align-items: center;
font-weight: bold;
color: rgba($color-black, 0.5);
color: #27b127;
margin-bottom: 0.5rem;
text-transform: uppercase;
font-size: 0.7rem;
line-height: 1;
&:before {
content: '';
display: inline-flex;
background-color: #27b127;
width: 0.4rem;
height: 0.4rem;
border-radius: 50%;
margin-right: 0.3rem;
}
}
</style>

View File

@@ -74,6 +74,15 @@ h3 {
background-color: rgba($color-black, 0.1); background-color: rgba($color-black, 0.1);
} }
.message {
background-color: rgba($color-black, 0.05);
color: rgba($color-black, 0.7);
padding: 1rem;
border-radius: 6px;
margin-bottom: 1rem;
font-style: italic;
}
@import "./editor"; @import "./editor";
@import "./menubar"; @import "./menubar";
@import "./menububble"; @import "./menububble";