dynamic
This commit is contained in:
parent
d29cf8a51e
commit
0b221ded05
@ -7,9 +7,8 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { getDiscussions, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage, updateDiscussionName} from '@/rest/msg.js'
|
||||
import { discussionsList, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage, updateDiscussionName} from '@/rest/msg.js'
|
||||
|
||||
const discussionsList = reactive(await getDiscussions());
|
||||
const msgContent = ref("");
|
||||
|
||||
</script>
|
||||
@ -18,10 +17,10 @@
|
||||
<div id="msg">
|
||||
<div id="discList">
|
||||
<div @click="fetchDiscussion(discussion.id)" class="discItem" v-for="discussion in discussionsList" :key="discussion.id">{{ discussion.name }}</div>
|
||||
<button id="createDiscussion" @click="createDiscussion('New Discussion').then( e => discussionsList.push(e) )">+</button>
|
||||
<button id="createDiscussion" @click="createDiscussion('New Discussion')">+</button>
|
||||
</div>
|
||||
<div id="discussion">
|
||||
<h1 id=msgName ><input class="InputTitle" type="text" @blur="updateDiscussionName(currentDiscussion.id, currentDiscussion.name).then(e => { getDiscussions().then(e => { discussionsList = e }) })" v-model="currentDiscussion.name"></h1>
|
||||
<h1 id=msgName ><input class="InputTitle" type="text" @blur="updateDiscussionName(currentDiscussion.id, currentDiscussion.name)" v-model="currentDiscussion.name"></h1>
|
||||
<div id=msgs>
|
||||
<div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id">
|
||||
{{ msg.content }}
|
||||
@ -58,11 +57,8 @@ div#discList{
|
||||
}
|
||||
|
||||
.InputTitle{
|
||||
background: inherit;
|
||||
border: inherit;
|
||||
font-size: inherit;
|
||||
font-family: inherit;
|
||||
text-align: inherit;
|
||||
all: inherit;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.discItem{
|
||||
|
@ -8,24 +8,18 @@
|
||||
import { restGet, restPost, restPatch } from './restConsumer.js'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const currentDiscussion = ref({});
|
||||
|
||||
/**
|
||||
* @return array of
|
||||
* - id
|
||||
* - name
|
||||
* - members
|
||||
*/
|
||||
export async function getDiscussions(){
|
||||
return restGet("/discussions");
|
||||
}
|
||||
export const discussionsList = ref({});
|
||||
export const currentDiscussion = ref({});
|
||||
|
||||
export async function fetchDiscussion(id){
|
||||
currentDiscussion.value = await restGet("/discussion/" + id);
|
||||
}
|
||||
|
||||
export async function createDiscussion(name){
|
||||
return restPost("/discussion", {name: name});
|
||||
let disc = await restPost("/discussion", {name: name});
|
||||
discussionsList.value.push(disc);
|
||||
}
|
||||
|
||||
|
||||
@ -42,5 +36,16 @@ export async function sendMessage(id, content, responseId){
|
||||
}
|
||||
|
||||
export async function updateDiscussionName(id, name){
|
||||
return restPatch("/discussion/" + id, {name: name});
|
||||
restPatch("/discussion/" + id, {name: name}).then(() => fetchDiscussions());
|
||||
}
|
||||
|
||||
|
||||
async function fetchDiscussions(){
|
||||
discussionsList.value = await restGet("/discussions");
|
||||
}
|
||||
|
||||
export async function fetchDiscussion(id){
|
||||
currentDiscussion.value = await restGet("/discussion/" + id);
|
||||
}
|
||||
|
||||
await fetchDiscussions();
|
||||
|
Loading…
Reference in New Issue
Block a user