diff --git a/.gitignore b/.gitignore
index 4d29575..74fdfbe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
+
+projectnotes.md*
diff --git a/src/components/ApplicationViews.js b/src/components/ApplicationViews.js
index 56d2011..d9fba45 100644
--- a/src/components/ApplicationViews.js
+++ b/src/components/ApplicationViews.js
@@ -2,6 +2,10 @@ import React from "react"
import { Route } from "react-router-dom"
import { EventList } from "./game/EventList.js"
import { GameList } from "./game/GameList.js"
+import { GameForm } from "./game/GameForm.js"
+import { EventForm } from "./game/EventForm.js"
+import { UpdateEvent } from "./game/UpdateEvent.js"
+import { UpdateGame} from "./game/UpdateGame.js"
export const ApplicationViews = () => {
return <>
{
+
+
+
+
+
+
+
+
+
+
+
+
>
diff --git a/src/components/game/EventForm.js b/src/components/game/EventForm.js
new file mode 100644
index 0000000..f47232e
--- /dev/null
+++ b/src/components/game/EventForm.js
@@ -0,0 +1,66 @@
+import React, { useState, useEffect } from "react"
+import { useHistory } from 'react-router-dom'
+
+
+export const EventForm = () => {
+ const history = useHistory()
+ const [eventTypes, setEventTypes] = useState([])
+
+ /*
+ Since the input fields are bound to the values of
+ the properties of this state variable, you need to
+ provide some default values.
+ */
+ const [currentEvent, setCurrentEvent] = useState({
+ skillLevel: 1,
+ Description: "",
+ date: "",
+ time: "",
+ game_id: 1,
+ organizer_id: 1
+ })
+
+ useEffect(() => {
+ // TODO: Get the event types, then set the state
+ }, [])
+
+ const changeEventState = (domEvent) => {
+ // TODO: Complete the onChange function
+ }
+
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/src/components/game/EventList.js b/src/components/game/EventList.js
index c65ad54..70b15f8 100644
--- a/src/components/game/EventList.js
+++ b/src/components/game/EventList.js
@@ -1,23 +1,51 @@
-import React, { useEffect, useState } from "react"
-import { getEvents } from "./EventManager.js"
+import React, { useEffect, useState, } from "react"
+import { getEvents, } from "./EventManager.js"
+import { UpdateEvent } from "./UpdateEvent.js"
+import { useHistory } from "react-router-dom/cjs/react-router-dom.min"
export const EventList = (props) => {
const [ events, setEvents ] = useState([])
+ const history = useHistory()
useEffect(() => {
getEvents().then(data => setEvents(data))
}, [])
- return (
-
+return (
+
+
+
+
{
- events.map(event => {
- return
+ events.map(
+ event => {
+ return(
+ <>
+
+
{event.description}
The event is happening on {event.date} at {event.time}.
- })
- }
+ >
+ )
+
+ }
+ )
+ }
+
+
+
)
}
\ No newline at end of file
diff --git a/src/components/game/EventManager.js b/src/components/game/EventManager.js
index 86daf5f..41d190f 100644
--- a/src/components/game/EventManager.js
+++ b/src/components/game/EventManager.js
@@ -5,4 +5,41 @@ export const getEvents = () => {
}
})
.then(response => response.json())
+}
+
+export const getEventById = (id) => {
+ return fetch(`http://localhost:8000/events/${id}`, {
+ headers:{
+ "Authorization": `Token ${localStorage.getItem("lu_token")}`
+ }
+ })
+ .then(response => response.json())
+}
+export const putEvents = (editedEvent) => {
+ return fetch(`http://localhost:8000/events/${editedEvent.id}`, {
+ method: "PUT",
+ body: JSON.stringify(
+ editedEvent
+ ),
+ headers:{
+ "Authorization": `Token ${localStorage.getItem("lu_token")}`,
+ "Content-Type": "Application/json"
+ }
+ }
+ )
+ .then(response => {response => {
+ return response.json()
+ }
+ }
+ )
+
+}
+
+export const createEvent = (event) => {
+ return fetch("http://localhost:8000/events", {
+ headers:{
+ "Authorization": `Token ${localStorage.getItem("lu_token")}`
+ }
+ })
+ .then(response => response.json())
}
\ No newline at end of file
diff --git a/src/components/game/GameForm.js b/src/components/game/GameForm.js
new file mode 100644
index 0000000..b127f91
--- /dev/null
+++ b/src/components/game/GameForm.js
@@ -0,0 +1,66 @@
+import React, { useState, useEffect } from "react"
+import { useHistory } from 'react-router-dom'
+import { createGame, getGameTypes } from './GameManager.js'
+
+
+export const GameForm = () => {
+ const history = useHistory()
+ const [gameTypes, setGameTypes] = useState([])
+
+ /*
+ Since the input fields are bound to the values of
+ the properties of this state variable, you need to
+ provide some default values.
+ */
+ const [currentGame, setCurrentGame] = useState({
+ skillLevel: 1,
+ numberOfPlayers: 0,
+ title: "",
+ maker: "",
+ gameTypeId: 0
+ })
+
+ useEffect(() => {
+ // TODO: Get the game types, then set the state
+ }, [])
+
+ const changeGameState = (domEvent) => {
+ // TODO: Complete the onChange function
+ }
+
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/src/components/game/GameList.js b/src/components/game/GameList.js
index 7983eb0..5fa53b8 100644
--- a/src/components/game/GameList.js
+++ b/src/components/game/GameList.js
@@ -1,18 +1,36 @@
import React, { useEffect, useState } from "react"
import { getGames } from "./GameManager.js"
+import {useHistory } from "react-router-dom"
+import { UpdateEvent } from "./UpdateEvent.js"
export const GameList = (props) => {
const [ games, setGames ] = useState([])
+ const history = useHistory()
+
useEffect(() => {
getGames().then(data => setGames(data))
- }, [])
+ },
+ []
+)
return (
+ <>
+
+
{
games.map(game => {
return
+
{game.title} by {game.maker}
{game.number_of_players} players needed
Skill level is {game.skill_level}
@@ -20,5 +38,6 @@ export const GameList = (props) => {
})
}
+ >
)
}
\ No newline at end of file
diff --git a/src/components/game/GameManager.js b/src/components/game/GameManager.js
index 69fd552..e26aed1 100644
--- a/src/components/game/GameManager.js
+++ b/src/components/game/GameManager.js
@@ -5,4 +5,45 @@ export const getGames = () => {
}
})
.then(response => response.json())
+}
+
+export const getGameById = (id) => {
+ return fetch(`http://localhost:8000/games/${id}`, {
+ headers:{
+ "Authorization": `Token ${localStorage.getItem("lu_token")}`
+ }
+ })
+ .then(response => response.json())
+}
+
+export const createGame = (game) => {
+ return fetch("http://localhost:8000/games", {
+ headers:{
+ "Authorization": `Token ${localStorage.getItem("lu_token")}`
+ }
+ })
+ .then(response => response.json())
+}
+
+export const getGameTypes = () => {
+ return fetch("http://localhost:8000/gametypes", {
+ headers:{
+ "Authorization": `Token ${localStorage.getItem("lu_token")}`
+ }
+ })
+ .then(response => response.json())
+}
+
+export const putGames = (editedGame) => {
+ return fetch(`http://localhost:8000/games/${editedGame.id}`, {
+ method: "PUT",
+ body: JSON.stringify(
+ editedGame
+ ),
+ headers:{
+ "Authorization": `Token ${localStorage.getItem("lu_token")}`,
+ "Content-Type": "Application/json"
+ }
+ }
+ )
}
\ No newline at end of file
diff --git a/src/components/game/UpdateEvent.js b/src/components/game/UpdateEvent.js
new file mode 100644
index 0000000..73a9b4c
--- /dev/null
+++ b/src/components/game/UpdateEvent.js
@@ -0,0 +1,117 @@
+import react, { useState, useEffect, } from "react";
+import { useParams, useHistory } from "react-router-dom/cjs/react-router-dom.min";
+import { getGames } from "./GameManager";
+import { putEvents } from "./EventManager";
+import { getEvents, getEventById } from "./EventManager";
+
+// getGames is imported to allow the select to display a list of games
+export const UpdateEvent = (props) => {
+ const [ gameList, setGameList] = useState([])
+ const [ eventList, setEventList] = useState([])
+ const [ eventToEdit, setEventToEdit ] = useState({})
+
+
+ let { id } = useParams()
+ const history = useHistory()
+
+
+
+
+useEffect(() => {
+ getGames().then(data => setGameList(data))
+ getEvents().then(data => setEventList(data))
+ getEventById(id).then(data =>
+ {
+ setEventToEdit(data)
+
+ }
+ )
+ },
+ []
+)
+
+
+ // Still need to write out this form and figure out controlled/uncontrolled input for it. Event pk value needs to be passed to the form as props if I'm understanding this correctly
+ const eventupdateform = () => {
+ return(
+ <>
+ Update Event
+
+
+ >
+
+ )
+ }
+ return(
+ eventupdateform()
+ )
+}
+
diff --git a/src/components/game/UpdateGame.js b/src/components/game/UpdateGame.js
new file mode 100644
index 0000000..749870b
--- /dev/null
+++ b/src/components/game/UpdateGame.js
@@ -0,0 +1,118 @@
+import react, { useState, useEffect, } from "react";
+import { useParams, useHistory } from "react-router-dom/cjs/react-router-dom.min";
+import { getGames, getGameById, getGameTypes, putGames } from "./GameManager";
+
+// getGames is imported to allow the select to display a list of games
+export const UpdateGame = (props) => {
+ const [ gameList, setGameList] = useState([])
+ const [ gameToEdit, setGameToEdit ] = useState({})
+ const [gametypes, setGameTypes ] = useState([])
+ let { id } = useParams()
+ const history = useHistory()
+
+
+
+
+useEffect(() => {
+ getGames().then(data => setGameList(data))
+ getGameTypes().then(data=> setGameTypes(data))
+ getGameById(id).then(data =>
+ {
+ data.game_type = data.game_type.id
+ setGameToEdit(data)
+
+ }
+ )
+ },
+ []
+)
+
+
+
+ const gameupdateform = () => {
+ return(
+ <>
+ Update Game
+
+
+ >
+
+ )
+ }
+ return(
+ gameupdateform()
+ )
+}
+