Skip to content

Commit

Permalink
Fix return to catalogue after activity
Browse files Browse the repository at this point in the history
  • Loading branch information
timdrysdale committed Feb 7, 2021
1 parent a1949f8 commit 77f0327
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/src/components/launchActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import describeUI from "./describeUI.vue";
import { mapGetters } from "vuex";

export default {
props: ["id"],
props: ["id", "setTimer"],
components: {
"describe-activity": describeActivity,
"describe-ui": describeUI,
Expand Down
2 changes: 1 addition & 1 deletion src/src/components/launchActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="container-fluid">
<div class="row">
<div class="col bg-secondary">
<h3 class="text-white text-left" > Your hardware</h3>
<h3 class="text-white text-left" > Your hardware </h3>
</div>
</div>
<div class="row">
Expand Down
24 changes: 17 additions & 7 deletions src/src/store/getters.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dayjs from "dayjs";

export const bearer = (state) => state.bearer;

export const bookingToken = (state) => state.bookingToken;
Expand Down Expand Up @@ -43,13 +45,21 @@ export const getBookingByID = (state, id) => {

export const getFinishedByID = (state, id) => {
return (id) => {
var results = state.finishedBookings.filter((obj) => {
return obj.id === id;
});
if (results.length < 1) {
return false;
} else {
return true;
try {
return state.finishedBookings[id].exp <= dayjs().unix();
} catch (e) {
console.log("error checking if finished", id, e);
return false; // avoid prematurely clearing new bookings
}
};
};
export const getTimeLeftByID = (state, id) => {
return (id) => {
try {
return state.finishedBookings[id].exp - dayjs().unix();
} catch (e) {
console.log("error checking if finished", id, e);
return -1;
}
};
};
2 changes: 1 addition & 1 deletion src/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const state = {
poolDescriptions: {},
poolStatus: {},
activityBookings: [],
finishedBookings: [],
finishedBookings: {},
requestsMade: 0,
finishedCount: 0,
lastPoolRefresh: 0,
Expand Down
11 changes: 7 additions & 4 deletions src/src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,24 @@ export const setPoolStatus = (state, status) => {
state.poolStatus[status.id] = status;
};

export const addActivityBooking = (state, booking) => {
/*export const addActivityBooking = (state, booking) => {
state.activityBookings.push(booking);
};
};*/

export const replaceBookings = (state, bookings) => {
var tempBookings = [];
var tempIDs = [];
var i;
for (i = 0; i < bookings.length; i++) {
var id = bookings[i].description.id;
tempBookings.push({
id: bookings[i].description.id,
id: id,
status: bookings[i],
ok: true,
});
tempIDs.push(bookings[i].description.id);
tempIDs.push(id);

state.finishedBookings[id] = bookings[i];
}

state.activityBookings = tempBookings;
Expand Down
33 changes: 21 additions & 12 deletions src/src/views/Activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,43 @@ export default {
components: {
"launch-activity": launchActivity,
},
data() {
return {
timerSet: false,
};
},
computed: {
id: function () {
return this.$route.params.id;
},
finished: function () {
setTimer: function () {
var id = this.id;
if (!id) {
return false;
}

var isFinished = this.getFinishedByID(id);
var timeLeft = this.getTimeLeftByID(id);

if (isFinished) {
this.$router.back();
if (timeLeft > 0 && !this.timerSet) {
console.log("setting Timer for ", timeLeft);
setTimeout(this.goBack, timeLeft * 1000);
this.timerSet = true;
return true;
}
return isFinished;

return this.timerSet;
},
...mapGetters(["getTimeLeftByID"]),
},
methods: {
goBack() {
console.log("going back");
this.$router.back();
},
...mapGetters(["getFinishedByID"]),
},
watch: {
$route(to, from) {
console.log("Activity:", to, from);
},
finished(now, before) {
console.log("watching finish, now=", now, "before=", before);
if (now) {
this.$router.back();
}
},
},
};
2 changes: 1 addition & 1 deletion src/src/views/Activity.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="container-fluid">
<div class="row">
<launch-activity :id="id"
<launch-activity :id="id" :setTimer="setTimer"
></launch-activity>
</div>
</div>
Expand Down

0 comments on commit 77f0327

Please sign in to comment.