From 1f60c86c538cda423a82554fc15cb95d3ca6a1d8 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Wed, 15 Dec 2021 15:02:45 +0100 Subject: add Groups View and message fetcher --- src/services/ChatService.js | 14 ++++++++++++- src/services/CommandsService.js | 8 ++++---- src/services/NotifyErrorService.js | 31 +++++++++++++++++++++-------- src/views/Home.vue | 40 +++++++++++++++++++++++++++++--------- 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/services/ChatService.js b/src/services/ChatService.js index 08deba2..d077e9b 100644 --- a/src/services/ChatService.js +++ b/src/services/ChatService.js @@ -13,7 +13,7 @@ export default { } }) .catch(error => error_notify(error)) - }, + }, async get_all_user_groups() { return await axios @@ -25,5 +25,17 @@ export default { } }) .catch(error => error_notify(error)) + }, + + async get_group_messages(group_pk) { + return await axios + .get(url+`groups/detail/${group_pk}/messages/`) + .then(res => { + return { + status: res.status, + data: res.data + } + }) + .catch(error => error_notify(error)) } } diff --git a/src/services/CommandsService.js b/src/services/CommandsService.js index cc5bdf2..181d50e 100644 --- a/src/services/CommandsService.js +++ b/src/services/CommandsService.js @@ -3,9 +3,9 @@ import ChatService from "./ChatService" import store from "@/store/index.js" import router from '@/router/index.js' -function set_groups(data) { +function set_groups(searcher, data) { function group_command(group) { - console.log(group) + searcher.$emit("group_set", group) } let groups = {} @@ -21,11 +21,11 @@ function set_groups(data) { export default { groups() { return { - async send() { + async send(searcher) { const {data, status} = await ChatService.get_all_user_groups() if (status!==200) return {} - const groups = set_groups(data) + const groups = set_groups(searcher, data) return groups }, diff --git a/src/services/NotifyErrorService.js b/src/services/NotifyErrorService.js index b28e664..465b908 100644 --- a/src/services/NotifyErrorService.js +++ b/src/services/NotifyErrorService.js @@ -1,16 +1,31 @@ import Vue from 'vue' +import router from '@/router/index.js' +import store from "@/store/index.js" + const error_notify = (error) => { - for (const [key, values] of Object.entries(error.response.data)) { - console.log(values) - values.forEach(value => { - Vue.notify({ - type: 'error', - title: value, - text: (key !== 'non_field_errors') ? key : '' - }) + if(error.response.status === 401) { + Vue.notify({ + type: 'error', + title: 'Please login again!', + text: 'Token expire' }) + + store.dispatch('logout') + router.push('/login') } + else + for (const [key, values] of Object.entries(error.response.data)) { + console.log(values) + values.forEach(value => { + Vue.notify({ + type: 'error', + title: value, + text: (key !== 'non_field_errors') ? key : '' + }) + }) + } + return { data: error.response.data, status: error.response.status diff --git a/src/views/Home.vue b/src/views/Home.vue index 1fbbb7f..7bd99a2 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,16 +1,23 @@ @@ -18,6 +25,7 @@