diff --git a/scripts/start.js b/scripts/start.js index 90ffd0910dc765ccaeb3393b06811be22cc740a0..c7e84267c6fb24fc98fe57ca1764fc727993fc09 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -26,7 +26,7 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { } // Tools like Cloud9 rely on this. -var DEFAULT_PORT = process.env.PORT || 5305; +var DEFAULT_PORT = process.env.PORT || 5501; var compiler; var handleCompile; diff --git a/src/components/BuildingListTable/index.js b/src/components/BuildingListTable/index.js index 1693664dde4ebbc9e56da8754746dd3840f82f87..45ca7cea53cad9310755aa20db14591d05dec663 100644 --- a/src/components/BuildingListTable/index.js +++ b/src/components/BuildingListTable/index.js @@ -19,7 +19,7 @@ export default function BuildingListTable({ buildings }) { React router Link component does not support relative paths */}
Loading...
; + } else if (hit.error.message && hit.error.response.status !== 404) { + return{hit.error.message}
; + } + if (!hit.error.message && hit.status !== '') { + let fileActions = ; + + if (hit.status === 'Reviewable') { + fileActions = ( +HIT Id: {hit.id}
-HIT Status: {hit.status}
+ HIT Status: {hit.status} + {fileActions}{hit.error.message}
-{hit.create.error.message}
; } return (Coming Soon!
; +} diff --git a/src/containers/BuildingDetail/actions.js b/src/containers/BuildingDetail/actions.js deleted file mode 100644 index 5a574bc8f5cd81edbebe19a771f6a5b0d4539a91..0000000000000000000000000000000000000000 --- a/src/containers/BuildingDetail/actions.js +++ /dev/null @@ -1,93 +0,0 @@ -import 'whatwg-fetch'; -import { - LOAD_BUILDING_DETAIL, - LOAD_BUILDING_DETAIL_SUCCEES, - LOAD_BUILDING_DETAIL_ERROR, - CREATE_HIT, - CREATE_HIT_SUCCEES, - CREATE_HIT_ERROR, -} from './constants'; - -/** - * Load building details, this action starts the request saga - * - * @param buildingID The current buildingID - * @returns {object} An action object with a type of LOAD_BUILDING_DETAIL - * passing the building detail - */ -export function loadBuildingDetail(buildingID) { - return { - type: LOAD_BUILDING_DETAIL, - payload: buildingID, - }; -} - -/** - * Dispatched when the building details are loaded by the request saga - * - * @param {object} buildingDetail The building data - * @returns {object} An action object with a type of - * LOAD_BUILDING_DETAIL_SUCCEES - */ -export function buildingDetailLoaded(buildingDetail) { - return { - type: LOAD_BUILDING_DETAIL_SUCCEES, - payload: buildingDetail, - }; -} - -/** - * Dispatched when loading the building detail fails - * - * @param {object} error The error - * - * @return {object} An action object with a type of - * LOAD_BUILDING_DETAIL_ERROR passing the error - */ -export function buildingDetailLoadingError(error) { - return { - type: LOAD_BUILDING_DETAIL_ERROR, - error, - }; -} - -/** - * Create mturk HIT, this action starts the request saga - * - * @param {object} formData The mturk form data - * @returns {object} An action object with a type of CREATE_HIT - */ -export function createHit(formData) { - return { - type: CREATE_HIT, - payload: formData, - }; -} - -/** - * Dispatched when the mturk HIT was successfully created - * - * @param {object} hitData The created hit data - * @returns {object} An action object with a type of CREATE_HIT_SUCCEES - */ -export function createHitSuccess(hitData) { - return { - type: CREATE_HIT_SUCCEES, - payload: hitData, - }; -} - -/** - * Dispatched when creating the mturk HIT fails - * - * @param {object} error The error - * - * @return {object} An action object with a type of CREATE_HIT_ERROR - * passing the error - */ -export function createHitError(error) { - return { - type: CREATE_HIT_ERROR, - error, - }; -} diff --git a/src/containers/BuildingDetail/constants.js b/src/containers/BuildingDetail/constants.js deleted file mode 100644 index 873b9080d77454308cb96f389e1c36077d58b7c8..0000000000000000000000000000000000000000 --- a/src/containers/BuildingDetail/constants.js +++ /dev/null @@ -1,6 +0,0 @@ -export const LOAD_BUILDING_DETAIL = 'LOAD_BUILDING_DETAIL'; -export const LOAD_BUILDING_DETAIL_SUCCEES = 'LOAD_BUILDING_DETAIL_SUCCEES'; -export const LOAD_BUILDING_DETAIL_ERROR = 'LOAD_BUILDING_DETAIL_ERROR'; -export const CREATE_HIT = 'CREATE_HIT'; -export const CREATE_HIT_SUCCEES = 'CREATE_HIT_SUCCEES'; -export const CREATE_HIT_ERROR = 'CREATE_HIT_ERROR'; diff --git a/src/containers/BuildingDetail/reducer.js b/src/containers/BuildingDetail/reducer.js deleted file mode 100644 index 457c6ed739417d42b920af95be052ddff1bdb7b4..0000000000000000000000000000000000000000 --- a/src/containers/BuildingDetail/reducer.js +++ /dev/null @@ -1,89 +0,0 @@ -import { - LOAD_BUILDING_DETAIL, - LOAD_BUILDING_DETAIL_SUCCEES, - LOAD_BUILDING_DETAIL_ERROR, - CREATE_HIT, - CREATE_HIT_SUCCEES, - CREATE_HIT_ERROR, -} from './constants'; - -const initState = { - overview: { - loading: false, - error: false, - }, - hit: { - id: '', - status: '', - loading: false, - error: false, - }, -}; - -export default function (state = initState, action) { - switch (action.type) { - case LOAD_BUILDING_DETAIL: - return { - ...state, - overview: { - ...state.overview, - loading: true, - error: false, - }, - }; - - case LOAD_BUILDING_DETAIL_SUCCEES: - return { - ...state, - overview: { - ...state.overview, - ...action.payload.data, - loading: false, - }, - }; - - case LOAD_BUILDING_DETAIL_ERROR: - return { - ...state, - overview: { - ...state.overview, - loading: true, - error: action.error, - }, - }; - - case CREATE_HIT: - return { - ...state, - hit: { - ...state.hit, - loading: true, - error: false, - }, - }; - - case CREATE_HIT_SUCCEES: - return { - ...state, - hit: { - ...state.hit, - id: action.payload.data.hit_id, - status: 'Submitted', - loading: false, - }, - }; - - case CREATE_HIT_ERROR: - return { - ...state, - hit: { - ...state.hit, - loading: false, - error: action.error, - }, - }; - - default: - return state; - } -} diff --git a/src/containers/BuildingList/index.js b/src/containers/BuildingList/index.js index f7a5355b7d65c3a7d284c42cbe319506759251a0..4b7040723473b3149c406344f3fe9daefba447d8 100644 --- a/src/containers/BuildingList/index.js +++ b/src/containers/BuildingList/index.js @@ -7,14 +7,12 @@ import BuildingListTable from '../../components/BuildingListTable'; import './styles.scss'; import { SearchSVG } from '../../components/bpl'; -// TODO remove this address -const INITIAL_TERM = '107 broadway'; class BuildingList extends Component { constructor(props) { super(props); - this.state = { term: INITIAL_TERM }; + this.state = { term: this.props.buildingList.term }; this.onInputChange = this.onInputChange.bind(this); this.onFormSubmit = this.onFormSubmit.bind(this); } diff --git a/src/containers/BuildingList/reducer.js b/src/containers/BuildingList/reducer.js index 13acd7e523fec1da413e9c3b9d1c88e9f2602256..230de775b591aac379e702e7251a310a5061a310 100644 --- a/src/containers/BuildingList/reducer.js +++ b/src/containers/BuildingList/reducer.js @@ -1,6 +1,11 @@ import { FETCH_BUILDINGS, SEARCH_TERM } from './constants'; -export default function (state = {}, action) { +// TODO remove hard coded search term +const initState = { + term: '107 broadway', +}; + +export default function (state = initState, action) { switch (action.type) { case FETCH_BUILDINGS: return { ...state, buildings: action.payload.buildings }; diff --git a/src/containers/BuildingOverview/actions.js b/src/containers/BuildingOverview/actions.js new file mode 100644 index 0000000000000000000000000000000000000000..28840a22deeefdc87f5416101a489c6958eb0824 --- /dev/null +++ b/src/containers/BuildingOverview/actions.js @@ -0,0 +1,182 @@ +import 'whatwg-fetch'; +import { + LOAD_BUILDING_DETAIL, + LOAD_BUILDING_DETAIL_SUCCEES, + LOAD_BUILDING_DETAIL_ERROR, + LOAD_HIT, + LOAD_HIT_SUCCESS, + LOAD_HIT_ERROR, + CREATE_HIT, + CREATE_HIT_SUCCESS, + CREATE_HIT_ERROR, + DECIDE_HIT, + DECIDE_HIT_SUCCESS, + DECIDE_HIT_ERROR, +} from './constants'; + +/** + * Load building details, this action starts the request saga + * + * @param buildingID The current buildingID + * @returns {object} An action object with a type of LOAD_BUILDING_DETAIL + * passing the building detail + */ +export function loadBuildingDetail(buildingID) { + return { + type: LOAD_BUILDING_DETAIL, + payload: buildingID, + }; +} + +/** + * Dispatched when the building details are loaded by the request saga + * + * @param {object} buildingDetail The building data + * @returns {object} An action object with a type of + * LOAD_BUILDING_DETAIL_SUCCEES + */ +export function buildingDetailLoaded(buildingDetail) { + return { + type: LOAD_BUILDING_DETAIL_SUCCEES, + payload: buildingDetail, + }; +} + +/** + * Dispatched when loading the building detail fails + * + * @param {object} error The error + * @return {object} An action object with a type of + * LOAD_BUILDING_DETAIL_ERROR passing the error + */ +export function buildingDetailLoadingError(error) { + return { + type: LOAD_BUILDING_DETAIL_ERROR, + error, + }; +} + +/** + * Load status of HIT + * TODO The HIT status should be loaded from the building detail route + * + * @param {string} buildingId The current buildingID + * @returns {object} An action object with a type of + * LOAD_HIT passing the building_id + */ +export function loadHit(buildingId) { + return { + type: LOAD_HIT, + payload: buildingId, + }; +} + +/** + * Dispatched when the hit status was successfully loaded + * + * @param {string} hitStatus The HIT status + * @returns {object} An action object with a type of + * LOAD_HIT_SUCCESS passing the hit status + */ +export function hitLoaded(hitStatus) { + return { + type: LOAD_HIT_SUCCESS, + payload: hitStatus, + }; +} + +/** + * Dispatched when loading the hit status fails + * + * @param {object} error The error + * @returns {object} An action object with a type of + * LOAD_HIT passing the hit status + */ +export function hitLoadingError(error) { + return { + type: LOAD_HIT_ERROR, + error, + }; +} + +/** + * Create mturk HIT, this action starts the request saga + * + * @param {object} formData The mturk form data + * @returns {object} An action object with a type of CREATE_HIT + */ +export function createHit(formData) { + return { + type: CREATE_HIT, + payload: formData, + }; +} + +/** + * Dispatched when the mturk HIT was successfully created + * + * @param {object} hitData The created hit data + * @returns {object} An action object with a type of CREATE_HIT_SUCCESS + */ +export function createHitSuccess(hitData) { + return { + type: CREATE_HIT_SUCCESS, + payload: hitData, + }; +} + +/** + * Dispatched when creating the mturk HIT fails + * + * @param {object} error The error + * @return {object} An action object with a type of CREATE_HIT_ERROR + * passing the error + */ +export function createHitError(error) { + return { + type: CREATE_HIT_ERROR, + error, + }; +} + +/** + * Dispatched when user selects approve or reject HIT + * + * @param {int} buildingId Id of building + * @param {int} decision 1 or 0 representing approve or reject + * @returns {object} An action object with a type of DECIDE_HIT + * passing the decision of the user + */ +export function hitDecision(buildingId, decision) { + return { + type: DECIDE_HIT, + buildingId, + decision, + }; +} + +/** + * Dispatched when the hit was successfully approved or disapproved + * + * @returns {object} + */ +export function hitDecisionSuccess(data) { + return { + type: DECIDE_HIT_SUCCESS, + payload: data, + }; +} + +/** + * Dispatched when there is a error approving or rejecting a HIT + * + * @param error The error + * @returns {object} An action object with a type of DECIDE_HIT_ERROR + * passing the error + */ +export function hitDecisionError(error) { + return { + type: DECIDE_HIT_ERROR, + error, + }; +} diff --git a/src/containers/BuildingOverview/constants.js b/src/containers/BuildingOverview/constants.js new file mode 100644 index 0000000000000000000000000000000000000000..4ed5fd68462fab08fa820f6f60430820d4a0c1e7 --- /dev/null +++ b/src/containers/BuildingOverview/constants.js @@ -0,0 +1,12 @@ +export const LOAD_BUILDING_DETAIL = 'LOAD_BUILDING_DETAIL'; +export const LOAD_BUILDING_DETAIL_SUCCEES = 'LOAD_BUILDING_DETAIL_SUCCEES'; +export const LOAD_BUILDING_DETAIL_ERROR = 'LOAD_BUILDING_DETAIL_ERROR'; +export const LOAD_HIT = 'LOAD_HIT'; +export const LOAD_HIT_SUCCESS = 'LOAD_HIT_SUCCESS'; +export const LOAD_HIT_ERROR = 'LOAD_HIT_ERROR'; +export const CREATE_HIT = 'CREATE_HIT'; +export const CREATE_HIT_SUCCESS = 'CREATE_HIT_SUCCESS'; +export const CREATE_HIT_ERROR = 'CREATE_HIT_ERROR'; +export const DECIDE_HIT = 'DECIDE_HIT'; +export const DECIDE_HIT_SUCCESS = 'DECIDE_HIT_SUCCESS'; +export const DECIDE_HIT_ERROR = 'DECIDE_HIT_ERROR'; diff --git a/src/containers/BuildingDetail/index.js b/src/containers/BuildingOverview/index.js similarity index 66% rename from src/containers/BuildingDetail/index.js rename to src/containers/BuildingOverview/index.js index 01b3490952add4c69cd8fbde5720b87d16fb2e38..c813797f51b75ef17911e9852cbb624cdcd59ce9 100644 --- a/src/containers/BuildingDetail/index.js +++ b/src/containers/BuildingOverview/index.js @@ -2,15 +2,22 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import { loadBuildingDetail, createHit } from './actions'; +import { + loadBuildingDetail, + loadHit, + createHit, + hitDecision, +} from './actions'; + import './styles.scss'; -import SideBarDetail from '../../components/SideBarDetail'; +import BuildingOverviewTop from '../../components/BuildingOverviewTop'; import TurkHit from '../../components/TurkHit'; -class BuildingDetail extends Component { +class BuildingOverview extends Component { componentDidMount() { this.props.loadBuildingDetail(this.props.params.buildingID); + this.props.loadHit(this.props.params.buildingID); } render() { @@ -24,14 +31,17 @@ class BuildingDetail extends Component { ); } else { - mainContent = React.cloneElement(this.props.children, { - building: this.props.buildingDetail.overview, - }); + mainContent = ( +