Open platform to collect and prioritize feedback
fix: better alignment of votes modal content on mobile devices (#826)
Guilherme Oenninge166d8d056e3
diff --git a/public/components/common/Moment.tsx b/public/components/common/Moment.tsxindex 9baf36083..f7654d787 100644--- a/public/components/common/Moment.tsx+++ b/public/components/common/Moment.tsx@@ -3,7 +3,8 @@ import { formatDate, timeSince } from "@fider/services";interface MomentText {date: Date | string;- format?: "full" | "timeSince";+ useRelative?: boolean;+ format?: "full" | "short";}export const Moment = (props: MomentText) => {@@ -11,16 +12,17 @@ export const Moment = (props: MomentText) => {return <span />;}- const format = props.format || "timeSince";+ const format = props.format || "full";+ const useRelative = typeof props.useRelative !== "undefined" ? props.useRelative : true;const now = new Date();const date = props.date instanceof Date ? props.date : new Date(props.date);const diff = (now.getTime() - date.getTime()) / (60 * 60 * 24 * 1000);- const display = format === "full" || diff >= 365 ? formatDate(props.date) : timeSince(now, date);+ const display = !useRelative || diff >= 365 ? formatDate(props.date, format) : timeSince(now, date);return (- <span className="date" title={formatDate(props.date)}>+ <span className="date" title={formatDate(props.date, "full")}>{display}</span>);diff --git a/public/pages/Administration/components/BillingPlanPanel.tsx b/public/pages/Administration/components/BillingPlanPanel.tsxindex 0fcc1f5df..945af0293 100644--- a/public/pages/Administration/components/BillingPlanPanel.tsx+++ b/public/pages/Administration/components/BillingPlanPanel.tsx@@ -178,7 +178,7 @@ export class BillingPlanPanel extends React.Component<BillingPlanPanelProps, Bil<>Your <strong>{currentPlan.name}</strong> subscription ends at{" "}<strong>- <Moment date={billing.subscriptionEndsAt} format="full" />+ <Moment date={billing.subscriptionEndsAt} useRelative={false} /></strong>. Subscribe to a new plan and avoid a service interruption.</>@@ -191,7 +191,7 @@ export class BillingPlanPanel extends React.Component<BillingPlanPanelProps, Bil</strong>{" "}is due on{" "}<strong>- <Moment date={this.props.invoiceDue.dueDate} format="full" />+ <Moment date={this.props.invoiceDue.dueDate} useRelative={false} /></strong>.</>@@ -207,7 +207,7 @@ export class BillingPlanPanel extends React.Component<BillingPlanPanelProps, Bil<>Your trial period ends at{" "}<strong>- <Moment date={billing.trialEndsAt} format="full" />+ <Moment date={billing.trialEndsAt} useRelative={false} /></strong>. Subscribe to a plan and avoid a service interruption.</>diff --git a/public/pages/ShowPost/components/VotesModal.scss b/public/pages/ShowPost/components/VotesModal.scssindex da0291e59..85e8794cc 100644--- a/public/pages/ShowPost/components/VotesModal.scss+++ b/public/pages/ShowPost/components/VotesModal.scss@@ -6,18 +6,21 @@overflow-y: scroll;.c-list-item {margin: 5px 0px;+ display: flex;.c-avatar {margin-right: 5px;}.l-user {- display: inline-block;vertical-align: middle;span {display: block;}}- span.date {- float: right;+ .l-date {+ margin-left: auto;+ text-align: right;+ width: 60px;+ min-width: 60px;}}}diff --git a/public/pages/ShowPost/components/VotesModal.tsx b/public/pages/ShowPost/components/VotesModal.tsxindex eaeb0a327..4a44dc608 100644--- a/public/pages/ShowPost/components/VotesModal.tsx+++ b/public/pages/ShowPost/components/VotesModal.tsx@@ -84,8 +84,8 @@ export class VotesModal extends React.Component<VotesModalProps, VotesModalState<UserName user={x.user} /><span className="info">{x.user.email}</span></span>- <span className="info">- <Moment date={x.createdAt} />+ <span className="l-date info">+ <Moment date={x.createdAt} useRelative={false} format="short" /></span></ListItem>))}diff --git a/public/services/utils.spec.ts b/public/services/utils.spec.tsindex 2fa452685..bcf4f1721 100644--- a/public/services/utils.spec.ts+++ b/public/services/utils.spec.ts@@ -32,8 +32,20 @@ import { readFileSync } from "fs";{ input: "2018-04-11T18:13:33.128082", expected: "April 11, 2018 · 18:13" },{ input: "2017-11-20T07:47:42.158142", expected: "November 20, 2017 · 07:47" }].forEach(x => {- test(`formatDate of ${x.input} should be ${x.expected}`, () => {- const result = formatDate(x.input);+ test(`formatDate (full) of ${x.input} should be ${x.expected}`, () => {+ const result = formatDate(x.input, "full");+ expect(result).toEqual(x.expected);+ });+});++[+ { input: new Date(2018, 4, 27, 10, 12, 59), expected: "May 2018" },+ { input: new Date(2058, 12, 12, 23, 21, 53), expected: "Jan 2059" },+ { input: "2018-04-11T18:13:33.128082", expected: "Apr 2018" },+ { input: "2017-11-20T07:47:42.158142", expected: "Nov 2017" }+].forEach(x => {+ test(`formatDate (short) of ${x.input} should be ${x.expected}`, () => {+ const result = formatDate(x.input, "short");expect(result).toEqual(x.expected);});});diff --git a/public/services/utils.ts b/public/services/utils.tsindex 6ba57d8d4..7cff8b3da 100644--- a/public/services/utils.ts+++ b/public/services/utils.ts@@ -47,15 +47,21 @@ const twoDigits = (value: number): string => {return value <= 9 ? `0${value}` : value.toString();};-export const formatDate = (input: Date | string): string => {+type DateFormat = "full" | "short";++export const formatDate = (input: Date | string, format: DateFormat = "full"): string => {const date = input instanceof Date ? input : new Date(input);- const day = date.getDate();const monthIndex = date.getMonth();const year = date.getFullYear();++ if (format === "short") {+ return `${monthNames[monthIndex].substring(0, 3)} ${year}`;+ }++ const day = date.getDate();const hours = twoDigits(date.getHours());const minutes = twoDigits(date.getMinutes());-return `${monthNames[monthIndex]} ${day}, ${year} · ${hours}:${minutes}`;};