diff --git a/src/App.css b/src/App.css index 8cf31418c5cc17db9852182200e9fc8dce43451c..b3004ac40734d1b05cd893b254948d77559da7dc 100644 --- a/src/App.css +++ b/src/App.css @@ -219,9 +219,10 @@ div.login button:hover { .tasklist { position: absolute; - margin-top: 50px; + margin-top: 100px; z-index: 2020; background-color: #ffffff80; + color: black; } .tasklist-item { diff --git a/src/components/GameView.js b/src/components/GameView.js index 67bdca2b55d50c3eac5a48b0d2f82cf8d235212b..cff3966a03bf6dffa580a43cb4e517ca8b9fcf16 100644 --- a/src/components/GameView.js +++ b/src/components/GameView.js @@ -1,5 +1,6 @@ import React from "react"; import UserMap from "./UserMap"; +import TaskListButton from "./TaskListButton"; import { BrowserRouter as Router, Link } from "react-router-dom"; export default class GameView extends React.Component { @@ -31,6 +32,7 @@ export default class GameView extends React.Component { <Link to="/"> <button>Game selection</button> </Link> + <TaskListButton gameId={this.state.gameId} /> <UserMap position={initialPosition} zoom={this.state.zoom} diff --git a/src/components/TaskItem.js b/src/components/TaskItem.js index 620ba85b27a310ef6a284cfd563e88695d5cfa0a..23afd845d77ec606f4206a4cebc9ecc29cbf1fb4 100644 --- a/src/components/TaskItem.js +++ b/src/components/TaskItem.js @@ -21,7 +21,7 @@ class TaskItem extends React.Component { }; getFactionlist(gameId) { - fetch(`${process.env.REACT_APP_URL}/game/${gameId}`, { + fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`, { method: "GET" }) .then(result => { @@ -56,10 +56,17 @@ class TaskItem extends React.Component { onTaskDelete = e => { e.preventDefault(); - this.props.onDelete(this.props.task.taskId); - this.setState({ - edit: false - }); + + if ( + window.confirm( + `Are you sure you want to delete task "${this.props.task.taskName}"` + ) + ) { + this.props.onDelete(this.props.task.taskId); + this.setState({ + edit: false + }); + } }; render() { diff --git a/src/components/TaskList.js b/src/components/TaskList.js index fedbc03ae0dbac449f8aa4c7518dcca03597b897..4a2ed06738aad0b9072b6043834214e31a2d040a 100644 --- a/src/components/TaskList.js +++ b/src/components/TaskList.js @@ -21,7 +21,7 @@ class TaskList extends React.Component { getTasks(gameId) { let token = sessionStorage.getItem("token"); - fetch(`${process.env.REACT_APP_URL}/task/get-tasks/${gameId}`, { + fetch(`${process.env.REACT_APP_API_URL}/task/get-tasks/${gameId}`, { method: "GET", headers: { Authorization: "Bearer " + token @@ -43,7 +43,7 @@ class TaskList extends React.Component { } getFactionlist(gameId) { - fetch(`${process.env.REACT_APP_URL}/game/${gameId}`, { + fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`, { method: "GET" }) .then(result => { @@ -68,24 +68,27 @@ class TaskList extends React.Component { } let token = sessionStorage.getItem("token"); - fetch(`${process.env.REACT_APP_URL}/task/new-task/${this.props.gameId}`, { - method: "POST", - headers: { - Authorization: "Bearer " + token, - "Content-Type": "application/json" - }, - body: JSON.stringify({ - taskName: this.state.taskNameInput, - taskDescription: this.state.taskDescriptionInput, - taskIsActive: true, - faction: - this.state.selectedFactionId === "" - ? null - : this.state.selectedFactionId, - taskWinner: null, - taskGame: this.props.gameId - }) - }) + fetch( + `${process.env.REACT_APP_API_URL}/task/new-task/${this.props.gameId}`, + { + method: "POST", + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/json" + }, + body: JSON.stringify({ + taskName: this.state.taskNameInput, + taskDescription: this.state.taskDescriptionInput, + taskIsActive: true, + faction: + this.state.selectedFactionId === "" + ? null + : this.state.selectedFactionId, + taskWinner: null, + taskGame: this.props.gameId + }) + } + ) .then(result => { if (!result.ok) { throw Error(Response.statusText); @@ -112,18 +115,21 @@ class TaskList extends React.Component { onTaskEditSave = (task, winnerFactionId) => { let token = sessionStorage.getItem("token"); - fetch(`${process.env.REACT_APP_URL}/task/edit-task/${this.props.gameId}`, { - method: "POST", - headers: { - Authorization: "Bearer " + token, - "Content-Type": "application/json" - }, - body: JSON.stringify({ - taskId: task.taskId, - taskWinner: winnerFactionId, - taskGame: this.props.gameId - }) - }) + fetch( + `${process.env.REACT_APP_API_URL}/task/edit-task/${this.props.gameId}`, + { + method: "POST", + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/json" + }, + body: JSON.stringify({ + taskId: task.taskId, + taskWinner: winnerFactionId, + taskGame: this.props.gameId + }) + } + ) .then(result => { if (!result.ok) { throw Error(result.responseText); @@ -144,7 +150,7 @@ class TaskList extends React.Component { } let token = sessionStorage.getItem("token"); fetch( - `${process.env.REACT_APP_URL}/task/delete-task/${this.props.gameId}`, + `${process.env.REACT_APP_API_URL}/task/delete-task/${this.props.gameId}`, { method: "DELETE", headers: { diff --git a/src/components/TaskListButton.js b/src/components/TaskListButton.js index 988beab9c3b21520190f5fde33774e76ac74ba35..e15b6c38af518ce6736536315a16af853a250508 100644 --- a/src/components/TaskListButton.js +++ b/src/components/TaskListButton.js @@ -1,12 +1,12 @@ import React, { Fragment } from "react"; import TaskList from "./TaskList"; -class TaskListButton extends React.Component { +export default class TaskListButton extends React.Component { constructor(props) { super(props); this.state = { - open: false, - newTasks: 0 + open: false + // newTasks: 0 }; this.handleClick = this.handleClick.bind(this); @@ -28,10 +28,11 @@ class TaskListButton extends React.Component { open: !this.state.open }, () => { + // Websocket task notification template // Set new task cout to zero when the tasklist opens - if (this.state.open) { - this.setState({ newTasks: 0 }); - } + // if (this.state.open) { + // this.setState({ newTasks: 0 }); + // } } ); }; @@ -40,14 +41,11 @@ class TaskListButton extends React.Component { return ( <Fragment> <button id="tasklistButton" onClick={this.handleClick}> - Tasks ({this.state.newTasks}) + {/* Tasks ({this.state.newTasks}) */} + Tasks </button> - {this.state.open && ( - <TaskList gameId="2c097e6a-591c-4a27-b7cb-38eb44e1f31c" /> - )} + {this.state.open && <TaskList gameId={this.props.gameId} />} </Fragment> ); } } - -export default TaskListButton;