Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Choose your own adventure MVP/React skeleton #63

Merged
merged 38 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
86fdf27
Created files needed
maoivy Feb 18, 2020
a83ff6b
Update chooseAdventure.js
maoivy Feb 19, 2020
4748ce3
Merge branch 'master' into cyoa-skeleton
maoivy Feb 21, 2020
30510f9
added the view
Mayowa99 Feb 21, 2020
9dbb50c
changed name
maoivy Feb 21, 2020
d05f37d
added stageview
maoivy Feb 21, 2020
b9c8243
added button and stuff
maoivy Feb 21, 2020
5d361b1
add proptypes for intro
maoivy Feb 21, 2020
ce1a864
Update stageView.js
maoivy Feb 21, 2020
8f00c93
Switched to using a dictionary rather than direct references
Dylan-Weber Feb 21, 2020
037e6e6
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
Dylan-Weber Feb 21, 2020
0d17c5a
Commit after merge + minor newline changes
Dylan-Weber Feb 21, 2020
55609cf
updated the intro view
Mayowa99 Feb 21, 2020
9fdbc5e
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
Mayowa99 Feb 21, 2020
92fc4a2
Implemented first steps of stageview
Dylan-Weber Feb 26, 2020
eaf9a1a
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
Dylan-Weber Feb 26, 2020
feb541a
changed some skeleton stuff
maoivy Feb 28, 2020
8575a51
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
maoivy Feb 28, 2020
b8bd724
Fixed the error on my end
Dylan-Weber Feb 28, 2020
b8bdaad
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
Dylan-Weber Feb 28, 2020
5f47419
Refactored stuff, moved get started button
maoivy Feb 28, 2020
1d531cc
Removed unecessary spacing
Dylan-Weber Feb 28, 2020
37ac9d1
Added connections to end view and success total calc
maoivy Feb 28, 2020
f9966ae
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
maoivy Feb 28, 2020
a9c72e6
Changed setActiveStage to setStage
Dylan-Weber Feb 28, 2020
7a20ca7
Added restart adventure
maoivy Feb 28, 2020
b58cd4b
Temp commit. Started adding updateHistory
Dylan-Weber Feb 28, 2020
156da6c
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
Dylan-Weber Feb 28, 2020
019d916
Added history
Dylan-Weber Feb 28, 2020
df15283
Added history to overview
maoivy Feb 28, 2020
71eb60a
Designed front page
Mayowa99 Feb 28, 2020
77f6970
Merge branch 'cyoa-skeleton' of https://github.com/dhmit/democracy_af…
Mayowa99 Feb 28, 2020
4e969b1
add assets dir for images
ryaanahmed Feb 28, 2020
dbd4d23
Merge branch 'cyoa-skeleton' of github.com:dhmit/democracy_africa int…
ryaanahmed Feb 28, 2020
3341387
move sample.jpg to new structure
ryaanahmed Feb 28, 2020
3e24732
Merge branch 'master' into cyoa-skeleton
ryaanahmed Feb 28, 2020
ff5a07e
Merge branch 'master' into cyoa-skeleton
ryaanahmed Feb 29, 2020
299cb1b
Add edx view, add success detail, change calc to multipliers
maoivy Mar 3, 2020
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ frontend/node_modules
# production
build/
static/
assets/

# misc
.DS_Store
Expand Down
5 changes: 1 addition & 4 deletions .idea/democracy_africa.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/rSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/img/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Images go here!
Binary file added assets/img/sample.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
# where collectstatic looks for static files
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'build'),
os.path.join(PROJECT_ROOT, 'assets'),
)

