You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB
Vue

6 years ago
<template>
<div>
<div style="padding: 10px;">
<thread-create v-if="this.with === 'true'" :user_id="this.user_id" @submitted="fetchThreads"></thread-create>
</div>
6 years ago
<h2>Browse Threads</h2>
<div class="card card-body" v-for="thread in threads" v-bind:key="thread.id">
<p v-if="thread.creator != null">{{ thread.creator.name }}</p>
<p v-else>[deleted]</p>
<a v-bind:href="'./test/' + thread.id"><h3>{{ thread.thread_title }}</h3></a>
<button v-if="deleteCheck(thread)" v-on:click="destroyThread(thread.id)" class="btn btn-danger">Delete</button>
6 years ago
</div>
</div>
</template>
<script>
export default {
props: ['user_id', 'with'],
data() {
return {
logged_in: this.user_id,
threads: [],
thread: {
id: '',
6 years ago
thread_title: '',
creator: {
id: '',
6 years ago
name: ''
},
},
thread_id: '',
scroll_flag: true,
edit: false
}
},
created() {
this.fetchThreads();
},
methods: {
fetchThreads() {
fetch("api/threads")
6 years ago
.then(res => res.json())
.then(res => {
6 years ago
this.threads = res.data;
if(this.scroll_flag) {
window.scrollTo(0,document.body.scrollHeight);
} else this.scroll_flag = true;
6 years ago
});
},
deleteCheck(thread) {
return thread.creator != null && this.user_id == thread.creator.id;
},
destroyThread(thread_id) {
fetch("api/thread/destroy/" + thread_id)
//.then(res => res.json())
.then(res => {
this.scroll_flag = false;
this.fetchThreads();
});
}
}
}
</script>