Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 7cb391b

Browse files
update router to use dates, fix QuizFinishedFail typo
1 parent 11eb5dc commit 7cb391b

File tree

2 files changed

+85
-38
lines changed

2 files changed

+85
-38
lines changed

src/plugins/router.js

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from "vue";
22
import VueRouter from "vue-router";
33
import { auth } from "@/api";
44
import store from "@/store";
5+
import moment from "moment";
56

67
Vue.use(VueRouter);
78

@@ -22,6 +23,23 @@ async function logout() {
2223
await auth.logout();
2324
}
2425

26+
// dates for determining components to render
27+
28+
// start and end time for questions before boss question
29+
let mainQuestionsStartTime = moment("5 Apr 2021 08:00:00 CDT");
30+
let mainQuestionsEndTime = moment("25 Apr 2021 23:59:59 CDT");
31+
32+
// start and end time for boss question (final question)
33+
let bossStartTime = moment("26 Apr 2021 08:00:00 CDT");
34+
let bossEndTime = moment("30 Apr 2021 23:59:59 CDT");
35+
36+
// start and end time for voting
37+
let votingStartTime = moment("3 May 2021 08:00:00 CDT");
38+
let votingEndTime = moment("7 May 2021 23:59:59 CDT");
39+
40+
// easy route testing by passing a date string below
41+
let now = moment();
42+
2543
const routes = [
2644
// testing route
2745
{
@@ -42,7 +60,6 @@ const routes = [
4260
beforeEnter(to, from, next) {
4361
// for testing
4462
if (to.path === "/testing/vote") {
45-
console.log("in redirect", to.path);
4663
next({ path: "/testing/vote" });
4764
return;
4865
}
@@ -134,23 +151,21 @@ const routes = [
134151
path: "voting",
135152
name: "voting",
136153
component: () => {
137-
// return import("@/views/Voting/VotingOver");
138-
return import("@/views/Voting/VoteWoah");
139-
// if (isChallengeClosed()) {
140-
// return import("@/views/Voting/Ballot");
141-
// } else {
142-
// return import("@/views/Voting/VoteWoah");
143-
// }
154+
// show VoteWoah if before vote start time
155+
if (now < votingStartTime) {
156+
return import("@/views/Voting/VoteWoah");
157+
}
158+
159+
// show VotingOver if past vote end time
160+
if (now > votingEndTime) {
161+
// TODO: add a leaderboard here once built
162+
return import("@/views/Voting/VotingOver");
163+
}
164+
165+
// show Ballot otherwise
166+
return import("@/views/Voting/Ballot");
144167
}
145168
}
146-
// {
147-
// path: "vote-confirmation",
148-
// name: "voting-confirmation",
149-
// meta: {
150-
// challengeOver: true
151-
// },
152-
// component: () => import("@/views/Voting/Confirm")
153-
// }
154169
]
155170
},
156171
{
@@ -163,38 +178,71 @@ const routes = [
163178
path: "quiz",
164179
name: "quiz",
165180
component: async () => {
166-
// CHALLENGE HAS NOT STARTED
167-
if (!isChallengeOpen()) {
181+
// time before challenge has started
182+
if (now < mainQuestionsStartTime) {
183+
// TODO: update QuizCountdown's content for 2022's before start time
168184
return import("@/views/Quiz/QuizCountdown");
169185
}
170186

171-
// USER HAS FINISHED QUIZ
172-
if (store.state.Quiz.maxRank === store.state.User.rank - 1) {
173-
return import("@/views/Quiz/QuizFinished");
174-
}
187+
// time during main quiz
188+
if (now >= mainQuestionsStartTime && now <= mainQuestionsEndTime) {
189+
// USER HAS FINISHED QUIZ
190+
// TODO: for 2022 import a 'you finished now wait for boss' component
191+
// if done will all questions except boss
175192

176-
// User did not make the cut
177-
if (
178-
store.state.Quiz.rankToday == store.state.Quiz.maxRank &&
179-
store.state.User.rank != store.state.Quiz.rankToday
180-
) {
181-
return import("@/views/Quiz/QuizFinishedFail");
193+
// NORMAL QUIZ MODE
194+
return import("@/views/Quiz/Quiz");
182195
}
183196

184-
// MUST WAIT FOR NEXT QUESTION
185-
if (store.state.Quiz.awaitNextQuestion) {
197+
// time between main questions ending and boss starting
198+
if (now > mainQuestionsEndTime && now < bossStartTime) {
199+
// TODO: for 2022 make an await final boss component, or start passing props to QuizCountdown
200+
201+
// MUST WAIT FOR NEXT QUESTION
186202
return import("@/views/Quiz/QuizCountdown");
187203
}
188204

189-
// SHOW THE LAST QUESTION
190-
if (store.state.Quiz.isLastQuestion) {
191-
return import("@/views/Quiz/QuizFinalQuestion");
205+
// time during boss final question
206+
if (now >= bossStartTime && now <= bossEndTime) {
207+
// User did not make the cut
208+
if (
209+
store.state.Quiz.rankToday == store.state.Quiz.maxRank &&
210+
store.state.User.rank != store.state.Quiz.rankToday
211+
) {
212+
return import("@/views/Quiz/QuizFinishedFail");
213+
}
214+
215+
// user has finished the boss question
216+
if (store.state.Quiz.maxRank === store.state.User.rank - 1) {
217+
return import("@/views/Quiz/QuizFinished");
218+
}
219+
220+
// show boss question
221+
if (store.state.Quiz.isLastQuestion) {
222+
return import("@/views/Quiz/QuizFinalQuestion");
223+
}
192224
}
193225

194-
// NORMAL QUIZ MODE
195-
return import("@/views/Quiz/Quiz");
226+
// time after boss question ends and before voting
227+
if (now > bossEndTime && now < votingStartTime) {
228+
// user has finished the boss question
229+
if (store.state.Quiz.maxRank === store.state.User.rank - 1) {
230+
return import("@/views/Quiz/QuizFinished");
231+
}
232+
233+
// if time is up and they did not finish, they failed
234+
return import("@/views/Quiz/QuizFinishedFail");
235+
}
236+
237+
// times after voting starts are handled in the route guard
238+
// TODO: make a component that alerts before redirect to /voting for better user experience
196239
},
197240
beforeEnter(from, to, next) {
241+
// redirect if all sections of quiz are over
242+
if (now >= votingStartTime) {
243+
next("/voting");
244+
}
245+
198246
// USER MUST SEE INTRO VIDEO
199247
if (
200248
isChallengeOpen() &&
@@ -252,7 +300,6 @@ const router = new VueRouter({
252300
router.beforeEach(async (to, from, next) => {
253301
// for testing
254302
if (to.path === "/testing/vote") {
255-
console.log("bypassing beforeEach");
256303
next();
257304
return;
258305
}

src/views/Quiz/QuizFinishedFail.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</p>
1414

1515
<p>
16-
You can still vote for this year's winner from April 26-30 and try
17-
again next year.
16+
You can still vote for this year's winner from April May 3 to May 7
17+
and try again next year.
1818
</p>
1919

2020
<v-btn :to="{ name: 'voting' }" color="white" light

0 commit comments

Comments
 (0)