A few cake day fixes. #916

This commit is contained in:
Dessalines 2020-07-09 19:59:02 -04:00
parent 7c35fc546b
commit d222c60cef
6 changed files with 35 additions and 39 deletions

View file

@ -27,8 +27,8 @@ table! {
creator_actor_id -> Text, creator_actor_id -> Text,
creator_local -> Bool, creator_local -> Bool,
creator_name -> Varchar, creator_name -> Varchar,
creator_avatar -> Nullable<Text>,
creator_published -> Timestamp, creator_published -> Timestamp,
creator_avatar -> Nullable<Text>,
score -> BigInt, score -> BigInt,
upvotes -> BigInt, upvotes -> BigInt,
downvotes -> BigInt, downvotes -> BigInt,
@ -63,8 +63,8 @@ table! {
creator_actor_id -> Text, creator_actor_id -> Text,
creator_local -> Bool, creator_local -> Bool,
creator_name -> Varchar, creator_name -> Varchar,
creator_avatar -> Nullable<Text>,
creator_published -> Timestamp, creator_published -> Timestamp,
creator_avatar -> Nullable<Text>,
score -> BigInt, score -> BigInt,
upvotes -> BigInt, upvotes -> BigInt,
downvotes -> BigInt, downvotes -> BigInt,
@ -102,8 +102,8 @@ pub struct CommentView {
pub creator_actor_id: String, pub creator_actor_id: String,
pub creator_local: bool, pub creator_local: bool,
pub creator_name: String, pub creator_name: String,
pub creator_avatar: Option<String>,
pub creator_published: chrono::NaiveDateTime, pub creator_published: chrono::NaiveDateTime,
pub creator_avatar: Option<String>,
pub score: i64, pub score: i64,
pub upvotes: i64, pub upvotes: i64,
pub downvotes: i64, pub downvotes: i64,

View file

@ -2,20 +2,15 @@ import { Component } from 'inferno';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
interface CakeDayProps { interface CakeDayProps {
creator_name: string; creatorName: string;
is_post_creator?: boolean;
} }
export class CakeDay extends Component<CakeDayProps, any> { export class CakeDay extends Component<CakeDayProps, any> {
render() { render() {
const { creator_name, is_post_creator } = this.props;
return ( return (
<div <div
className={`mr-lg-2 d-inline-block unselectable pointer${ className={`mx-2 d-inline-block unselectable pointer`}
is_post_creator ? ' mx-2' : '' data-tippy-content={this.cakeDayTippy()}
}`}
data-tippy-content={this.cakeDayTippy(creator_name)}
> >
<svg class="icon icon-inline"> <svg class="icon icon-inline">
<use xlinkHref="#icon-cake"></use> <use xlinkHref="#icon-cake"></use>
@ -24,7 +19,7 @@ export class CakeDay extends Component<CakeDayProps, any> {
); );
} }
cakeDayTippy(creator_name: string): string { cakeDayTippy(): string {
return i18n.t('cake_day_info', { creator_name }); return i18n.t('cake_day_info', { creator_name: this.props.creatorName });
} }
} }

View file

@ -26,7 +26,6 @@ import {
isMod, isMod,
setupTippy, setupTippy,
colorList, colorList,
isCakeDay,
} from '../utils'; } from '../utils';
import moment from 'moment'; import moment from 'moment';
import { MomentTime } from './moment-time'; import { MomentTime } from './moment-time';
@ -34,7 +33,6 @@ import { CommentForm } from './comment-form';
import { CommentNodes } from './comment-nodes'; import { CommentNodes } from './comment-nodes';
import { UserListing } from './user-listing'; import { UserListing } from './user-listing';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
import { CakeDay } from './cake-day';
interface CommentNodeState { interface CommentNodeState {
showReply: boolean; showReply: boolean;
@ -160,14 +158,11 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
id: node.comment.creator_id, id: node.comment.creator_id,
local: node.comment.creator_local, local: node.comment.creator_local,
actor_id: node.comment.creator_actor_id, actor_id: node.comment.creator_actor_id,
published: node.comment.creator_published,
}} }}
/> />
</span> </span>
{isCakeDay(node.comment.creator_published) && (
<CakeDay creator_name={node.comment.creator_name} />
)}
{this.isMod && ( {this.isMod && (
<div className="badge badge-light d-none d-sm-inline mr-2"> <div className="badge badge-light d-none d-sm-inline mr-2">
{i18n.t('mod')} {i18n.t('mod')}

View file

@ -33,10 +33,8 @@ import {
setupTippy, setupTippy,
hostname, hostname,
previewLines, previewLines,
isCakeDay,
} from '../utils'; } from '../utils';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
import { CakeDay } from './cake-day';
interface PostListingState { interface PostListingState {
showEdit: boolean; showEdit: boolean;
@ -436,13 +434,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
id: post.creator_id, id: post.creator_id,
local: post.creator_local, local: post.creator_local,
actor_id: post.creator_actor_id, 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 && ( {this.isMod && (
<span className="mx-1 badge badge-light"> <span className="mx-1 badge badge-light">
{i18n.t('mod')} {i18n.t('mod')}

View file

@ -1,7 +1,13 @@
import { Component } from 'inferno'; import { Component } from 'inferno';
import { Link } from 'inferno-router'; import { Link } from 'inferno-router';
import { UserView } from '../interfaces'; import { UserView } from '../interfaces';
import { pictrsAvatarThumbnail, showAvatars, hostname } from '../utils'; import {
pictrsAvatarThumbnail,
showAvatars,
hostname,
isCakeDay,
} from '../utils';
import { CakeDay } from './cake-day';
interface UserOther { interface UserOther {
name: string; name: string;
@ -9,6 +15,7 @@ interface UserOther {
avatar?: string; avatar?: string;
local?: boolean; local?: boolean;
actor_id?: string; actor_id?: string;
published?: string;
} }
interface UserListingProps { interface UserListingProps {
@ -35,6 +42,7 @@ export class UserListing extends Component<UserListingProps, any> {
} }
return ( return (
<>
<Link className="text-body font-weight-bold" to={link}> <Link className="text-body font-weight-bold" to={link}>
{user.avatar && showAvatars() && ( {user.avatar && showAvatars() && (
<img <img
@ -46,6 +54,9 @@ export class UserListing extends Component<UserListingProps, any> {
)} )}
<span>{name_}</span> <span>{name_}</span>
</Link> </Link>
{isCakeDay(user.published) && <CakeDay creatorName={name_} />}
</>
); );
} }
} }

4
ui/src/utils.ts vendored
View 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(undefined) or moment.utc(undefined) returns the current date/time
// moment(null) or moment.utc(null) returns null // 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()); const currentDate = moment(new Date());
return ( return (