Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
artyomich committed Aug 27, 2019
1 parent 4e44c26 commit b34ee55
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@
/build

# misc
.idea
.DS_Store
.env.local
.env.development.local
Expand Down
12 changes: 12 additions & 0 deletions api/comments.xsl
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="posts">
<xsl:for-each select="post">
<xsl:value-of select="id" />
<xsl:value-of select="name" />
<xsl:value-of select="message" />
<xsl:value-of select="parent_id" />
<xsl:value-of select="time" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
10 changes: 9 additions & 1 deletion api/index.php
Expand Up @@ -81,24 +81,32 @@
'parent_id' => $parentId
];
saveComment($data + ['time' => $time, 'lastSessionId' => $currentSessionId], $xmlRoot, $fileXML);
//sortComments($xmlRoot);
jsonResponse(transform($data + ['time' => time()]), 201);
}

if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
$id = @$_DELETE['id'];

}
/**************************************
* Return list of Comments *
**************************************/
// Read xml and print the results:
$comments = [];
foreach ($xmlRoot->children() as $posts) {
foreach ($posts->children() as $post) {
$comments[] = $post;
}
}

//$comments = array_map('transform', $comments);

// Transform result
jsonResponse($comments);

/************************************** Helper functions *************************************/

/**
* Save a comment in xml
*
Expand All @@ -119,7 +127,7 @@ function saveComment($data, $xmlRoot, $file)
$post->addChild('id', strip_tags($data['id']));
$post->addChild('name', strip_tags($data['name']));
$post->addChild('message', strip_tags($data['message']));
$post->addChild('parent_id', strip_tags($data['parent_id']));
$post->addChild('parent_id', $data['parent_id']);
$post->addChild('time', strip_tags($data['time']));
}
// Bind and execute
Expand Down
68 changes: 47 additions & 21 deletions src/components/Comment.js
@@ -1,27 +1,53 @@
import React from "react";

/*constructor(props) {
this.onSubmit = this.onSubmit.bind(this);
}*/
/*
onSubmit(e) {
fetch("http://localhost", {
method: "delete",
body: JSON.stringify(id)
})
.then(res => res.json())
.then(res => {
if (res.error) {
this.setState({loading: false, error: res.error});
} else {
}
})
.catch(err => {
this.setState({
error: "Something went wrong while deleting comment.",
loading: false
});
});
}*/

export default function Comment(props) {
const { id, name, message, time, parent_id } = props.comment;
const {id, name, message, time, parent_id} = props.comment;

return (
<div className={parent_id > 0 ? "media mb-3 ml-5" : "media mb-3"} >
<img
className="mr-3 bg-light rounded"
width="48"
height="48"
src={`https://api.adorable.io/avatars/48/${name.toLowerCase()}@adorable.io.png`}
alt={name}
/>
return (
<div className={parent_id > 0 ? "media mb-3 ml-5" : "media mb-3"}>
<img
className="mr-3 bg-light rounded"
width="48"
height="48"
src={`https://api.adorable.io/avatars/48/${name.toLowerCase()}@adorable.io.png`}
alt={name}
/>

<div className="media-body p-2 shadow-sm rounded bg-light border">
<small className="float-right text-muted">#{id} ({time})</small>
<h6 className="mt-0 mb-1 text-muted">{name}</h6>
{message}
<form>
<button className ="btn btn-primary float-right text-white">💬 Comment</button>
</form>
</div>
</div>
);
}
<div className="media-body p-2 shadow-sm rounded bg-light border">
<small className="float-right text-muted">#{id} ({time})</small>
<h6 className="mt-0 mb-1 text-muted">{name}</h6>
{message}
<form className="form-group" >
<button className="btn btn-primary float-right text-white ml-3">❌ Delete</button>
<button className="btn btn-primary float-right text-white ml-3">✏ Edit</button>
<button className="btn btn-primary float-right text-white ml-3">💬 Comment</button>
</form>
</div>
</div>
);
}

0 comments on commit b34ee55

Please sign in to comment.