-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,139 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import axios from "axios"; | ||
import { ARTICLE_SUCCESS, ARTICLE_FAIL } from "./types"; | ||
import { toast } from "react-toastify"; | ||
|
||
export const successCreateArticle = data => { | ||
return { | ||
type: ARTICLE_SUCCESS, | ||
payload: data.article.slug | ||
}; | ||
}; | ||
|
||
export const articleCreateEditAction = (article, url, method, props) => { | ||
return async dispatch => { | ||
try { | ||
const response = await axios({ | ||
method: method, | ||
url: url, | ||
data: article, | ||
headers: { | ||
Authorization: `Bearer ${sessionStorage.getItem("token")}` | ||
} | ||
}); | ||
|
||
toast.dismiss(); | ||
dispatch(successCreateArticle(response.data)); | ||
props.history.push("/article/" + response.data.article.slug); | ||
} catch (error) { | ||
if (error.response) { | ||
dispatch({ | ||
type: ARTICLE_FAIL | ||
}); | ||
toast.dismiss(); | ||
const errors = error.response.data.errors; | ||
for (var key in errors) { | ||
toast.error(`${key}: ${errors[key]}`, { | ||
position: toast.POSITION.TOP_RIGHT, | ||
autoClose: false, | ||
hideProgressBar: false | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import axios from "axios"; | ||
import { FETCH_ARTICLE_SUCCESS } from "./types"; | ||
|
||
export const getArticleAction = slug => dispatch => { | ||
return axios | ||
.get( | ||
"https://ah-backend-prime-staging.herokuapp.com/api/v1/articles/" + slug | ||
) | ||
.then(response => { | ||
dispatch(fetchArticlesSuccess(response.data)); | ||
}); | ||
}; | ||
|
||
const fetchArticlesSuccess = payload => { | ||
return { | ||
type: FETCH_ARTICLE_SUCCESS, | ||
payload: payload | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import axios from "axios"; | ||
import { FETCH_ARTICLES_SUCCESS } from "./types"; | ||
|
||
export const getArticlesAction = () => dispatch => { | ||
export const getArticlesAction = (kwargs = " ") => dispatch => { | ||
return axios | ||
.get("https://my-json-server.typicode.com/patrickf949/demo/posts") | ||
.get( | ||
"https://ah-backend-prime-staging.herokuapp.com/api/v1/articles/" + kwargs | ||
) | ||
.then(response => { | ||
dispatch({ | ||
type: FETCH_ARTICLES_SUCCESS, | ||
payload: response.data | ||
}); | ||
dispatch(fetchArticlesSuccess(response.data.results)); | ||
}); | ||
}; | ||
|
||
const fetchArticlesSuccess = payload => { | ||
return { | ||
type: FETCH_ARTICLES_SUCCESS, | ||
payload: payload | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from "react"; | ||
import "../../styles/createArticles.scss"; | ||
import "../../styles/singleArticle.scss"; | ||
const CreateArticleComponent = props => { | ||
const { onChange, onSubmit, onUpload, image } = props; | ||
return ( | ||
<div className="container-fluid mt-5"> | ||
<div className="row"> | ||
<div className="col col-lg-3" /> | ||
<div className="col col-lg-6"> | ||
<h1>Tell A story</h1> | ||
<form> | ||
<div className="form-group"> | ||
<input | ||
onChange={onChange} | ||
className="form-control" | ||
placeholder="title" | ||
name="title" | ||
id="title" | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<input | ||
onChange={onChange} | ||
className="form-control" | ||
placeholder="description" | ||
name="description" | ||
id="description" | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<textarea | ||
onChange={onChange} | ||
className="form-control" | ||
placeholder="Body" | ||
name="body" | ||
id="body" | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<input | ||
onChange={onChange} | ||
className="form-control" | ||
placeholder="tags" | ||
name="tags" | ||
id="tags" | ||
/> | ||
<div> | ||
<i>Separate your tags with a comma</i> | ||
</div> | ||
</div> | ||
<div className="image-div"> | ||
<div className="actual-image"> | ||
<img src={image} className="image-fluid" /> | ||
</div> | ||
<input | ||
type="file" | ||
name="imageUpload" | ||
onChange={event => onUpload(event.target.files)} | ||
id="fitz" | ||
/> | ||
</div> | ||
|
||
<input name="image" /> | ||
<div className="form-group"> | ||
<button onClick={onSubmit} className="btn btn-primary"> | ||
Publish Story | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
<div className="col col-lg-3" /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CreateArticleComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React, { Component } from "react"; | ||
import { connect } from "react-redux"; | ||
import "../../styles/app.scss"; | ||
import { articleCreateEditAction } from "../../actions/articleCreateEditAction"; | ||
import CreateArticleComponent from "./createArticleComponent"; | ||
import firebase from "../../firebase/config"; | ||
|
||
export class CreateArticlePage extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
title: "", | ||
body: "", | ||
description: "", | ||
tags: "", | ||
image: "", | ||
isUploaded: false | ||
}; | ||
this.onChange = this.onChange.bind(this); | ||
this.onSubmit = this.onSubmit.bind(this); | ||
this.onUpload = this.onUpload.bind(this); | ||
} | ||
|
||
/* istanbul ignore next */ | ||
onUpload(files) { | ||
const image = URL.createObjectURL(event.target.files[0]); | ||
this.setState({ image }); | ||
|
||
const task = firebase | ||
.storage() | ||
.ref(`images/${files[0].name}`) | ||
.put(files[0]); | ||
|
||
task.then(res => { | ||
firebase | ||
.storage() | ||
.ref(`images/${files[0].name}`) | ||
.getDownloadURL() | ||
.then(url => { | ||
console.log(url); | ||
this.setState({ isUploaded: true, image: url }); | ||
}); | ||
}); | ||
|
||
task.on("state_changed", snapshot => { | ||
const isUploaded = true; | ||
this.setState({ isUploaded: isUploaded }); | ||
}); | ||
} | ||
|
||
onChange(e) { | ||
this.setState({ [e.target.name]: e.target.value }); | ||
} | ||
onSubmit(e) { | ||
e.preventDefault(); | ||
const { title, body, description, tags, image } = this.state; | ||
const messageObject = { | ||
title: title, | ||
body: body, | ||
description: description, | ||
tags: tags.split(","), | ||
image: image | ||
}; | ||
|
||
this.props.articleCreateEditAction( | ||
messageObject, | ||
"https://ah-backend-prime-staging.herokuapp.com/api/v1/articles/", | ||
"post", | ||
this.props | ||
); | ||
} | ||
|
||
render() { | ||
const { image } = this.state; | ||
return ( | ||
<div> | ||
<CreateArticleComponent | ||
onChange={this.onChange} | ||
onUpload={this.onUpload} | ||
onSubmit={this.onSubmit} | ||
image={image} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
null, | ||
{ articleCreateEditAction } | ||
)(CreateArticlePage); |
Oops, something went wrong.