Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/samuel barker implement mockup #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 193 additions & 0 deletions public/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,196 @@
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
background-color: #F8F8F8;
}

/* Common border styling */
.comment, .comment__children > .comment, .event__details, .event__progress__meter {
border: 1px solid #dfe0e6;
}

/* Common styling between the event section and the comments section. */
.event, .comments {
display: table-cell;
width: 35%;
max-width: 50%;
height: 20%;
margin-top: 5%;
}

/* Styling for the event side-panel */
.event {
background: white;
border: 2px solid #dfe0e6;
border-radius: 5px;
float: left;
margin-left: 10%;
margin-top: 5%;
}

/* Styling for the comments side-panel */
.comments {
float: right;
margin-right: 10%;
}

/* Handles mobile and tablet views */
@media all and (max-width: 800px) {
.event, .comments {
width: 90%;
max-width: 90%;
}

.event {
display: table-header-group;
margin-left: 5%;
}

.comments {
display: table-footer-group;
margin-right: 5%;
}
}

/* Styles the component which contains the title */
.event__title__container {
background: #F5F5F5;
border-bottom: 2px solid #dfe0e6;
width: auto;
}

/* Styles the event title */
.event__title {
margin: 0;
padding: 2%;
font-size: 95%;
}

/* Styles the event description */
.event__description {
margin: 3%;
padding-bottom: 3%;
border-bottom: 1px solid #dfe0e6;
}

/* Styles the event funding */
.event__funding {
margin: 3%;
}

/* Styles the totals text for the event funding */
.event__funding__totals {
color: #245626;
}

/* Styles the amount raised for the event funding element */
.event__funding__raised {
font-size: 200%;
font-weight: bold;
}

/* Styles the funding progress meter */
.event__progress__meter{
background: #F5F5F5;
}

/* Styles the event progress percent */
.event__progress__percent {
background: #3CBF42;
padding-bottom: 5%;
}

/* Styles the event details */
.event__details {
margin-left: 3%;
margin-right: 3%;
margin-bottom: 3%;
background: #F5F5F5;
overflow: hidden;
padding: 2%;
}

/* Common styling for the event date and the event location */
.event__details__date, .event__details__location {
width: 40%;
display: inline;
float: left;
font-size: 75%;
margin-left: 10%;
}

/* Styling for normal comments */
.comment {
background: #F5F5F5;
margin-bottom: 8%;
border-radius: 5px;
position: relative;
}

/* Styling for child comments */
.comment__children > .comment {
background: white;
margin-left: 8%;
margin-bottom: 10%;
border-radius: 5px;
}

/* Styling for the picture in a comment */
.comment__picture {
max-width: 15%;
max-height: 15%:
display: inline-block;
margin: 3%;
}

/* Styling for the actual text of a comment */
.comment__text {
display: inline-block;
vertical-align: top;
margin-top: 3%;
font-size: 85%;
max-height: 20%;
max-width: 75%;
}

/* Handles the transform of the 'arrow' for the message */
.comment:before, .comment:after, .comment__children > .comment:after {
transform: rotate( 135deg ) skew( 0deg );
-moz-transform: rotate( 135deg ) skew( 0deg );
-ms-transform: rotate( 135deg ) skew( 0deg );
-o-transform: rotate( 135deg ) skew( 0deg );
-webkit-transform: rotate( 135deg ) skew( 0deg );
content: "";
position: absolute;
}

/* Common styling for arrows */
.comment:after, .comment__children > .comment:after {
left: -12px;
border-left: 19px solid transparent;
border-right: 19px solid transparent;
}

/* Styling for border of the arrow */
.comment:before {
top: 85%;
left: -14px;
border-top: 20px solid #dfe0e6;
border-top-color: #dfe0e6;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
z-index: -1;
}

/* Styling for the arrow for a normal comment */
.comment:after {
top: 84%;
border-top: 19px solid #F5F5F5;
border-top-color: #F5F5F5;
}

/* Styling for the arrow for a child comment */
.comment__children > .comment:after {
top: 83%;
border-top: 19px solid white;
border-top-color: white;
}
132 changes: 132 additions & 0 deletions src/components/comments/elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Picture component.
*/
class Picture {
constructor(personName) {
this.personName = personName;
}

render() {
/**
* Find the correct profile image for the people with specific names.
* Otherwise just assigns a random image.
*/
function getProfileImageForPerson(personName) {
let character = personName.slice(-1);
let pictureNumber = 0;

switch(character) {
case 'A':
pictureNumber = 13;
break;
case 'B':
pictureNumber = 12;
break;
case 'C':
pictureNumber = 11;
break;
case 'D':
pictureNumber = 10;
break;
default:
// Just select a random profile picture.
pictureNumber = Math.floor(Math.random() * 20) + 1;
break;
}

return `128-${pictureNumber}.jpg`;
}

return `
<img class="comment__picture" src="../../../images/faces/${getProfileImageForPerson(this.personName)}" />
`;
}
}

/**
* Title component.
*/
class Title {
constructor(person, donation) {
this.person = person;
this.donation = donation;
}

render() {
/**
* Obtains the correct donation HTML string depending on whether or not there was a donation.
*/
function renderDonationHTML(donation) {
let donationHTML = ``;
if(donation > 0) {
donationHTML = `
<small>donated £${(donation/100).toFixed(2)}</small>
`;
}

return donationHTML;
}

return `
<strong>${this.person}</strong>
${renderDonationHTML(this.donation)}
`;
}
}

/**
* Text component.
*/
class Text {
constructor(text) {
this.text = text;
}

render() {
return `<p>${this.text}</p>`;
}
}

/**
* Comment component.
*/
export class Comment {
constructor(comment) {
this.picture = new Picture(comment.name);
this.title = new Title(comment.name, comment.donation);
this.text = new Text(comment.comment);

// Recursively create child comments to this one.
this.children = comment.children.map(child => new Comment(child));
}

render() {
/**
* If a comment has any children, render them.
*/
function renderChildrenIfDefined(children) {
let childrenHTML = ``;

if(children && children.length && children.length > 0) {
childrenHTML = `
<div class="comment__children">
${children.map(child => child.render())}
</div>
`;
}

return childrenHTML;
}

return `
<div class="comment">
${this.picture.render()}
<div class="comment__text">
${this.title.render()}
${this.text.render()}
</div>
</div>
${renderChildrenIfDefined(this.children)}
`;
}
}
20 changes: 19 additions & 1 deletion src/components/comments/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// -- comments
// -- -- comment

import {Comment} from './elements.js'

export default class {
constructor(data) {
this.data = data;
Expand All @@ -6,9 +11,22 @@ export default class {
}

createFactories() {
this.comments = this.data.comments.map(comment => new Comment(comment));
}

render() {
return "comments";
/**
* Using normal map method adds commas between entries because of the array toString() method.
* Overcome this by doing it this way.
*/
function renderComments(comments) {
let result = ``;
comments.map(comment => result = result + ' ' + comment.render());
return result;
}

return `<div class="comments">
${renderComments(this.comments)}
</div>`;
}
}
Loading