forked from dekkerglen/CubeCobra
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
eb09a57
commit a3095d6
Showing
13 changed files
with
396 additions
and
34 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
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,95 @@ | ||
import React from 'react'; | ||
|
||
class AgeText extends React.Component { | ||
constructor(props) | ||
{ | ||
super(props); | ||
} | ||
|
||
inSeconds(d1, d2) { | ||
var t2 = d2.getTime(); | ||
var t1 = d1.getTime(); | ||
|
||
return parseInt((t2-t1)/(1000)); | ||
} | ||
|
||
inMinutes(d1, d2) { | ||
var t2 = d2.getTime(); | ||
var t1 = d1.getTime(); | ||
|
||
return parseInt((t2-t1)/(60*1000)); | ||
} | ||
|
||
inHours(d1, d2) { | ||
var t2 = d2.getTime(); | ||
var t1 = d1.getTime(); | ||
|
||
return parseInt((t2-t1)/(3600*1000)); | ||
} | ||
|
||
inDays(d1, d2) { | ||
var t2 = d2.getTime(); | ||
var t1 = d1.getTime(); | ||
|
||
return parseInt((t2-t1)/(24*3600*1000)); | ||
} | ||
|
||
inWeeks(d1, d2) { | ||
var t2 = d2.getTime(); | ||
var t1 = d1.getTime(); | ||
|
||
return parseInt((t2-t1)/(24*3600*1000*7)); | ||
} | ||
|
||
inMonths(d1, d2) { | ||
var d1Y = d1.getFullYear(); | ||
var d2Y = d2.getFullYear(); | ||
var d1M = d1.getMonth(); | ||
var d2M = d2.getMonth(); | ||
|
||
return (d2M+12*d2Y)-(d1M+12*d1Y); | ||
} | ||
|
||
inYears(d1, d2) { | ||
return d2.getFullYear()-d1.getFullYear(); | ||
} | ||
|
||
render() { | ||
var date = new Date(this.props.date); | ||
var now = new Date(); | ||
var str = ''; | ||
if(this.inYears(date, now) > 0) { | ||
str = this.inYears(date, now) + ' year'; | ||
} else if(this.inMonths(date, now) > 0) { | ||
str = this.inMonths(date, now) + ' month'; | ||
} else if(this.inWeeks(date, now) > 0) { | ||
str = this.inWeeks(date, now) + ' week'; | ||
} else if(this.inDays(date, now) > 0) { | ||
str = this.inDays(date, now) + ' day'; | ||
} else if(this.inHours(date, now) > 0) { | ||
str = this.inHours(date, now) + ' hour'; | ||
} else if(this.inMinutes(date, now) > 0) { | ||
str = this.inMinutes(date, now) + ' minute'; | ||
} else if(this.inSeconds(date, now) > 0) { | ||
str = this.inSeconds(date, now) + ' second'; | ||
} else { | ||
str = 'just now'; | ||
} | ||
if(str != 'just now') | ||
{ | ||
if(parseInt(str) > 1) | ||
{ | ||
str += 's ago'; | ||
} | ||
else | ||
{ | ||
str += ' ago'; | ||
} | ||
} | ||
return ( | ||
<>{str}</> | ||
) | ||
} | ||
} | ||
|
||
export default AgeText |
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,52 @@ | ||
import React from 'react'; | ||
|
||
import CommentEntry from './CommentEntry'; | ||
import CommentsSection from './CommentsSection'; | ||
import AgeText from './AgeText'; | ||
|
||
class Comment extends React.Component { | ||
constructor(props) | ||
{ | ||
super(props); | ||
|
||
this.onPost = this.onPost.bind(this); | ||
|
||
this.childElement = React.createRef(); | ||
} | ||
|
||
onPost(comment) | ||
{ | ||
comment.index = this.props.comment.comments.length; | ||
this.props.comment.comments.push(comment); | ||
this.forceUpdate(); | ||
this.childElement.current.expand(); | ||
} | ||
|
||
render() { | ||
var comment = this.props.comment; | ||
return ( | ||
<div className='comment'> | ||
<div className="form-group"> | ||
{comment.ownerName ? <a href={'/user/view/'+comment.owner}><small>{comment.ownerName}</small></a> : <a><small>Anonymous</small></a>} | ||
{comment.timePosted && <a><small> - <AgeText date={comment.timePosted}/></small></a>} | ||
<br></br> | ||
<a>{comment.content}</a> | ||
<div> | ||
<a className="comment-button mb-2 text-muted clickable">Delete</a> | ||
{' '} | ||
<CommentEntry id={this.props.id} position={this.props.position} onPost={this.onPost}> | ||
<span className="comment-button mb-2 text-muted clickable">Reply</span> | ||
</CommentEntry> | ||
</div> | ||
</div> | ||
{comment.comments.length > 0 && | ||
<div className="pl-2 border-left"> | ||
<CommentsSection ref={this.childElement} className='pl-4' id={this.props.id} comments={comment.comments} position={this.props.position} expanded={comment.expanded ? true : false} /> | ||
</div> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Comment |
Oops, something went wrong.