-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouters.js
37 lines (33 loc) · 1.06 KB
/
routers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { getProblemOfDay, problems } from "./db/problems.js";
import { UserDb } from "./db/userDb.js";
export const routers = {
"/": "<problem-form/>",
done: "<done-comp/>",
usage: "<markdown-renderer src='./README.md'/>",
newStream: "<new-stream/>",
joinStream: "<join-stream/>",
problemsDistribution: "<problems-distribution/>",
};
export function routingRules() {
if (!UserDb.get().loggedIn) {
if (location.hash.slice(1) === "") location.hash = "newStream";
} else {
if (
location.hash.slice(1) === "done" &&
(Object.keys(UserDb.get().problems).length === 0 ||
!UserDb.get().problems[problems[getProblemOfDay()].id])
)
location.hash = "";
else if (
location.hash.slice(1) === "" &&
Object.keys(UserDb.get().problems).length > 0 &&
UserDb.get().problems[problems[getProblemOfDay()].id]
)
location.hash = "done";
}
}
export function router() {
const path = window.location.hash.slice(1);
const contentDiv = document.getElementById("content");
contentDiv.innerHTML = routers[path || "/"];
}