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

Commit 26cfa60

Browse files
Merge pull request #238 from codewizardshq/update-router-dates
update router to use dates, fix QuizFinishedFail typo
2 parents 11eb5dc + 1a1a69f commit 26cfa60

File tree

2 files changed

+93
-38
lines changed

2 files changed

+93
-38
lines changed

src/plugins/router.js

Lines changed: 91 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,25 @@ 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+
const getCurrentTime = function() {
42+
return moment();
43+
};
44+
2545
const routes = [
2646
// testing route
2747
{
@@ -42,7 +62,6 @@ const routes = [
4262
beforeEnter(to, from, next) {
4363
// for testing
4464
if (to.path === "/testing/vote") {
45-
console.log("in redirect", to.path);
4665
next({ path: "/testing/vote" });
4766
return;
4867
}
@@ -134,23 +153,23 @@ const routes = [
134153
path: "voting",
135154
name: "voting",
136155
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-
// }
156+
const now = getCurrentTime();
157+
158+
// show VoteWoah if before vote start time
159+
if (now < votingStartTime) {
160+
return import("@/views/Voting/VoteWoah");
161+
}
162+
163+
// show VotingOver if past vote end time
164+
if (now > votingEndTime) {
165+
// TODO: add a leaderboard here once built
166+
return import("@/views/Voting/VotingOver");
167+
}
168+
169+
// show Ballot otherwise
170+
return import("@/views/Voting/Ballot");
144171
}
145172
}
146-
// {
147-
// path: "vote-confirmation",
148-
// name: "voting-confirmation",
149-
// meta: {
150-
// challengeOver: true
151-
// },
152-
// component: () => import("@/views/Voting/Confirm")
153-
// }
154173
]
155174
},
156175
{
@@ -163,38 +182,75 @@ const routes = [
163182
path: "quiz",
164183
name: "quiz",
165184
component: async () => {
166-
// CHALLENGE HAS NOT STARTED
167-
if (!isChallengeOpen()) {
185+
const now = getCurrentTime();
186+
187+
// time before challenge has started
188+
if (now < mainQuestionsStartTime) {
189+
// TODO: update QuizCountdown's content for 2022's before start time
168190
return import("@/views/Quiz/QuizCountdown");
169191
}
170192

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

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");
199+
// NORMAL QUIZ MODE
200+
return import("@/views/Quiz/Quiz");
182201
}
183202

184-
// MUST WAIT FOR NEXT QUESTION
185-
if (store.state.Quiz.awaitNextQuestion) {
203+
// time between main questions ending and boss starting
204+
if (now > mainQuestionsEndTime && now < bossStartTime) {
205+
// TODO: for 2022 make an await final boss component, or start passing props to QuizCountdown
206+
207+
// MUST WAIT FOR NEXT QUESTION
186208
return import("@/views/Quiz/QuizCountdown");
187209
}
188210

189-
// SHOW THE LAST QUESTION
190-
if (store.state.Quiz.isLastQuestion) {
191-
return import("@/views/Quiz/QuizFinalQuestion");
211+
// time during boss final question
212+
if (now >= bossStartTime && now <= bossEndTime) {
213+
// User did not make the cut
214+
if (
215+
store.state.Quiz.rankToday == store.state.Quiz.maxRank &&
216+
store.state.User.rank != store.state.Quiz.rankToday
217+
) {
218+
return import("@/views/Quiz/QuizFinishedFail");
219+
}
220+
221+
// user has finished the boss question
222+
if (store.state.Quiz.maxRank === store.state.User.rank - 1) {
223+
return import("@/views/Quiz/QuizFinished");
224+
}
225+
226+
// show boss question
227+
if (store.state.Quiz.isLastQuestion) {
228+
return import("@/views/Quiz/QuizFinalQuestion");
229+
}
230+
}
231+
232+
// time after boss question ends and before voting
233+
if (now > bossEndTime && now < votingStartTime) {
234+
// user has finished the boss question
235+
if (store.state.Quiz.maxRank === store.state.User.rank - 1) {
236+
return import("@/views/Quiz/QuizFinished");
237+
}
238+
239+
// if time is up and they did not finish, they failed
240+
return import("@/views/Quiz/QuizFinishedFail");
192241
}
193242

194-
// NORMAL QUIZ MODE
195-
return import("@/views/Quiz/Quiz");
243+
// times after voting starts are handled in the route guard
244+
// TODO: make a component that alerts before redirect to /voting for better user experience
196245
},
197246
beforeEnter(from, to, next) {
247+
const now = getCurrentTime();
248+
249+
// redirect if all sections of quiz are over
250+
if (now >= votingStartTime) {
251+
next("/voting");
252+
}
253+
198254
// USER MUST SEE INTRO VIDEO
199255
if (
200256
isChallengeOpen() &&
@@ -252,7 +308,6 @@ const router = new VueRouter({
252308
router.beforeEach(async (to, from, next) => {
253309
// for testing
254310
if (to.path === "/testing/vote") {
255-
console.log("bypassing beforeEach");
256311
next();
257312
return;
258313
}

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)