Skip to content
This repository has been archived by the owner on Sep 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
redid add/edit actions to single lines and the reducer to contain the…
… api calls (again) due to wierd undefined parameters.
  • Loading branch information
Eric Helin committed Apr 1, 2019
1 parent 84a68d0 commit dd04da2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 64 deletions.
@@ -1,7 +1,7 @@
import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { actionCreators } from '../../store/userInterface/BucketListItem'; // TODO -> add
import { actionCreators } from '../../store/userInterface/BucketListItem';
import Button from './Button';
var utilsRef = require('../../common/Utilities');

Expand Down
47 changes: 18 additions & 29 deletions TgimbaNetCoreWebReactJs/ClientApp/src/store/Add.js
Expand Up @@ -15,30 +15,29 @@ const initialState = {
};

export const actionCreators = {
add: (
name,
dateCreated,
bucketListItemType,
completed,
latitude,
longitude
) => async (dispatch, getState) => {
add: (name, dateCreated, bucketListItemType, completed, latitude, longitude) => ({ type: ACTION_TYPE_ADD_TO_SERVER, name, dateCreated, bucketListItemType, completed, latitude, longitude }),
};

export const reducer = (state, action) => {
state = state || initialState;

if (action.type == ACTION_TYPE_ADD_TO_SERVER) {
var constants = Object.create(constantsRef.Constants);
var session = Object.create(sessionRef.Session);

var utils = Object.create(utilsRef.Utilities);
var host = utils.GetHost();

var userName = session.SessionGet(constants.SESSION_USERNAME);
var completed = completed === true ? 'true' : 'false';
var completed = action.completed === true ? 'true' : 'false';

const url = host + '/BucketListItem/AddBucketListItem'
+ '?Name=' + name
+ '&DateCreated=' + dateCreated
+ '&BucketListItemType=' + bucketListItemType
+ '?Name=' + action.name
+ '&DateCreated=' + action.dateCreated
+ '&BucketListItemType=' + action.bucketListItemType
+ '&Completed=' + completed
+ '&Latitude=' + latitude
+ '&Longitude=' + longitude
+ '&Latitude=' + action.latitude
+ '&Longitude=' + action.longitude
+ '&DatabaseId=' + ''
+ '&UserName=' + userName
+ '&encodedUser=' + btoa(userName)
Expand All @@ -50,27 +49,17 @@ export const actionCreators = {
if (data && data.currentTarget
&& data.currentTarget && data.currentTarget.response
&& data.currentTarget.response.length > 0
&& data.currentTarget.response === 'true') {
dispatch
({
type: ACTION_TYPE_ADD_TO_SERVER
});
&& data.currentTarget.response === 'true')
{
var utils = Object.create(utilsRef.Utilities);
var host = utils.GetHost();
window.location = host + '/main';
} else {
alert('Add failed');
}
};
xhr.send();
}
};

export const reducer = (state, action) => {
state = state || initialState;

if (action.type == ACTION_TYPE_ADD_TO_SERVER) {
var utils = Object.create(utilsRef.Utilities);
var host = utils.GetHost();
window.location = host + '/main';
}

return state;
};
56 changes: 22 additions & 34 deletions TgimbaNetCoreWebReactJs/ClientApp/src/store/Edit.js
Expand Up @@ -17,33 +17,30 @@ const initialState = {
};

export const actionCreators = {
edit: (
name,
dateCreated,
bucketListItemType,
completed,
latitude,
longitude,
databaseId,
userName
) => async (dispatch, getState) => {
edit: (name, dateCreated, bucketListItemType, completed, latitude, longitude, databaseId, userName) => ({ type: ACTION_TYPE_EDIT_TO_SERVER, name, dateCreated, bucketListItemType, completed, latitude, longitude, databaseId, userName }),
};

export const reducer = (state, action) => {
state = state || initialState;

if (action.type == ACTION_TYPE_EDIT_TO_SERVER) {
var constants = Object.create(constantsRef.Constants);
var session = Object.create(sessionRef.Session);

var utils = Object.create(utilsRef.Utilities);
var host = utils.GetHost();

var userName = session.SessionGet(constants.SESSION_USERNAME);
var completed = completed === true ? 'true' : 'false';
var completed = action.completed === true ? 'true' : 'false';

const url = host + '/BucketListItem/EditBucketListItem'
+ '?Name=' + name
+ '&DateCreated=' + dateCreated
+ '&BucketListItemType=' + bucketListItemType
+ '?Name=' + action.name
+ '&DateCreated=' + action.dateCreated
+ '&BucketListItemType=' + action.bucketListItemType
+ '&Completed=' + completed
+ '&Latitude=' + latitude
+ '&Longitude=' + longitude
+ '&DatabaseId=' + databaseId
+ '&Latitude=' + action.latitude
+ '&Longitude=' + action.longitude
+ '&DatabaseId=' + action.databaseId
+ '&UserName=' + userName
+ '&encodedUser=' + btoa(userName)
+ '&encodedToken=' + btoa(session.SessionGet(constants.SESSION_TOKEN));
Expand All @@ -54,27 +51,18 @@ export const actionCreators = {
if (data && data.currentTarget
&& data.currentTarget && data.currentTarget.response
&& data.currentTarget.response.length > 0
&& data.currentTarget.response === 'true') {
dispatch
({
type: ACTION_TYPE_EDIT_TO_SERVER
});
&& data.currentTarget.response === 'true')
{
var utils = Object.create(utilsRef.Utilities);
var host = utils.GetHost();
window.location = host + '/main';

} else {
alert('Add failed');
alert('Edit failed');
}
};
xhr.send();
}
};

export const reducer = (state, action) => {
state = state || initialState;

if (action.type == ACTION_TYPE_EDIT_TO_SERVER) {
var utils = Object.create(utilsRef.Utilities);
var host = utils.GetHost();
window.location = host + '/main';
}
}

return state;
};

0 comments on commit dd04da2

Please sign in to comment.