Skip to content

Commit

Permalink
Blog feature and fixes (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Wu authored Jan 1, 2021
1 parent 154a98e commit 8e5aed8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ bower_containers
build/Release

# Dependency directories
node_modules/
node_modules
jspm_packages/
web/node_modules
back/node_modules
hub/node_modules

# Typescript v1 declaration files
typings/
Expand Down
12 changes: 7 additions & 5 deletions hub/src/containers/blog/Blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Blog extends Component {

componentDidMount = () => {
const { id } = this.props.match.params;
if (id) {
if (checkValue(id)) {
this.props.fetchBlogApi(id);
}

Expand All @@ -42,15 +42,17 @@ class Blog extends Component {
if (this.props.name !== props.name || this.props.name !== this.state.name) {
this.setState({ name: this.props.name });
}
if (this.props.content !== props.content || this.props.content !== this.state.content) {
if (checkValue(this.props.content) && (this.props.content !== props.content || this.props.content !== this.state.content)) {
this.setState({ content: this.props.content });
}
if (this.props.status !== props.status|| this.props.status !== this.state.status) {
if (this.props.status !== props.status) {
this.setState({ status: this.props.status });
}
};

handleTitle = (e) => this.setState({ [e.target.name]: e.target.value });
handleTitle = (e) => {
this.setState({ name: e.target.value });
}

handleChange = (e, { name, value }) => {
this.setState(
Expand All @@ -70,7 +72,7 @@ class Blog extends Component {

onSubmit = (e) => {
e.preventDefault();
if (this.props.match.params.id) {
if (checkValue(this.props.match.params.id)) {
this.setState({ _id: this.props.match.params.id}, () => this.props.saveBlogApi(this.state))
} else {
this.props.saveBlogApi(this.state);
Expand Down
15 changes: 11 additions & 4 deletions hub/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import moment from 'moment';
import moment from "moment";

export function formatDate(value) {
const readable = moment(value).format('Do MMMM YYYY');
const readable = moment(value).format("Do MMMM YYYY");
return readable;
}

export function checkValue(value) {
if (value !== '' && value !== undefined && value !== null) {
if (
value !== "" &&
value !== undefined &&
value !== null &&
value !== "null" &&
value !== "undefined"
) {
return true;
}
return false;
}

export const parseSize = (bytes) => parseFloat(Math.round(bytes/1024)).toFixed(2);
export const parseSize = (bytes) =>
parseFloat(Math.round(bytes / 1024)).toFixed(2);

0 comments on commit 8e5aed8

Please sign in to comment.