Skip to content

Commit

Permalink
Alerts for Errors (ubclaunchpad#68)
Browse files Browse the repository at this point in the history
* Initialized Alert.js, reducer and action.

* Added alerts to saga functions and onto signup.

* Fixed error.

* Added alerts to signup and login.

* Added alerts to profile.js

* Fixed alerts appearing between login and signup.

* Added alert to editprofile.

* Added alerts onto newStep and recipe.

* Edits to editprofile and profile.

* Added alerts and dispatches between screens.

* Delete package-lock.json

Co-authored-by: Hao (Harin) Wu <[email protected]>
aaronchan73 and Harin329 authored Apr 3, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent bf396f0 commit 669cfa7
Showing 24 changed files with 422 additions and 8,199 deletions.
4 changes: 2 additions & 2 deletions frontend/ios/umami.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -590,7 +590,7 @@
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
@@ -656,7 +656,7 @@
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
1 change: 1 addition & 0 deletions frontend/src/actions/globalActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Redux
export const SET_ONBOARDING = 'SET_ONBOARDING';
export const SET_LOADING = 'SET_LOADING';
export const SET_ALERT = 'SET_ALERT';

// Saga
10 changes: 10 additions & 0 deletions frontend/src/components/Alerts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Alert } from 'react-native';

export default function Alerts(alertVisible, text) {

return alertVisible ? Alert.alert(
"Error",
text
) : null;

}
13 changes: 12 additions & 1 deletion frontend/src/redux/globalReducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {combineReducers} from 'redux';
import {SET_LOADING, SET_ONBOARDING} from '../actions/globalActions';
import {SET_LOADING, SET_ONBOARDING, SET_ALERT} from '../actions/globalActions';

const defaultOnboardState = true;
const defaultLoadingState = false;
const defaultAlertState = false;

const onboardReducer = (state = defaultOnboardState, action) => {
switch (action.type) {
@@ -22,7 +23,17 @@ const loadingReducer = (state = defaultLoadingState, action) => {
}
};

const alertReducer = (state = defaultAlertState, action) => {
switch(action.type) {
case SET_ALERT:
return action.alert;
default:
return state;
}
};

export default combineReducers({
onboardReducer,
loadingReducer,
alertReducer,
});
22 changes: 19 additions & 3 deletions frontend/src/saga/accountSaga.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {takeLatest, call, put} from 'redux-saga/effects';
import { takeLatest, call, put } from 'redux-saga/effects';
import axios from 'axios';
import {API_URL} from '@env';
import { API_URL } from '@env';
import {
GET_USER,
POST_USER,
PUT_USER,
USER_INFO,
POST_USER_TOKEN,
} from '../actions/accountActions';
import { SET_ALERT } from '../actions/globalActions';

function* signUpCall(param) {
try {
@@ -49,6 +50,10 @@ function* signUpCall(param) {
});
} catch (e) {
console.log('Signup Failed');
yield put({
type: SET_ALERT,
alert: true
});
}
}

@@ -74,6 +79,10 @@ function* updateUserCall(param) {
});
} catch (e) {
console.log('Update User Failed');
yield put({
type: SET_ALERT,
alert: true
});
}
}

@@ -109,9 +118,12 @@ function* getUserCall(param) {
style: results[0][15],
experience: results[0][16],
};
yield put({type: USER_INFO, payload: userObj});
} catch (e) {
console.log('Get User Failed');
yield put({
type: SET_ALERT,
alert: true
});
}
}

@@ -130,6 +142,10 @@ function* registerUserTokenCall(param) {
} catch (e) {
console.log(e);
console.log('User token registeration failed');
yield put({
type: SET_ALERT,
alert: true
});
}
}

14 changes: 13 additions & 1 deletion frontend/src/saga/feedSaga.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import {
SEARCH_FEED,
SEARCH_RESULT,
} from '../actions/feedActions';
import {SET_LOADING} from '../actions/globalActions';
import {SET_LOADING, SET_ALERT} from '../actions/globalActions';

function* searchFeedCall(param) {
try {
@@ -84,6 +84,10 @@ function* searchFeedCall(param) {
yield put({type: SEARCH_RESULT, payload: recipeArray});
} catch (e) {
console.log('Get Feed Failed');
yield put({
type: SET_ALERT,
alert: true
});
}
}

@@ -175,6 +179,10 @@ function* getFeedCall(param) {
yield put({type: (param.startIndex === 0) ? REPLACE_FEED : FORYOU_FEED, payload: recipeArray});
} catch (e) {
console.log('Get Feed Failed: ' + e);
yield put({
type: SET_ALERT,
alert: true
});
}
}

@@ -250,6 +258,10 @@ function* getFeaturedCall(param) {
yield put({type: FEATURED_FEED, payload: recipeArray});
} catch (e) {
console.log('Get Featured Feed Failed: ' + e);
yield put({
type: SET_ALERT,
alert: true
});
}
}

Loading

0 comments on commit 669cfa7

Please sign in to comment.