41 lines
938 B
TypeScript
41 lines
938 B
TypeScript
import { reactive, ref } from 'vue'
|
|
|
|
export const groups_store = reactive({
|
|
groups: ref([]),
|
|
})
|
|
|
|
export function update_groups() {
|
|
fetch('http://localhost:31337/get/groups', {
|
|
credentials: 'include',
|
|
})
|
|
.then((res) => {
|
|
res
|
|
.json()
|
|
.then((groupsjson) => {
|
|
groups_store.groups = groupsjson.groups
|
|
})
|
|
.catch(() => {})
|
|
})
|
|
.catch(() => {})
|
|
}
|
|
|
|
export function add_group(group: string) {
|
|
fetch('http://localhost:31337/post/group?name=' + group, {
|
|
credentials: 'include',
|
|
method: 'POST',
|
|
body: JSON.stringify({ name: group }),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
.then((res) => {
|
|
if (res.status === 400) {
|
|
console.log('Group submitted is invalid.')
|
|
} else if (res.status === 401) {
|
|
console.log("You aren't logged in.")
|
|
} else {
|
|
update_groups()
|
|
}
|
|
})
|
|
.catch(() => {})
|
|
}
|