dynamic
This commit is contained in:
parent
d29cf8a51e
commit
0b221ded05
@ -7,9 +7,8 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive } from 'vue'
|
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("");
|
const msgContent = ref("");
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@ -18,10 +17,10 @@
|
|||||||
<div id="msg">
|
<div id="msg">
|
||||||
<div id="discList">
|
<div id="discList">
|
||||||
<div @click="fetchDiscussion(discussion.id)" class="discItem" v-for="discussion in discussionsList" :key="discussion.id">{{ discussion.name }}</div>
|
<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>
|
||||||
<div id="discussion">
|
<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 id=msgs>
|
||||||
<div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id">
|
<div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id">
|
||||||
{{ msg.content }}
|
{{ msg.content }}
|
||||||
@ -58,11 +57,8 @@ div#discList{
|
|||||||
}
|
}
|
||||||
|
|
||||||
.InputTitle{
|
.InputTitle{
|
||||||
background: inherit;
|
all: inherit;
|
||||||
border: inherit;
|
margin: auto;
|
||||||
font-size: inherit;
|
|
||||||
font-family: inherit;
|
|
||||||
text-align: inherit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.discItem{
|
.discItem{
|
||||||
|
@ -8,24 +8,18 @@
|
|||||||
import { restGet, restPost, restPatch } from './restConsumer.js'
|
import { restGet, restPost, restPatch } from './restConsumer.js'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
export const currentDiscussion = ref({});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array of
|
|
||||||
* - id
|
* - id
|
||||||
* - name
|
* - name
|
||||||
* - members
|
* - members
|
||||||
*/
|
*/
|
||||||
export async function getDiscussions(){
|
export const discussionsList = ref({});
|
||||||
return restGet("/discussions");
|
export const currentDiscussion = ref({});
|
||||||
}
|
|
||||||
|
|
||||||
export async function fetchDiscussion(id){
|
|
||||||
currentDiscussion.value = await restGet("/discussion/" + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createDiscussion(name){
|
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){
|
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