From: Filip785 Date: Wed, 8 Jul 2020 17:46:18 +0000 (+0200) Subject: Updates to PR as requested X-Git-Url: http://these/git/%22https:/join-lemmy.org/%22%7B%7D/static/gitweb.css?a=commitdiff_plain;h=8fe8836bc263be11895fafa958409499c9e9fc9d;p=lemmy.git Updates to PR as requested --- diff --git a/ui/src/components/cake-day.tsx b/ui/src/components/cake-day.tsx index 67ac7f8b..be807184 100644 --- a/ui/src/components/cake-day.tsx +++ b/ui/src/components/cake-day.tsx @@ -1,37 +1,26 @@ import { Component } from 'inferno'; -import moment from 'moment'; import { i18n } from '../i18next'; interface CakeDayProps { creator_name: string; - creator_published: string; + is_post_creator?: boolean; } export class CakeDay extends Component { render() { - const { creator_name, creator_published } = this.props; + const { creator_name, is_post_creator } = this.props; return ( - this.isCakeDay(creator_published) && ( -
- - - -
- ) - ); - } - - isCakeDay(input: string): boolean { - const userCreationDate = moment.utc(input).local(); - const currentDate = moment(new Date()); - - return ( - userCreationDate.date() === currentDate.date() && - userCreationDate.month() === currentDate.month() +
+ + + +
); } diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index ab9321bd..2d1426b0 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -26,6 +26,7 @@ import { isMod, setupTippy, colorList, + isCakeDay, } from '../utils'; import moment from 'moment'; import { MomentTime } from './moment-time'; @@ -126,7 +127,6 @@ export class CommentNode extends Component { render() { let node = this.props.node; - const { creator_name, creator_published } = node.comment; return (
{ /> - + {isCakeDay(node.comment.creator_published) && ( + + )} {this.isMod && (
diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index 7199510b..92a2f9cb 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -33,6 +33,7 @@ import { setupTippy, hostname, previewLines, + isCakeDay, } from '../utils'; import { i18n } from '../i18next'; import { CakeDay } from './cake-day'; @@ -258,8 +259,6 @@ export class PostListing extends Component { listing() { let post = this.props.post; - const { creator_name, creator_published } = post; - return (
@@ -440,10 +439,9 @@ export class PostListing extends Component { }} /> - + {isCakeDay(post.creator_published) && ( + + )} {this.isMod && ( diff --git a/ui/src/utils.ts b/ui/src/utils.ts index f65ca4e3..3ccaae12 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -53,6 +53,7 @@ import emojiShortName from 'emoji-short-name'; import Toastify from 'toastify-js'; import tippy from 'tippy.js'; import EmojiButton from '@joeattardi/emoji-button'; +import moment from 'moment'; export const repoUrl = 'https://github.com/LemmyNet/lemmy'; export const helpGuideUrl = '/docs/about_guide.html'; @@ -489,6 +490,16 @@ export function showAvatars(): boolean { ); } +export function isCakeDay(creator_published: string): boolean { + const userCreationDate = moment.utc(creator_published).local(); + const currentDate = moment(new Date()); + + return ( + userCreationDate.date() === currentDate.date() && + userCreationDate.month() === currentDate.month() + ); +} + // Converts to image thumbnail export function pictrsImage(hash: string, thumbnail: boolean = false): string { let root = `/pictrs/image`;