Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start button works (replacing input text thingy) #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/dashboard/DashboardContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class DashboardContent extends React.Component {
{
choices.map((choice, key) => {
const isIMG = choice.startsWith("**Image** ");
return <div className={
"dashboard-content__item--choice" + (isIMG ? "--image" : "") + (key.toString() === answer ? " dashboard-content__item--answer" : "")
} style={ isIMG? {backgroundImage: "url(" + choice.slice(10) + ")"} : null }>
return <div
className={
"dashboard-content__item--choice" + (isIMG ? "--image" : "") + (key === answer ? " dashboard-content__item--answer" : "")
}
style={ isIMG? {backgroundImage: "url(" + choice.slice(10) + ")"} : null }
key={key}
>
{ isIMG ? null: choice }
</div>
})
Expand Down
48 changes: 32 additions & 16 deletions src/components/dashboard/DashboardContentHeader.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
import React from 'react';
import {bindActionCreators} from "redux";
import {connect} from "react-redux";
import { withRouter } from "react-router";
import {toggleModal} from "../../redux/actions/ModalActions";
import {deleteQuiz} from "../../redux/actions/QuizActions";
import { setUrl } from '../../redux/actions/ScoreboardActions';
import { DEFAULT_API_URL, DEFAULT_WEBSOCKET_URL } from '../../configurations';

const url = 'https://howlplay-dashboard.azurewebsites.net/spinup';
const DEFAULT_ADMIN_KEY = "HelloWorld";
// const url = 'https://howlplay-dashboard.azurewebsites.net/spinup';
const url = DEFAULT_API_URL + '/quizzes/codes/';
// const DEFAULT_ADMIN_KEY = "HelloWorld";

function startQuiz(quiz_details, admin_key) {
console.log(quiz_details);
console.log(admin_key);
let data = {details: quiz_details, key: admin_key};
fetch(url, {
method: 'POST',
body: JSON.stringify(data)
}).then(data => {
console.log("Done");
})
function startQuiz(quizCode, setUrl, history) {
/* console.log(quiz_details);
console.log(admin_key);
let data = {details: quiz_details, key: admin_key};
fetch(url, {
method: 'POST',
body: JSON.stringify(data)
}).then(data => {
console.log(data);
}) */
fetch(url + quizCode)
.then(data => data.json())
.then(json => {
if (json.url && (json.url.startsWith("ws://") || json.url.startsWith("wss://"))) {
setUrl(json);
} else {
console.log(`INVALID URL: Redirecting to '${DEFAULT_WEBSOCKET_URL}'`);
setUrl({ ...json, url: DEFAULT_WEBSOCKET_URL });
}
history.push('/displayscore');
}).catch( err => console.log("Error when joining game") );
}

const DashboardContentHeader = ({quiz, quizName, quizCode, groupName, toggleModal, deleteQuiz}) =>
const DashboardContentHeader = ({quiz, quizName, quizCode, toggleModal, deleteQuiz, setUrl, history}) =>
<div id={"dashboard-content-header"} style={{display: `${(quizCode) ? 'flex': 'none'}`}}>
<div className={"dashboard-content-labels"}>
<h1 className={"quiz-name"}>{quizName}</h1>
<h3 className={"quiz-code"}>Code: {quizCode}</h3>
</div>
<div id="dashboard-content-controls">
<button className={"quiz-button"} id={"start-quiz-button"} onClick={(e) => startQuiz(quizName, DEFAULT_ADMIN_KEY)}>Start</button>
<button className={"quiz-button"} id={"start-quiz-button"} onClick={(e) => startQuiz(quizCode, setUrl, history)}>Start</button>
<button className={"quiz-button"} id={"edit-quiz-button"} onClick={(e) => toggleModal(true, quiz)}>Edit</button>
<button className={"quiz-button"} id={"delete-quiz-button"} onClick={(e) => deleteQuiz(quiz)}>Delete</button>
</div>
Expand All @@ -43,8 +58,9 @@ const mapStateToProps = (state) => {

const mapDispatchToProps = dispatch => bindActionCreators({
toggleModal,
deleteQuiz
deleteQuiz,
setUrl
}, dispatch);


export default connect(mapStateToProps, mapDispatchToProps) (DashboardContentHeader);
export default connect(mapStateToProps, mapDispatchToProps) (withRouter(DashboardContentHeader));
8 changes: 4 additions & 4 deletions src/configurations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const DEFAULT_QUIZ_TOKEN = "fc14f8d2-f49b-403e-a65a-20bce77df1b5";

export const DEFAULT_WEBSOCKET_URL = "wss://howlplay-demo-game-server.azurewebsites.net";
export const DEFAULT_API_URL = "https://howlplay-main-server.azurewebsites.net";
// export const DEFAULT_WEBSOCKET_URL = "wss://howlplay-demo-game-server.azurewebsites.net";
// export const DEFAULT_API_URL = "https://howlplay-main-server.azurewebsites.net";
//
// export const DEFAULT_WEBSOCKET_URL = "ws://localhost:9090";
// export const DEFAULT_API_URL = "http://localhost:8080";
export const DEFAULT_WEBSOCKET_URL = "ws://localhost:9090";
export const DEFAULT_API_URL = "http://localhost:8080";
5 changes: 3 additions & 2 deletions src/redux/actions/ScoreboardActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export function setUrl(url) {
export function setUrl(data) {
return {
type : 'SET_URL',
payload : url
payload : data
}
}

2 changes: 1 addition & 1 deletion src/redux/reducers/ScoreboardReducers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const scoreboard_initial_state = {
url : "",
id : ""
id : -1
};

export const ScoreboardReducer = (state=scoreboard_initial_state, action) => {
Expand Down