updates frontend to use DB api

This commit is contained in:
2019-07-04 14:53:50 +02:00
parent 4e28eb4159
commit 503ebf7b6b
5 changed files with 103 additions and 61 deletions

View File

@@ -72,7 +72,7 @@
id="`item-${idx}`"
:value="item.id"
v-model="sell_selected">
{{item.sell_value}} GP
{{item.base_price / 2}} GP
</label>
</div>
<PercentInput></PercentInput>
@@ -118,7 +118,6 @@
data () {
return {
app_state: AppStorage.state,
content: [],
is_selling: false,
is_adding: false,
sell_selected: [],
@@ -126,27 +125,25 @@
},
methods: {
fetchLoot () {
fetch(`http://localhost:8088/loot/${this.player}`)
.then(r => r.json())
.then(data => {
data.forEach(item => this.content.push(item));
})
.then(_ => console.log("Loot loaded !"))
}
},
computed: {
content () {
const playerId = this.player;
console.log("Refresh chest of", playerId);
return this.app_state.player_loot[playerId];
},
// Can the active user sell items from this chest ?
canSell () {
return this.player == this.app_state.player_id;
},
totalSellValue () {
const selected = this.sell_selected;
var value = this.content
return this.content
.filter(item => selected.includes(item.id))
.map(item => item.sell_value)
.map(item => item.base_price / 2)
.reduce((total,value) => total + value, 0);
return value;
},
// Can the user grab items from this chest ?
canGrab () {
@@ -163,9 +160,6 @@
&& !this.is_adding);
}
},
mounted () {
this.fetchLoot();
}
}
</script>