basic components and schema added

This commit is contained in:
Wenszel 2021-03-13 16:01:03 +01:00
parent 5e52ff6fe4
commit 3b6fa7eab6
7 changed files with 79 additions and 2 deletions

1
.gitignore vendored
View File

@ -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

View 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 );

View File

@ -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);
}); });

View File

@ -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>
); );
} }

View File

@ -0,0 +1,6 @@
import React from 'react';
const GameBoard = () => {
}
export default GameBoard

View 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
View 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>
);
}