UserBio: a few fixes, but still doesn't work as expected
[vchess.git] / client / src / components / UserBio.vue
CommitLineData
dd10eb93
BA
1<template lang="pug">
2div
3 input#modalBio.modal(type="checkbox")
4 div#bioDiv(
5 role="dialog"
6 data-checkbox="modalBio"
7 )
8 .card
80b38d46 9 div(v-if="st.user.id > 0 && st.user.id == uid")
dd10eb93
BA
10 h3.section(@click="modeEdit = !modeEdit") Click to edit
11 textarea(
80b38d46 12 v-if="userBio !== undefined && modeEdit"
dd10eb93
BA
13 v-model="userBio"
14 )
15 button#submitBtn(@click="sendBio()") Submit
16 div(
17 v-if="userBio !== undefined"
18 v-html="userBio"
19 @click="modeEdit = !modeEdit"
20 )
21 #dialog.text-center {{ st.tr[infoMsg] }}
80b38d46
BA
22 span(
23 :class="{ clickable: !!uname }"
24 @click="showBio()"
25 )
26 | {{ uname || "@nonymous" }}
dd10eb93
BA
27</template>
28
29<script>
30import { store } from "@/store";
31import { ajax } from "@/utils/ajax";
32import { processModalClick } from "@/utils/modalClick.js";
33export default {
34 name: "my-user-bio",
80b38d46 35 props: ["uid", "uname"],
dd10eb93
BA
36 data: function() {
37 return {
38 st: store.state,
39 userBio: undefined,
40 infoMsg: "",
41 modeEdit: false
42 };
43 },
44 mounted: function() {
45 document.getElementById("bioDiv")
46 .addEventListener("click", processModalClick);
47 },
48 methods: {
49 showBio: function() {
80b38d46
BA
50 if (!this.uname)
51 // Anonymous users have no bio:
52 return;
dd10eb93
BA
53 this.infoMsg = "";
54 document.getElementById("modalBio").checked = true;
55 if (this.userBio === undefined) {
56 ajax(
57 "/userbio",
58 "GET",
59 {
80b38d46 60 data: { id: this.uid },
dd10eb93
BA
61 success: (res) => {
62 this.userBio = res.bio;
63 }
64 }
65 );
66 }
67 },
68 sendBio: function() {
69 ajax(
70 "/userbio",
71 "PUT",
72 {
73 data: { bio: this.userBio },
74 success: () => {
75 this.infoMsg = this.st.tr["Modifications applied!"];
76 }
77 }
78 );
79 }
80 }
81};
82</script>
83
84<style lang="sass" scoped>
85[type="checkbox"].modal+div .card
80b38d46 86 max-width: 570px
dd10eb93
BA
87 max-height: 100%
88
89#submitBtn
90 width: 50%
91 margin: 0 auto
92
93#dialog
94 padding: 5px
95 color: blue
96</style>