]> Untitled Git - lemmy.git/commitdiff
Updates to PR as requested
authorFilip785 <fdjuricic98@gmail.com>
Wed, 8 Jul 2020 17:46:18 +0000 (19:46 +0200)
committerFilip785 <fdjuricic98@gmail.com>
Wed, 8 Jul 2020 17:46:18 +0000 (19:46 +0200)
ui/src/components/cake-day.tsx
ui/src/components/comment-node.tsx
ui/src/components/post-listing.tsx
ui/src/utils.ts

index 67ac7f8bf62c6ab1f98fe055daa5a57c552cf6c9..be807184953a90d805029f48b6eb0623644f5cfc 100644 (file)
@@ -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<CakeDayProps, any> {
   render() {
-    const { creator_name, creator_published } = this.props;
+    const { creator_name, is_post_creator } = this.props;
 
     return (
-      this.isCakeDay(creator_published) && (
-        <div
-          className="mr-lg-2 d-inline-block unselectable pointer mx-2"
-          data-tippy-content={this.cakeDayTippy(creator_name)}
-        >
-          <svg class="icon icon-inline">
-            <use xlinkHref="#icon-cake"></use>
-          </svg>
-        </div>
-      )
-    );
-  }
-
-  isCakeDay(input: string): boolean {
-    const userCreationDate = moment.utc(input).local();
-    const currentDate = moment(new Date());
-
-    return (
-      userCreationDate.date() === currentDate.date() &&
-      userCreationDate.month() === currentDate.month()
+      <div
+        className={`mr-lg-2 d-inline-block unselectable pointer${
+          is_post_creator ? ' mx-2' : ''
+        }`}
+        data-tippy-content={this.cakeDayTippy(creator_name)}
+      >
+        <svg class="icon icon-inline">
+          <use xlinkHref="#icon-cake"></use>
+        </svg>
+      </div>
     );
   }
 
index ab9321bdaf007e5a223d374681f234ee1fd38363..2d1426b05343014c240087d1e3ce3c6c25a2be7e 100644 (file)
@@ -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<CommentNodeProps, CommentNodeState> {
 
   render() {
     let node = this.props.node;
-    const { creator_name, creator_published } = node.comment;
     return (
       <div
         className={`comment ${
@@ -164,10 +164,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                 />
               </span>
 
-              <CakeDay
-                creator_name={creator_name}
-                creator_published={creator_published}
-              />
+              {isCakeDay(node.comment.creator_published) && (
+                <CakeDay creator_name={node.comment.creator_name} />
+              )}
 
               {this.isMod && (
                 <div className="badge badge-light d-none d-sm-inline mr-2">
index 7199510b6a7b2cbc28286622baa4fbb8d645456a..92a2f9cb8aafac6df12f6df6e2acef28861a73ea 100644 (file)
@@ -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<PostListingProps, PostListingState> {
 
   listing() {
     let post = this.props.post;
-    const { creator_name, creator_published } = post;
-
     return (
       <div class="row">
         <div className={`vote-bar col-1 pr-0 small text-center`}>
@@ -440,10 +439,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                     }}
                   />
 
-                  <CakeDay
-                    creator_name={creator_name}
-                    creator_published={creator_published}
-                  />
+                  {isCakeDay(post.creator_published) && (
+                    <CakeDay creator_name={post.creator_name} is_post_creator />
+                  )}
 
                   {this.isMod && (
                     <span className="mx-1 badge badge-light">
index f65ca4e3795003076c3674130dbfd54a2f9e320a..3ccaae12d71ffe6d2c1edb2c567a4c6df7621594 100644 (file)
@@ -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`;