This commit is contained in:
j3d1 2023-05-14 00:55:57 +02:00
parent b4ea1d8df2
commit c14762e20b
2 changed files with 75 additions and 8 deletions

View file

@ -203,6 +203,16 @@ export default createStore({
}) })
console.log('ext_reply', ext_reply) console.log('ext_reply', ext_reply)
return true; return true;
},
async acceptFriend({state, dispatch}, args) {
console.log('accepting friend ' + args)
},
async declineFriend({state, dispatch}, args) {
console.log('declining friend ' + args)
},
async fetchFriendRequests({state, dispatch}) {
const requests = await dispatch('apiLocalGet', {target: '/api/friendrequests/'})
return requests
} }
}, },
getters: { getters: {

View file

@ -13,10 +13,10 @@
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th style="width:40%;">Name</th> <th>Name</th>
<th class="d-none d-md-table-cell" style="width:25%">Server</th> <th class="d-none d-md-table-cell" style="width:25%">Server</th>
<th> <th style="width: 16em">
<a @click="fetchFriends" class="align-middle"> <a @click="fetchContent" class="align-middle">
<b-icon-arrow-clockwise></b-icon-arrow-clockwise> <b-icon-arrow-clockwise></b-icon-arrow-clockwise>
Refresh Refresh
</a> </a>
@ -55,6 +55,45 @@
</table> </table>
</div> </div>
</div> </div>
<div class="col-12 col-xl-6">
<div class="card">
<div class="card-header">
<h5 class="card-title">Requests</h5>
<h6 class="card-subtitle text-muted">Bar <code>baz</code>.</h6>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th class="d-none d-md-table-cell" style="width:25%">Key</th>
<th style="width: 16em">
<a @click="fetchContent" class="align-middle">
<b-icon-arrow-clockwise></b-icon-arrow-clockwise>
Refresh
</a>
</th>
</tr>
</thead>
<tbody>
<tr v-for="request in requests" :key="request.befriender">
<td>{{ request.befriender }}</td>
<td class="d-none d-md-table-cell">
{{ request.befriender_public_key.slice(0,32) }}...</td>
<td class="table-action">
<button class="btn btn-sm btn-success" @click="tryAcceptFriend(request.befriender)">
<b-icon-check></b-icon-check>
Accept
</button> &nbsp;
<button class="btn btn-sm btn-danger" @click="tryRejectFriend(request.befriender)">
<b-icon-x></b-icon-x>
Decline
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div> </div>
</div> </div>
</main> </main>
@ -76,7 +115,8 @@ export default {
return { return {
friends: {}, friends: {},
show_newfriend: false, show_newfriend: false,
newfriend: "" newfriend: "",
requests: []
} }
}, },
computed: { computed: {
@ -93,8 +133,8 @@ export default {
} }
}, },
methods: { methods: {
...mapActions(['getFriends', "getFriendServer", "requestFriend"]), ...mapActions(['getFriends', "getFriendServer", "requestFriend", "acceptFriend", "fetchFriendRequests", "declineFriend"]),
fetchFriends() { fetchContent() {
this.getFriends().then((friends) => { this.getFriends().then((friends) => {
friends.map((friend) => { friends.map((friend) => {
this.getFriendServer({username: friend}).then((server) => { this.getFriendServer({username: friend}).then((server) => {
@ -102,6 +142,9 @@ export default {
}) })
}) })
}) })
this.fetchFriendRequests().then((requests) => {
this.requests = requests
})
}, },
showNewFriend() { showNewFriend() {
this.show_newfriend = true this.show_newfriend = true
@ -111,13 +154,27 @@ export default {
if (ok) { if (ok) {
this.show_newfriend = false this.show_newfriend = false
this.newfriend = "" this.newfriend = ""
this.fetchFriends() this.fetchContent()
}
}).catch(() => {})
},
tryAcceptFriend(friend) {
this.acceptFriend({username: friend}).then((ok) => {
if (ok) {
this.fetchContent()
}
}).catch(() => {})
},
tryRejectFriend(friend) {
this.declineFriend({username: friend}).then((ok) => {
if (ok) {
this.fetchContent()
} }
}).catch(() => {}) }).catch(() => {})
} }
}, },
mounted() { mounted() {
this.fetchFriends() this.fetchContent()
} }
} }
</script> </script>