]> Untitled Git - lemmy.git/commitdiff
A few cake day fixes. #916
authorDessalines <tyhou13@gmx.com>
Thu, 9 Jul 2020 23:59:02 +0000 (19:59 -0400)
committerDessalines <tyhou13@gmx.com>
Thu, 9 Jul 2020 23:59:02 +0000 (19:59 -0400)
server/src/db/comment_view.rs
ui/src/components/cake-day.tsx
ui/src/components/comment-node.tsx
ui/src/components/post-listing.tsx
ui/src/components/user-listing.tsx
ui/src/utils.ts

index 75ed4cb7cadef03a23acb3cbcae0cef5511dedaa..7c853a81794595f8eb0f46b0077a93266d30ed55 100644 (file)
@@ -27,8 +27,8 @@ table! {
     creator_actor_id -> Text,
     creator_local -> Bool,
     creator_name -> Varchar,
-    creator_avatar -> Nullable<Text>,
     creator_published -> Timestamp,
+    creator_avatar -> Nullable<Text>,
     score -> BigInt,
     upvotes -> BigInt,
     downvotes -> BigInt,
@@ -63,8 +63,8 @@ table! {
     creator_actor_id -> Text,
     creator_local -> Bool,
     creator_name -> Varchar,
-    creator_avatar -> Nullable<Text>,
     creator_published -> Timestamp,
+    creator_avatar -> Nullable<Text>,
     score -> BigInt,
     upvotes -> BigInt,
     downvotes -> BigInt,
@@ -102,8 +102,8 @@ pub struct CommentView {
   pub creator_actor_id: String,
   pub creator_local: bool,
   pub creator_name: String,
-  pub creator_avatar: Option<String>,
   pub creator_published: chrono::NaiveDateTime,
+  pub creator_avatar: Option<String>,
   pub score: i64,
   pub upvotes: i64,
   pub downvotes: i64,
index be807184953a90d805029f48b6eb0623644f5cfc..f28be33c204e5fe17ae819a3cebb8e3d2120a335 100644 (file)
@@ -2,20 +2,15 @@ import { Component } from 'inferno';
 import { i18n } from '../i18next';
 
 interface CakeDayProps {
-  creator_name: string;
-  is_post_creator?: boolean;
+  creatorName: string;
 }
 
 export class CakeDay extends Component<CakeDayProps, any> {
   render() {
-    const { creator_name, is_post_creator } = this.props;
-
     return (
       <div
-        className={`mr-lg-2 d-inline-block unselectable pointer${
-          is_post_creator ? ' mx-2' : ''
-        }`}
-        data-tippy-content={this.cakeDayTippy(creator_name)}
+        className={`mx-2 d-inline-block unselectable pointer`}
+        data-tippy-content={this.cakeDayTippy()}
       >
         <svg class="icon icon-inline">
           <use xlinkHref="#icon-cake"></use>
@@ -24,7 +19,7 @@ export class CakeDay extends Component<CakeDayProps, any> {
     );
   }
 
-  cakeDayTippy(creator_name: string): string {
-    return i18n.t('cake_day_info', { creator_name });
+  cakeDayTippy(): string {
+    return i18n.t('cake_day_info', { creator_name: this.props.creatorName });
   }
 }
index 0e2d1d94b11939228e4ebc5c8b8aa5154009b817..8e976e7cc8d4bcd6c57f3de62f459faaf28e4dae 100644 (file)
@@ -26,7 +26,6 @@ import {
   isMod,
   setupTippy,
   colorList,
-  isCakeDay,
 } from '../utils';
 import moment from 'moment';
 import { MomentTime } from './moment-time';
@@ -34,7 +33,6 @@ import { CommentForm } from './comment-form';
 import { CommentNodes } from './comment-nodes';
 import { UserListing } from './user-listing';
 import { i18n } from '../i18next';
-import { CakeDay } from './cake-day';
 
 interface CommentNodeState {
   showReply: boolean;
@@ -160,14 +158,11 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                     id: node.comment.creator_id,
                     local: node.comment.creator_local,
                     actor_id: node.comment.creator_actor_id,
+                    published: node.comment.creator_published,
                   }}
                 />
               </span>
 
-              {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">
                   {i18n.t('mod')}
index 92a2f9cb8aafac6df12f6df6e2acef28861a73ea..fa2a078e4664daf3dc24b743cf197f3a00deffa7 100644 (file)
@@ -33,10 +33,8 @@ import {
   setupTippy,
   hostname,
   previewLines,
-  isCakeDay,
 } from '../utils';
 import { i18n } from '../i18next';
-import { CakeDay } from './cake-day';
 
 interface PostListingState {
   showEdit: boolean;
@@ -436,13 +434,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                       id: post.creator_id,
                       local: post.creator_local,
                       actor_id: post.creator_actor_id,
+                      published: post.creator_published,
                     }}
                   />
 
-                  {isCakeDay(post.creator_published) && (
-                    <CakeDay creator_name={post.creator_name} is_post_creator />
-                  )}
-
                   {this.isMod && (
                     <span className="mx-1 badge badge-light">
                       {i18n.t('mod')}
index 0e150b9420d3468d61cadd01ea229ab2dca01c54..58475d3e94127996cdc516d898745cf6b5e4ccec 100644 (file)
@@ -1,7 +1,13 @@
 import { Component } from 'inferno';
 import { Link } from 'inferno-router';
 import { UserView } from '../interfaces';
-import { pictrsAvatarThumbnail, showAvatars, hostname } from '../utils';
+import {
+  pictrsAvatarThumbnail,
+  showAvatars,
+  hostname,
+  isCakeDay,
+} from '../utils';
+import { CakeDay } from './cake-day';
 
 interface UserOther {
   name: string;
@@ -9,6 +15,7 @@ interface UserOther {
   avatar?: string;
   local?: boolean;
   actor_id?: string;
+  published?: string;
 }
 
 interface UserListingProps {
@@ -35,17 +42,21 @@ export class UserListing extends Component<UserListingProps, any> {
     }
 
     return (
-      <Link className="text-body font-weight-bold" to={link}>
-        {user.avatar && showAvatars() && (
-          <img
-            height="32"
-            width="32"
-            src={pictrsAvatarThumbnail(user.avatar)}
-            class="rounded-circle mr-2"
-          />
-        )}
-        <span>{name_}</span>
-      </Link>
+      <>
+        <Link className="text-body font-weight-bold" to={link}>
+          {user.avatar && showAvatars() && (
+            <img
+              height="32"
+              width="32"
+              src={pictrsAvatarThumbnail(user.avatar)}
+              class="rounded-circle mr-2"
+            />
+          )}
+          <span>{name_}</span>
+        </Link>
+
+        {isCakeDay(user.published) && <CakeDay creatorName={name_} />}
+      </>
     );
   }
 }
index e38834aa5d1f43565db47e869cea88bff2fed779..22536043e23108d5f6bcbc254e000e25d0680f81 100644 (file)
@@ -502,10 +502,10 @@ export function showAvatars(): boolean {
   );
 }
 
-export function isCakeDay(creator_published: string): boolean {
+export function isCakeDay(published: string): boolean {
   // moment(undefined) or moment.utc(undefined) returns the current date/time
   // moment(null) or moment.utc(null) returns null
-  const userCreationDate = moment.utc(creator_published || null).local();
+  const userCreationDate = moment.utc(published || null).local();
   const currentDate = moment(new Date());
 
   return (