Skip to content

Commit 1631703

Browse files
author
Kyrylo Burmelov
committed
initial commit
0 parents  commit 1631703

File tree

20 files changed

+3015
-0
lines changed

20 files changed

+3015
-0
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
]
5+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Starter for **HTTP, REST / WS** homework. Binary Studio Academy
2+
3+
## Installation
4+
5+
`yarn install`
6+
7+
`yarn start`
8+
9+
open http://localhost:3002/

config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import path from "path";
2+
3+
export const STATIC_PATH = path.join(__dirname, "public");
4+
export const HTML_FILES_PATH = path.join(STATIC_PATH, "html");
5+
6+
export const PORT = 3002;

data.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const texts = [
2+
"Text for typing #1",
3+
"Text for typing #2",
4+
"Text for typing #3",
5+
"Text for typing #4",
6+
"Text for typing #5",
7+
"Text for typing #6",
8+
"Text for typing #7",
9+
];
10+
11+
export default { texts };

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "http-ws-hw-starter",
3+
"version": "1.0.0",
4+
"description": "Starter for HTTP / WS homework. Binary Studio Academy",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "nodemon server.js --exec \"babel-node\""
8+
},
9+
"keywords": [
10+
"bsa",
11+
"homework"
12+
],
13+
"author": "Kyrylo Burmelov",
14+
"license": "ISC",
15+
"dependencies": {
16+
"express": "^4.17.1",
17+
"socket.io": "^2.3.0"
18+
},
19+
"devDependencies": {
20+
"@babel/core": "^7.10.2",
21+
"@babel/node": "^7.10.1",
22+
"@babel/preset-env": "^7.10.2",
23+
"@babel/register": "^7.10.1",
24+
"nodemon": "^2.0.4"
25+
}
26+
}

public/html/game.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="/styles/reset.css">
8+
<link rel="stylesheet" href="/styles/common.css">
9+
<link
10+
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&display=swap"
11+
rel="stylesheet">
12+
<script src="/socket.io/socket.io.js"></script>
13+
<script defer type="module" src="/javascript/game.mjs"></script>
14+
<title>Game</title>
15+
</head>
16+
17+
<body>
18+
<div id="root">
19+
<div id="rooms-page" class="full-screen">
20+
Rooms Page
21+
</div>
22+
<div id="game-page" class="full-screen display-none">
23+
Game Page
24+
</div>
25+
</div>
26+
</body>
27+
28+
</html>

public/html/login.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="/styles/reset.css">
8+
<link rel="stylesheet" href="/styles/common.css">
9+
<link rel="stylesheet" href="/styles/login.css">
10+
<link
11+
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&display=swap"
12+
rel="stylesheet">
13+
<script defer type="module" src="/javascript/login.mjs"></script>
14+
<title>Login</title>
15+
</head>
16+
17+
<body>
18+
<div id="login-page" class="full-screen flex-centered">
19+
<div class="flex">
20+
<div class="username-input-container">
21+
<input id="username-input" autofocus placeholder="username" type="text">
22+
</div>
23+
<button id="submit-button" class="no-select">submit</button>
24+
</div>
25+
</div>
26+
</body>
27+
28+
</html>

public/javascript/game.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const username = sessionStorage.getItem("username");
2+
3+
if (!username) {
4+
window.location.replace("/login");
5+
}
6+
7+
const socket = io("", { query: { username } });

public/javascript/login.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const username = sessionStorage.getItem("username");
2+
3+
if (username) {
4+
window.location.replace("/game");
5+
}
6+
7+
const submitButton = document.getElementById("submit-button");
8+
const input = document.getElementById("username-input");
9+
10+
const getInputValue = () => input.value;
11+
12+
const onClickSubmitButton = () => {
13+
const inputValue = getInputValue();
14+
if (!inputValue) {
15+
return;
16+
}
17+
sessionStorage.setItem("username", inputValue);
18+
window.location.replace("/game");
19+
};
20+
21+
const onKeyUp = ev => {
22+
const enterKeyCode = 13;
23+
if (ev.keyCode === enterKeyCode) {
24+
submitButton.click();
25+
}
26+
};
27+
28+
submitButton.addEventListener("click", onClickSubmitButton);
29+
window.addEventListener("keyup", onKeyUp);

0 commit comments

Comments
 (0)