-
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
13 changed files
with
395 additions
and
47 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 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,22 @@ | ||
import axios from "axios"; | ||
import { DELETE_ARTICLE_SUCCESS } from "./types"; | ||
|
||
export const getArticleAction = slug => dispatch => { | ||
return axios({ | ||
url: | ||
"https://ah-backend-prime-staging.herokuapp.com/api/v1/articles/" + slug, | ||
method: "delete", | ||
headers: { | ||
Authorization: `Bearer ${sessionStorage.getItem("token")}` | ||
} | ||
}).then(response => { | ||
dispatch(deleteArticleSuccess(response.data)); | ||
}); | ||
}; | ||
|
||
const deleteArticleSuccess = payload => { | ||
return { | ||
type: DELETE_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
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,235 @@ | ||
import React, { Component } from "react"; | ||
import { connect } from "react-redux"; | ||
import "../../styles/app.scss"; | ||
import { articleCreateEditAction } from "../../actions/articleCreateEditAction"; | ||
import { getArticleAction } from "../../actions/getArticle"; | ||
import CreateArticleComponent from "./createArticleComponent"; | ||
import firebase from "../../firebase/config"; | ||
import { TextArea } from "semantic-ui-react"; | ||
|
||
export class EditArticlePage 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); | ||
} | ||
componentWillMount() { | ||
this.props.getArticleAction(this.props.match.params.slug); | ||
} | ||
|
||
componentWillReceiveProps(newP) { | ||
// const { article } = newP.props; | ||
if (newP) { | ||
this.setState({ | ||
title: newP.article.article.title, | ||
description: newP.article.article.description, | ||
body: newP.article.article.body, | ||
image: newP.article.article.image, | ||
tags: newP.article.tagList, | ||
article: newP.article.article | ||
}); | ||
} | ||
// console.log("article ", this.state.title); | ||
} | ||
|
||
/* istanbul ignore next */ | ||
onUpload(files) { | ||
const image1 = URL.createObjectURL(event.target.files[0]); | ||
this.setState({ image1 }); | ||
|
||
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 => { | ||
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 ? tags.split(",") : "", | ||
image: image | ||
}; | ||
const url = | ||
"https://ah-backend-prime-staging.herokuapp.com/api/v1/articles/" + | ||
this.props.match.params.slug + | ||
"/"; | ||
console.log("this is the url", url); | ||
this.props.articleCreateEditAction(messageObject, url, "put", this.props); | ||
} | ||
|
||
render() { | ||
const { image, article } = this.state; | ||
console.log("the body", this.state.body); | ||
|
||
return ( | ||
<div> | ||
{/* <CreateArticleComponent | ||
onChange={this.onChange} | ||
onUpload={this.onUpload} | ||
onSubmit={this.onSubmit} | ||
image={image} | ||
article={article ? article : null} | ||
/> */} | ||
<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={this.onChange} | ||
className="form-control" | ||
placeholder="title" | ||
name="title" | ||
id="title" | ||
defaultValue={article ? article.title : ""} | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<input | ||
onChange={e => this.onChange(e)} | ||
className="form-control" | ||
placeholder="description" | ||
name="description" | ||
id="description" | ||
defaultValue={article ? article.description : ""} | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
{/* <div | ||
className="fixedTextArea" | ||
contentEditable | ||
id="body" | ||
suppressContentEditableWarning | ||
onChange={e => this.onChange(e)} | ||
> | ||
{article ? article.body : ""} | ||
</div> */} | ||
|
||
<textarea | ||
onChange={e => this.onChange(e)} | ||
className="form-control" | ||
placeholder="Body" | ||
name="body" | ||
id="body" | ||
// readOnly="true" | ||
value={article ? article.body : ""} | ||
/> | ||
{/* <input | ||
onChange={e => this.onChange(e)} | ||
className="form-control text-area" | ||
placeholder="Body" | ||
name="body" | ||
id="body" | ||
// readOnly="true" | ||
defaultValue={article ? article.body : ""} | ||
/> */} | ||
|
||
{/* <div | ||
className="form-control, " | ||
id="body" | ||
name="body" | ||
contentEditable | ||
suppressContentEditableWarning | ||
> | ||
{article ? article.body : ""} | ||
</div> */} | ||
</div> | ||
<div className="form-group"> | ||
<input | ||
onChange={e => this.onChange(e)} | ||
className="form-control" | ||
placeholder="tags" | ||
name="tags" | ||
id="tags" | ||
defaultValue={ | ||
article | ||
? article.tagList | ||
? article.tagList.join(",") | ||
: "" | ||
: "" | ||
} | ||
/> | ||
<div> | ||
<i>Separate your tags with a comma</i> | ||
</div> | ||
</div> | ||
<div className="image-div"> | ||
<div className="actual-image"> | ||
<img | ||
src={image ? image : article ? article.image : " "} | ||
className="image-fluid" | ||
/> | ||
</div> | ||
<input | ||
type="file" | ||
name="imageUpload" | ||
onChange={e => this.onUpload(event.target.files)} | ||
id="fitz" | ||
/> | ||
</div> | ||
|
||
<div className="form-group"> | ||
<button | ||
onClick={e => this.onSubmit(e)} | ||
className="btn btn-primary" | ||
> | ||
Publish Story | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
<div className="col col-lg-3" /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export const mapStateToProps = state => ({ | ||
article: state.getArticleReducer.article | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
{ getArticleAction, articleCreateEditAction } | ||
)(EditArticlePage); | ||
|
||
// export default connect( | ||
// null, | ||
// { getArticleAction, articleCreateEditAction } | ||
// )(); |
Oops, something went wrong.