Skip to content

Commit

Permalink
Merge pull request #117 from bigrobsf/multiple_choice
Browse files Browse the repository at this point in the history
Multiple choice
  • Loading branch information
mmmaaatttttt committed Oct 23, 2017
2 parents e5d7e36 + b8e8c22 commit f202d7b
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 15 deletions.
25 changes: 17 additions & 8 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ button {

.button:hover {
text-decoration: none;
box-shadow: $nav-shadow-hover;
}

/*BANNER
Expand Down Expand Up @@ -259,7 +260,8 @@ form * {
box-sizing: border-box;
padding: 2%;
padding-top: 0px;
height: 25vw;
display: inline-block;
height: auto;
width: 30vw;
border: 0px solid;
border-radius: 10px;
Expand Down Expand Up @@ -348,7 +350,7 @@ button.button.dropdown-content {
align-items: center;
color: white;
padding: 2rem;
max-width: 10rem;
max-width: 12rem;
}

.createplaylistheader {
Expand All @@ -363,16 +365,15 @@ button.button.dropdown-content {
.sortablelist {
padding: 2%;
padding-top: 0px;
height: 30vw;
height: auto;
width: 30vw;
box-sizing: border-box;
border: 0px solid;
border-radius: 10px;
background-color: #f1f1f1;
line-height: 25px;
line-height: 1.5rem;
margin: 0 auto;
overflow: auto;
white-space: nowrap;
}

.grabbable {
Expand Down Expand Up @@ -417,16 +418,21 @@ button.button.dropdown-content {
font-size: 1.5rem;
}
body {
font-size: 1.5rem;
font-size: 1rem;
}
.content {
padding-top: 1rem;
padding-left: 0;
padding-right: 0;
margin-top: 1vmax;
}
.content-image {
max-width: 15rem;
padding: 1rem;
}
.forms, .sortablelist {
min-width: 380px;
}
}

@media (max-width: 800px) and (min-width: 600px) {
Expand All @@ -444,7 +450,7 @@ button.button.dropdown-content {
font-size: 1.5rem;
}
body {
font-size: 1.5rem;
font-size: 1rem;
}
.content {
padding-top: 1rem;
Expand All @@ -454,14 +460,17 @@ button.button.dropdown-content {
max-width: 12rem;
margin: auto;
}
.forms, .sortablelist {
min-width: 380px;
}
}

@media (max-width: 1200px) and (min-width: 800px) {
.banner {
width: 250vw;
}
body {
font-size: 20px;
font-size: 1rem;
}
.logo {
max-width: 3.5rem;
Expand Down
97 changes: 97 additions & 0 deletions src/MultipleChoiceQuestionForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import "./MultipleChoiceQuestionForm.css";

class MultipleChoiceQuestionForm extends Component {
constructor(props) {
super(props);
this.state = {
title: "",
choices: []
};
this.handleAdd = this.handleAdd.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleClick = this.handleClick.bind(this);
this.handleRemove = this.handleRemove.bind(this);
this.handleChoiceChange = this.handleChoiceChange.bind(this);
}

handleChange(e) {
this.setState({
[e.target.name]: e.target.value
});
}

handleAdd(e) {
e.preventDefault();
if (this.state.choices.length === 0) return;
this.props.addQuestion({
title: this.state.title,
choices: this.state.choices
});
this.setState({ title: "", choices: [] });
}

handleClick() {
this.setState({ choices: [...this.state.choices, ""] });
}

handleRemove(i) {
let choices = this.state.choices.filter((e, index) => index !== i);
this.setState({ choices });
}

handleChoiceChange(e) {
let choices = [...this.state.choices];
choices[e.target.name] = e.target.value;
this.setState({ choices });
}

render() {
let inputs = this.state.choices.map((e, i) => (
<span className="choice" key={"span" + i}>
<input
type="text"
name={i}
placeholder="answer"
key={i}
value={this.state.choices[i]}
onChange={this.handleChoiceChange}
required
/>
<button className="remove button" key={"butt-" + i} onClick={() => this.handleRemove(i)}>
X
</button>
</span>
));
return (
<div className="forms">
<form className="addQuestion" onSubmit={this.handleAdd}>
<h4>Add Question</h4>
<input
className="quest"
type="text"
onChange={this.handleChange}
name="title"
placeholder="Add A Question"
value={this.state.title}
required
/>
<button className="button ac" type="button" onClick={this.handleClick}>
Add choice
</button>
{inputs}
<button type="submit" className="button" value="Add">
+
</button>
</form>
</div>
);
}
}

MultipleChoiceQuestionForm.propTypes = {
addQuestion: PropTypes.func.isRequired
};

export default MultipleChoiceQuestionForm;
19 changes: 19 additions & 0 deletions src/MultipleChoiceQuestionForm.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.choice {
padding: 0px;
}

.choice input {
margin: 0px;
}

button.remove {
margin: 0px;
}

button.ac {
margin-bottom: 10px;
}

input.quest {
margin-bottom: 2px;
}
8 changes: 4 additions & 4 deletions src/PlaylistWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ class PlaylistWrapper extends Component {
.post(`${BASE_URL}/api/users/${userID()}/playlists`, data, config)
.then(response => {
let playlistID = response.data.id;
this.setState({ error: false, playlistID: playlistID, cleared: true });
this.setState({ error: false, playlistID: playlistID, cleared: true }, this.getPlaylistName);
})
.catch(error => {
this.setState({ error: true });
});
}

componentWillMount() {
let playlistID = this.props.match.params.playlistID;
getPlaylistName() {
let playlistID = this.state.playlistID;
if (playlistID) {
axios
.get(
`${BASE_URL}/api/users/${userID()}/playlists/${+playlistID}`,
`${BASE_URL}/api/users/${userID()}/playlists/${playlistID}`,
config()
)
.then(response => {
Expand Down
1 change: 1 addition & 0 deletions src/QuestionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class QuestionForm extends Component {
name="title"
placeholder="Add A Question"
value={this.state.title}
required
/>
<label htmlFor="timer">Timer (in secs)</label>
<input
Expand Down
28 changes: 28 additions & 0 deletions src/ScreenForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from "axios";
import { BASE_URL, config } from "./helpers.js";
import "./ScreenForm.css";
import QuestionForm from "./QuestionForm";
import MultipleChoiceQuestionForm from "./MultipleChoiceQuestionForm";
import VideoUploadForm from "./VideoUploadForm";
import PropTypes from "prop-types";

Expand All @@ -14,6 +15,7 @@ class ScreenForm extends Component {
searchtext: "",
showVideoForm: false,
showQuestionForm: false,
showMultipleChoiceQuestionForm: false,
showVideoPlayer: false,
videoUrl: ""
};
Expand Down Expand Up @@ -63,13 +65,23 @@ class ScreenForm extends Component {
this.setState({
showVideoForm: true,
showQuestionForm: false,
showMultipleChoiceQuestionForm: false,
showVideoPlayer: false
});
}
if (e.target.id === "addQuestion") {
this.setState({
showVideoForm: false,
showQuestionForm: true,
showMultipleChoiceQuestionForm: false,
showVideoPlayer: false
});
}
if (e.target.id === "addMultipleChoiceQuestion") {
this.setState({
showVideoForm: false,
showQuestionForm: false,
showMultipleChoiceQuestionForm: true,
showVideoPlayer: false
});
}
Expand Down Expand Up @@ -142,6 +154,14 @@ class ScreenForm extends Component {
<QuestionForm addQuestion={this.props.addQuestion} />
</div>
) : null;
let multipleChoiceQuestionForm = this.state
.showMultipleChoiceQuestionForm ? (
<div className="form-wrapper">
<MultipleChoiceQuestionForm
addQuestion={this.props.addMultipleChoiceQuestion}
/>
</div>
) : null;

return (
<div>
Expand All @@ -152,10 +172,18 @@ class ScreenForm extends Component {
<button id="addQuestion" className="button" onClick={this.toggleForm}>
Add Question
</button>
<button
id="addMultipleChoiceQuestion"
className="button"
onClick={this.toggleForm}
>
Add Multiple Choice Question
</button>
</div>
<div>
{videoForm}
{questionForm}
{multipleChoiceQuestionForm}
</div>
</div>
);
Expand Down
22 changes: 19 additions & 3 deletions src/ScreenForm.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
@import "variables";

.form-wrapper {
display: flex;
justify-content: space-around;
@media (min-width: 800px) {
.form-wrapper {
display: flex;
justify-content: space-around;
}
}

.videos-list {
box-sizing: border-box;
padding: 2%;
padding-top: 0px;
display: inline-block;
height: 25vw;
width: 30vw;
border: 0px solid;
Expand All @@ -18,6 +21,19 @@
white-space: nowrap;
}

@media (max-width: 800px) {
.form-wrapper {
display: block;
text-align: center;
justify-content: center;
}
.videos-list {
min-width: 380px;
margin-bottom: 1rem;
height: auto;
}
}

a.video-title {
margin-bottom: 10px;
border-radius: 4px;
Expand Down
Loading

0 comments on commit f202d7b

Please sign in to comment.