From 49379b11b8dfa179fd81398e8b4b5423c7275038 Mon Sep 17 00:00:00 2001
From: jdlugosz963 <jdlugosz963@gmail.com>
Date: Wed, 15 Dec 2021 14:53:33 +0100
Subject: add Groups View and message fetcher

---
 src/components/group/GroupSender.vue | 67 ++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 src/components/group/GroupSender.vue

(limited to 'src/components/group/GroupSender.vue')

diff --git a/src/components/group/GroupSender.vue b/src/components/group/GroupSender.vue
new file mode 100644
index 0000000..160ca76
--- /dev/null
+++ b/src/components/group/GroupSender.vue
@@ -0,0 +1,67 @@
+<template>
+  <div class="group_view">
+      <h1> {{group.name}} </h1>
+      <div class="messages">
+        <Message v-for="message in messages" :key="message.id" :message="message" />
+      </div>
+
+      <form @submit="send_message">
+        <input v-model="message" type="text" ref="input" />
+      </form>
+  </div>
+</template>
+
+<script>
+import Message from '@/components/group/Message.vue'
+import ChatService from '@/services/ChatService.js'
+
+export default {
+  data() {
+    return {
+      message: "",
+      messages: []
+    }
+  },
+
+  props: {
+    group: Object
+  },
+
+  methods: {
+      close() {
+        this.$emit('close')
+      },
+
+    send_message(e) {
+      e.preventDefault()
+      console.log(this.message)
+      this.message = ""
+    },
+
+    async get_messages() {
+      let {status, data} = await ChatService.get_group_messages(this.group.id)
+
+      console.log(data)
+
+      if(status===200)
+        this.messages = data.messages
+    }
+  },
+
+  components: {
+    Message
+  },
+
+  created() {
+    this.$nextTick(function () {
+      this.$refs.input.focus()
+
+      this.get_messages()
+    })
+  }
+}
+</script>
+
+<style scoped>
+
+</style>
-- 
cgit v1.2.3

