From 3b6fa7eab67a166860101f0a02c82644480b0f6a Mon Sep 17 00:00:00 2001 From: Wenszel Date: Sat, 13 Mar 2021 16:01:03 +0100 Subject: [PATCH] basic components and schema added --- .gitignore | 1 + backend/schemas/game-room.js | 13 +++++++++++++ backend/server.js | 13 ++++++++++++- src/App.js | 3 ++- src/components/GameBoard.jsx | 6 ++++++ src/components/NameInput.jsx | 30 ++++++++++++++++++++++++++++++ src/components/Navbar.jsx | 15 +++++++++++++++ 7 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 backend/schemas/game-room.js create mode 100644 src/components/GameBoard.jsx create mode 100644 src/components/NameInput.jsx create mode 100644 src/components/Navbar.jsx diff --git a/.gitignore b/.gitignore index af696d2..1833665 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ backend/node_modules +backend/credentials.js # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies diff --git a/backend/schemas/game-room.js b/backend/schemas/game-room.js new file mode 100644 index 0000000..30699a7 --- /dev/null +++ b/backend/schemas/game-room.js @@ -0,0 +1,13 @@ +var mongoose = require('mongoose'); + +var Schema = mongoose.Schema; + +var GameRoomSchema = new Schema({ + id: Number, + createDate: Date, + started: Boolean, + players: Array, + positions: Map +}); + +var GameRoomModel = mongoose.model('GameRoomModel', GameRoomSchema ); \ No newline at end of file diff --git a/backend/server.js b/backend/server.js index fe9168e..fe81a8d 100644 --- a/backend/server.js +++ b/backend/server.js @@ -1,7 +1,18 @@ const express = require("express"); -const mangoose = require("mangoose"); const app = express(); const PORT = 3000|| process.env.PORT; +const mongoose = require("mongoose"); +const CONNECTION_URI = require("./credentials.js").MONGODB_URL; + +mongoose.connect(CONNECTION_URI, { + useNewUrlParser: true, + useUnifiedTopology: true + }) + .then(() => { + console.log('MongoDB Connected…'); + }) +.catch(err => console.error(err)); + app.listen(PORT, ()=>{ console.log("Server runs on port "+PORT); }); \ No newline at end of file diff --git a/src/App.js b/src/App.js index 9921d49..036e830 100644 --- a/src/App.js +++ b/src/App.js @@ -1,9 +1,10 @@ import './App.css'; +import NameInput from './components/NameInput'; function App() { return (
- Hello World! +
); } diff --git a/src/components/GameBoard.jsx b/src/components/GameBoard.jsx new file mode 100644 index 0000000..ff3619c --- /dev/null +++ b/src/components/GameBoard.jsx @@ -0,0 +1,6 @@ +import React from 'react'; + +const GameBoard = () => { + +} +export default GameBoard \ No newline at end of file diff --git a/src/components/NameInput.jsx b/src/components/NameInput.jsx new file mode 100644 index 0000000..32f1df3 --- /dev/null +++ b/src/components/NameInput.jsx @@ -0,0 +1,30 @@ +import React, { useState } from 'react'; +const NameInput = ()=>{ + const [inputValue, setInputValue] = useState(''); + const handleInputChange = (e) => { + setInputValue(e.target.value); + } + const handleButtonClick = () => { + const request = { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name: inputValue }) + }; + fetch('localhost:3000/adduser', request) + .then(response => { + if(response.status == 200){ + //redirect + }else{ + //error + } + }); + } + return( +
+ + +
+ ) +} + +export default NameInput; \ No newline at end of file diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx new file mode 100644 index 0000000..2874620 --- /dev/null +++ b/src/components/Navbar.jsx @@ -0,0 +1,15 @@ +import React, { useEffect } from 'react'; + +const Navbar = () => { + const [names, setNames] = useState([]); + useEffect( + //fetching names, time and other data + ); + return( +
+ {names.map((name)=>{ +

{name}

+ })} +
+ ); +} \ No newline at end of file