basic components and schema added
This commit is contained in:
parent
5e52ff6fe4
commit
3b6fa7eab6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
backend/node_modules
|
backend/node_modules
|
||||||
|
backend/credentials.js
|
||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|||||||
13
backend/schemas/game-room.js
Normal file
13
backend/schemas/game-room.js
Normal file
@ -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 );
|
||||||
@ -1,7 +1,18 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const mangoose = require("mangoose");
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3000|| process.env.PORT;
|
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, ()=>{
|
app.listen(PORT, ()=>{
|
||||||
console.log("Server runs on port "+PORT);
|
console.log("Server runs on port "+PORT);
|
||||||
});
|
});
|
||||||
@ -1,9 +1,10 @@
|
|||||||
import './App.css';
|
import './App.css';
|
||||||
|
import NameInput from './components/NameInput';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
Hello World!
|
<NameInput></NameInput>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
6
src/components/GameBoard.jsx
Normal file
6
src/components/GameBoard.jsx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const GameBoard = () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
export default GameBoard
|
||||||
30
src/components/NameInput.jsx
Normal file
30
src/components/NameInput.jsx
Normal file
@ -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(
|
||||||
|
<div>
|
||||||
|
<input placeholder = "Podaj swoje imię" type="text" onChange={handleInputChange}/>
|
||||||
|
<input type="submit" onClick={handleButtonClick}/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NameInput;
|
||||||
15
src/components/Navbar.jsx
Normal file
15
src/components/Navbar.jsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import React, { useEffect } from 'react';
|
||||||
|
|
||||||
|
const Navbar = () => {
|
||||||
|
const [names, setNames] = useState([]);
|
||||||
|
useEffect(
|
||||||
|
//fetching names, time and other data
|
||||||
|
);
|
||||||
|
return(
|
||||||
|
<div>
|
||||||
|
{names.map((name)=>{
|
||||||
|
<h1>{name}</h1>
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user