Skip to content

Commit

Permalink
added Profile icon for profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
biagioo committed Sep 2, 2020
1 parent 1324b12 commit 50371a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 39 deletions.
Binary file added assets/Profile icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions helpers/BaseUrl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const BASEURL = 'https://flatiron-cheat-sheet.herokuapp.com/api/v1/';
// 'http://localhost:3000/api/v1/';
const BASEURL =
// 'https://flatiron-cheat-sheet.herokuapp.com/api/v1/';
'http://localhost:3000/api/v1/';
export default BASEURL;

// finish url with slash !!!
11 changes: 10 additions & 1 deletion reducers/authReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ export default (
tips: [...state.user.tips, payload],
},
};

case 'UPDATE_TIP':
return {
...state,
user: {
...state.user,
tips: state.user.tips.map((tip) =>
tip.id === payload.id ? payload : tip,
),
},
};
default:
return state;
}
Expand Down
50 changes: 14 additions & 36 deletions screens/TipModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,26 @@ import FloatLabelInput from '../helpers/FloatLabelInput';
import AppButton from '../helpers/AppButton';
import BASEURL from '../helpers/BaseUrl';
import { newTip } from '../actions/authActions';
import { CreateOrUpdateTip, UpdateUserTips } from '../actions/tipAction';
import { connect } from 'react-redux';

const TipModal = (props) => {

const { route, navigation, jwt } = props;
const { id, title: categoryTitle, color, tip } = route.params;
const { id, title: categoryTitle, color, tip } = props.route.params;

const [title, setTitle] = useState(tip?.title || '');
const [description, setDescription] = useState(tip?.description || '');
const [snippet, setSnippet] = useState(tip?.code_snippet || '');
const [moreInfo, setMoreInfo] = useState(tip?.more_info || '');

const handleSubmit = () => {
const configObject = {
method: tip ? 'PATCH' : 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify({
tip: {
title,
description,
code_snippet: snippet,
category_id: id || tip.category_id,
more_info: moreInfo,
},
}),
let tipObject = {
title,
description,
code_snippet: snippet,
category_id: id || tip.category_id,
more_info: moreInfo,
};
const url = BASEURL + (tip ? `tips/${tip.id}` : 'tips');
fetch(url, configObject)
.then((data) => data.json())
.then((json) => {
if (json.error) {
Alert.alert(json.message);
} else {
if (tip) {
navigation.navigate('Auth');
// TODO update the TIP
} else {
props.newTip(json.data);
navigation.navigate('Tips', { data: json.data, ...route.params });
}
}
});
props.CreateOrUpdateTip(props, tipObject);
};

const styles = StyleSheet.create({
Expand Down Expand Up @@ -95,4 +69,8 @@ const mapStateToProps = ({ authStore }) => ({
jwt: authStore.jwt,
});

export default connect(mapStateToProps, { newTip })(TipModal);
export default connect(mapStateToProps, {
newTip,
CreateOrUpdateTip,
UpdateUserTips,
})(TipModal);

0 comments on commit 50371a3

Please sign in to comment.