From bc398cd04350fbd008c26c3e8878a4c2826925e0 Mon Sep 17 00:00:00 2001 From: Joni Laukka <joni.laukka.overflow@gmail.com> Date: Fri, 12 Jul 2019 14:48:52 +0300 Subject: [PATCH] Tasklist updated and moved to gameview --- src/App.css | 3 +- src/components/GameView.js | 2 + src/components/TaskItem.js | 17 +++++--- src/components/TaskList.js | 72 +++++++++++++++++--------------- src/components/TaskListButton.js | 22 +++++----- 5 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/App.css b/src/App.css index 8cf3141..b3004ac 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 67bdca2..cff3966 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 620ba85..23afd84 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 fedbc03..4a2ed06 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 988beab..e15b6c3 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; -- GitLab