From 4b6be9f09ff56dfae1c719cb744f2312e11be317 Mon Sep 17 00:00:00 2001
From: jdlugosz963 <jdlugosz963@gmail.com>
Date: Sun, 12 Dec 2021 23:09:20 +0100
Subject: add group maker

---
 src/components/GroupMaker.vue | 79 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 src/components/GroupMaker.vue

(limited to 'src/components/GroupMaker.vue')

diff --git a/src/components/GroupMaker.vue b/src/components/GroupMaker.vue
new file mode 100644
index 0000000..59f83fd
--- /dev/null
+++ b/src/components/GroupMaker.vue
@@ -0,0 +1,79 @@
+<template>
+  <div class="group_maker">
+      Group maker
+      <form @submit="make_group">
+          <input
+              v-model="group_name"
+              ref='input'
+              type="text"
+              placeholder="Type group name..."
+          />
+
+          <select multiple v-model="users_selection">
+
+            <option
+              v-for="user in users"
+              :key="user.id"
+              :value="user.id">
+              {{user.username}}
+            </option>
+
+          </select>
+      </form>
+  </div>
+</template>
+
+<script>
+import ChatService from "@/services/ChatService.js"
+import AuthService from "@/services/AuthService.js"
+
+export default {
+  data() {
+    return {
+      group_name: "",
+      users_selection: [],
+      users: []
+    }
+  },
+
+  methods: {
+      close() {
+        this.$emit('close')
+      },
+
+      async make_group(e) {
+        e.preventDefault()
+        console.log(this.users_selection)
+        const {status} = await ChatService.group_create({
+          "name": this.group_name,
+          "users": this.users_selection
+        })
+
+        if(status === 201)
+          this.$notify({
+            type: "success",
+            text: "Group created!"
+          })
+      },
+
+    async set_users() {
+      const {status, data} = await AuthService.info("all=true")
+
+      if(status === 200)
+        this.users = data.users
+      else
+        this.close()
+
+      console.log(this.users)
+    }
+  },
+
+  created() {
+    this.$nextTick(function () {
+      this.$refs.input.focus()
+
+      this.set_users()
+    })
+  }
+}
+</script>
-- 
cgit v1.2.3

