]> Untitled Git - lemmy.git/blob - ui/src/components/cake-day.tsx
Merge remote-tracking branch 'upstream/master' into cake-day
[lemmy.git] / ui / src / components / cake-day.tsx
1 import { Component } from 'inferno';
2 import moment from 'moment';
3 import { i18n } from '../i18next';
4
5 interface CakeDayProps {
6   creator_name: string;
7   creator_published: string;
8 }
9
10 export class CakeDay extends Component<CakeDayProps, any> {
11   render() {
12     const { creator_name, creator_published } = this.props;
13
14     return (
15       this.isCakeDay(creator_published) && (
16         <div
17           className="mr-lg-2 d-inline-block unselectable pointer mx-2"
18           data-tippy-content={this.cakeDayTippy(creator_name)}
19         >
20           <svg class="icon icon-inline">
21             <use xlinkHref="#icon-cake"></use>
22           </svg>
23         </div>
24       )
25     );
26   }
27
28   isCakeDay(input: string): boolean {
29     const userCreationDate = moment.utc(input).local();
30     const currentDate = moment(new Date());
31
32     return (
33       userCreationDate.date() === currentDate.date() &&
34       userCreationDate.month() === currentDate.month()
35     );
36   }
37
38   cakeDayTippy(creator_name: string): string {
39     return i18n.t('cake_day_info', { creator_name });
40   }
41 }