REST_FRAMEWORK = {
Expand Down
1 change: 1 addition & 0 deletions backend/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def edx_path(route, component_name):
# React views
path('', render_react_view, {'component_name': 'IndexView'}),
path('all_view/', render_react_view, {'component_name': 'AllView'}),
path('adventure/', render_react_view, {'component_name': 'ChooseAdventureView'}),
maoivy marked this conversation as resolved.
Show resolved Hide resolved
edx_path('map_quiz/', 'MapQuiz'),
edx_path('budget_voting_simulation/', 'BudgetVotingSimViz'),
edx_path('heat_map/', 'DemocracyViz'),
Expand Down
1 change: 1 addition & 0 deletions frontend/src/UILibrary/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
@import '../democracyViz/democracyViz';
@import '../budgetSimulation/budgetSimulation';
@import './edx.scss';
@import "../chooseAdventure/chooseAdventure";


2 changes: 2 additions & 0 deletions frontend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { BudgetVotingSimViz } from './budgetSimulation/budgetSimulation.js';
import { DemocracyViz } from './democracyViz/democracyViz.js';
import { CampaignView } from "./campaign/campaignView";
import { EdXView } from "./UILibrary/components";
import { ChooseAdventureView } from "./chooseAdventure/chooseAdventure.js";

// Import all styles
import './UILibrary/styles.scss';
Expand All @@ -30,4 +31,5 @@ window.app_modules = {
DemocracyViz,
CampaignView,
EdXView,
ChooseAdventureView,
};
84 changes: 84 additions & 0 deletions frontend/src/chooseAdventure/chooseAdventure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import IntroView from './introView.js';
import StageView from './stageView.js';
import EndView from './endView.js';


/**
* Component for displaying choose your own adventure skeleton
*/
export class ChooseAdventureView extends React.Component {
constructor(props) {
super(props);
this.state = {
view: 'intro',
history: [],
successTotal: 0,
};
}

componentDidMount() {
// do your fetch and set initial state
}

setView = (view) => {
this.setState({ view: view, });
};

updateHistory = (option) => {
this.setState((prevState) => ({
history: prevState.history.concat(option),
}));
};

updateSuccess = (successFactor) => {
this.setState((prevState) => ({
successTotal: prevState.successTotal + successFactor,
maoivy marked this conversation as resolved.
Show resolved Hide resolved
}));
};

resetProgress = () => {
this.setState({
successTotal: 0,
history: [],
});
};


render() {
const desc = 'example paragraph: Paragraphs are the building blocks of papers. Many ' +
'students ' +
'define paragraphs in terms of length: a paragraph is a group of at least five ' +
'sentences, ' +
'a paragraph is half a page long, etc. In reality, though, the unity and coherence ' +
'of ' +
'ideas among sentences is what constitutes a paragraph. A paragraph is defined as ' +
'“a ' +
'group of sentences or a single sentence that forms a unit” (Lunsford and Connors ' +
'116). ' +
'Length and appearance do not determine whether a section in a paper is a paragraph. ' +
'For instance, in some styles of writing, particularly journalistic styles, a ' +
'paragraph ' +
'can be just one sentence long. Ultimately, a paragraph is a sentence or group of ' +
'sentences that support one main idea. In this handout, we will refer to this as the ' +
'“controlling idea,” because it controls what happens in the rest of the paragraph.';
console.log("rerendering");
return (
<div>
{this.state.view === 'intro' && <IntroView desc={desc} setView={this.setView} />}
{this.state.view === 'stage' &&
<StageView setView={this.setView}
updateSuccess={this.updateSuccess}
updateHistory={this.updateHistory}
/>}
{this.state.view === 'end' && <EndView
successTotal={this.state.successTotal}
history={this.state.history}
setView={this.setView}
resetProgress={this.resetProgress}
/>}
</div>
);

}
}
7 changes: 7 additions & 0 deletions frontend/src/chooseAdventure/chooseAdventure.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.intro_desc{

}

.cyoa-button{
position: center;
}
40 changes: 40 additions & 0 deletions frontend/src/chooseAdventure/endView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import * as PropTypes from 'prop-types';

/**
* Component for displaying choose your own adventure skeleton
*/

class EndView extends React.Component {
constructor(props) {
super(props);
}

resetAdventure = () => {
this.props.setView('stage');
this.props.resetProgress();
};

render() {
const choices = this.props.history.map((option, k) => (
<p key={k}>Choosing {option.text} increased success by {option.successFactor}</p>
));
return (
<div>
<div>Your success total was {this.props.successTotal}</div>
{choices}
<button onClick={() => this.resetAdventure()}>Try again</button>
</div>
);
}
}

EndView.propTypes = {
setView: PropTypes.func,
history: PropTypes.array,
successTotal: PropTypes.number,
resetProgress: PropTypes.func,
};


export default EndView;
44 changes: 44 additions & 0 deletions frontend/src/chooseAdventure/introView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import * as PropTypes from "prop-types";


/**
* Component for displaying choose your own adventure skeleton
*/

class IntroView extends React.Component {
constructor(props) {
super(props);
}

render() {
return (
<div>
<div className='row'>
<div className={'col-6'}>
{this.props.desc}
</div>
<img className= 'col-6' src='/static/img/sample.jpg' alt="Sample" />

</div>

<button className='col-5 cyoa-button' onClick={() => this.props.setView('stage')}>
Get started
</button>
</div>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know this is just mvp / prototyping code but whoa there unnecessary whitespace





);

}
}

IntroView.propTypes = {
desc: PropTypes.string,
setView: PropTypes.func,
};

export default IntroView;
130 changes: 130 additions & 0 deletions frontend/src/chooseAdventure/stageView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React from 'react';
import * as PropTypes from 'prop-types';

// TODO: hardcode data structure here, add a reference with dictionary

const START_STAGE = {
'text': 'Your school district\'s budget was cut!',
'options': [{
'text': 'Start a media campaign',
'stageName': 'MEDIA_STAGE',
'successFactor': 20,
},
{
'text': 'Take direct action',
'stageName': 'DIRECT_STAGE',
'successFactor': 10,
}],
};

const MEDIA_STAGE = {
'text': 'You chose to start a media campaign.',
'options': [{
'text': 'Twitter',
'stageName': null,
'successFactor': 420,
},
{
'text': 'Facebook',
'stageName': null,
'successFactor': 0,
},
{
'text': 'Radio',
'stageName': null,
'successFactor': 30,
}],
};

const DIRECT_STAGE = {
'text': 'You chose to take direct action against the school.',
'options': [{
'text': 'Sue the principal',
'stageName': null,
'successFactor': 10,
},
{
'text': 'Ask the principal nicely',
'stageName': null,
'successFactor': 5,
}],
};

const NAME_TO_STAGE = {
'START_STAGE' : START_STAGE,
'MEDIA_STAGE' : MEDIA_STAGE,
'DIRECT_STAGE' : DIRECT_STAGE
};

const getStageFromName = (stageName) => {
return NAME_TO_STAGE[stageName];
};

class Option extends React.Component {
constructor(props) {
super(props);
}

render() {
let stage = getStageFromName(this.props.option.stageName);
let option = this.props.option;
return (
<button
onClick={() =>
this.props.setStage(stage, option)}
>{this.props.option.text}</button>
);
}
}
Option.propTypes = {
option: PropTypes.object,
setStage: PropTypes.func,
};

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work with this wrapper component!

* Component for displaying choose your own adventure skeleton
*/

class StageView extends React.Component {
constructor(props) {
super(props);
this.state = {
stage: getStageFromName("START_STAGE"),
};
}

setStage = (stage, option) => {
this.props.updateHistory(option);
this.props.updateSuccess(option.successFactor);
if (option.stageName) {
this.setState({stage: getStageFromName(option.stageName)});
} else {
this.props.setView('end');
}
this.setState({ stage: stage });
};

render() {
let optionComponents = <div>Loading...</div>;
if (this.state.stage.options) {
optionComponents = this.state.stage.options.map((option, k) =>
<Option key={k} option={option}
setStage={this.setStage}
/>);
}
return (
<div className={"wrapper"}>
<p>{this.state.stage.text}</p>
{optionComponents}
</div>
);
}
}
StageView.propTypes = {
stageName: PropTypes.string,
updateHistory: PropTypes.func,
setView: PropTypes.func,
updateSuccess: PropTypes.func,
};

export default StageView;