From 7605be6c77393ed98e179c27f3bc3915afb95f5c Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Fri, 9 Oct 2020 20:51:00 +0300
Subject: feat: create DateString component

---
 src/components/DateString/DateString.tsx | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 src/components/DateString/DateString.tsx

(limited to 'src/components/DateString/DateString.tsx')

diff --git a/src/components/DateString/DateString.tsx b/src/components/DateString/DateString.tsx
new file mode 100644
index 0000000..e31b52e
--- /dev/null
+++ b/src/components/DateString/DateString.tsx
@@ -0,0 +1,22 @@
+import React from 'react';
+
+interface PropTypes {
+  value: Date | string;
+}
+
+const DATE_FORMAT = {
+  month: 'long',
+  day: 'numeric',
+  year: 'numeric',
+  hour: '2-digit',
+  minute: '2-digit'
+};
+
+const DateString: React.FC<PropTypes> = ({ value }) => {
+  const date = new Date(value);
+  const formatted = date.toLocaleString('default', DATE_FORMAT);
+
+  return <>{formatted}</>;
+};
+
+export default DateString;
-- 
cgit v1.2.3


From 31900353b6ea3e4570c15d1c1585685b4413d6d9 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Fri, 9 Oct 2020 21:46:45 +0300
Subject: feat: toggle between compact and full date format

---
 src/components/DateString/DateString.tsx | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

(limited to 'src/components/DateString/DateString.tsx')

diff --git a/src/components/DateString/DateString.tsx b/src/components/DateString/DateString.tsx
index e31b52e..3f2ceb2 100644
--- a/src/components/DateString/DateString.tsx
+++ b/src/components/DateString/DateString.tsx
@@ -1,9 +1,18 @@
-import React from 'react';
+import React, { useState, useMemo, useCallback } from 'react';
+import { makeStyles } from '@material-ui/core/styles';
+import compactDateString from './compactDateString';
 
 interface PropTypes {
   value: Date | string;
 }
 
+const useStyles = makeStyles({
+  root: {
+    display: 'block',
+    cursor: 'pointer'
+  }
+});
+
 const DATE_FORMAT = {
   month: 'long',
   day: 'numeric',
@@ -13,10 +22,20 @@ const DATE_FORMAT = {
 };
 
 const DateString: React.FC<PropTypes> = ({ value }) => {
-  const date = new Date(value);
-  const formatted = date.toLocaleString('default', DATE_FORMAT);
+  const [isCompact, setIsCompact] = useState<boolean>(true);
+  const classes = useStyles();
+
+  const toggleScompact = useCallback(() => setIsCompact(v => !v), [setIsCompact]);
+
+  const date = useMemo(() => new Date(value), [value]);
+  const formatted = useMemo(() => date.toLocaleString('default', DATE_FORMAT), [date]);
+  const compact = useMemo(() => compactDateString(date), [date]);
 
-  return <>{formatted}</>;
+  return (
+    <div className={classes.root} onClick={toggleScompact}>
+      {isCompact ? compact : formatted}
+    </div>
+  );
 };
 
 export default DateString;
-- 
cgit v1.2.3


From a1a2cb59616d833d503c3c090116fc0ad1e9d542 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sat, 10 Oct 2020 11:48:05 +0300
Subject: fix: resolve eslint errors

---
 src/components/DateString/DateString.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/components/DateString/DateString.tsx')

diff --git a/src/components/DateString/DateString.tsx b/src/components/DateString/DateString.tsx
index 3f2ceb2..7c824cd 100644
--- a/src/components/DateString/DateString.tsx
+++ b/src/components/DateString/DateString.tsx
@@ -32,7 +32,7 @@ const DateString: React.FC<PropTypes> = ({ value }) => {
   const compact = useMemo(() => compactDateString(date), [date]);
 
   return (
-    <div className={classes.root} onClick={toggleScompact}>
+    <div role="presentation" className={classes.root} onClick={toggleScompact}>
       {isCompact ? compact : formatted}
     </div>
   );
-- 
cgit v1.2.3

