From 58004aeff0e921016052f6eb76bb56641891a0ae Mon Sep 17 00:00:00 2001 From: lareii Date: Mon, 16 Sep 2024 19:57:13 +0300 Subject: [PATCH] refactor(client): componentize tooltip for posts and comments --- client/components/app/Comment/index.jsx | 46 +-------------------- client/components/app/Post/index.jsx | 52 +---------------------- client/components/app/Tooltip/Date.jsx | 55 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 94 deletions(-) create mode 100644 client/components/app/Tooltip/Date.jsx diff --git a/client/components/app/Comment/index.jsx b/client/components/app/Comment/index.jsx index 22c883b..9fd7fac 100644 --- a/client/components/app/Comment/index.jsx +++ b/client/components/app/Comment/index.jsx @@ -9,6 +9,7 @@ import { import Dropdown from '@/components/app/Comment/Dropdown'; import LikeButton from '@/components/app/Comment/LikeButton'; import UserInfo from '@/components/app/User/Info'; +import DateTooltip from '@/components/app/Tooltip/Date'; export default function Comment({ comment: initialComment, onDelete }) { const [comment, setComment] = useState(initialComment); @@ -26,50 +27,7 @@ export default function Comment({ comment: initialComment, onDelete }) { {comment.content}
- - - -
- {new Date(comment.created_at.T * 1000).toLocaleDateString( - 'tr-TR', - { - year: 'numeric', - month: 'long', - day: 'numeric' - } - )} -
-
- -
- oluşturuldu:{' '} - {new Date(comment.created_at.T * 1000).toLocaleDateString( - 'tr-TR', - { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric' - } - )} -
-
- güncellendi:{' '} - {new Date(comment.updated_at.T * 1000).toLocaleDateString( - 'tr-TR', - { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric' - } - )} -
-
-
-
+
); diff --git a/client/components/app/Post/index.jsx b/client/components/app/Post/index.jsx index 0ab98a5..7fe8e1e 100644 --- a/client/components/app/Post/index.jsx +++ b/client/components/app/Post/index.jsx @@ -3,16 +3,11 @@ import { usePathname } from 'next/navigation'; import { useState } from 'react'; import Markdown from 'react-markdown'; -import { - Tooltip, - TooltipContent, - TooltipProvider, - TooltipTrigger -} from '@/components/ui/tooltip'; import Dropdown from '@/components/app/Post/Dropdown'; import LikeButton from '@/components/app/Post/LikeButton'; import CommentButton from '@/components/app/Post/CommentButton'; import UserInfo from '@/components/app/User/Info'; +import DateTooltip from '@/components/app/Tooltip/Date'; export default function Post({ post: initialPost, onDelete, onNewComment }) { const [post, setPost] = useState(initialPost); @@ -43,50 +38,7 @@ export default function Post({ post: initialPost, onDelete, onNewComment }) { onNewComment={onNewComment} /> - - - -
- {new Date(post.created_at.T * 1000).toLocaleDateString( - 'tr-TR', - { - year: 'numeric', - month: 'long', - day: 'numeric' - } - )} -
-
- -
- oluşturuldu:{' '} - {new Date(post.created_at.T * 1000).toLocaleDateString( - 'tr-TR', - { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric' - } - )} -
-
- güncellendi:{' '} - {new Date(post.updated_at.T * 1000).toLocaleDateString( - 'tr-TR', - { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric' - } - )} -
-
-
-
+ ); diff --git a/client/components/app/Tooltip/Date.jsx b/client/components/app/Tooltip/Date.jsx new file mode 100644 index 0000000..9df747a --- /dev/null +++ b/client/components/app/Tooltip/Date.jsx @@ -0,0 +1,55 @@ +import { useState } from 'react'; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger +} from '@/components/ui/tooltip'; + +export default function DateTooltip({ created_at, updated_at }) { + const [open, setOpen] = useState(false); + + return ( + + + +
setOpen(!open)} + onMouseEnter={() => setOpen(true)} + onMouseLeave={() => setOpen(false)} + onTouchStart={() => setOpen(!open)} + className='text-xs text-zinc-400' + > + {new Date(created_at.T * 1000).toLocaleDateString('tr-TR', { + year: 'numeric', + month: 'long', + day: 'numeric' + })} +
+
+ +
+ oluşturuldu:{' '} + {new Date(created_at.T * 1000).toLocaleDateString('tr-TR', { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric' + })} +
+
+ güncellendi:{' '} + {new Date(updated_at.T * 1000).toLocaleDateString('tr-TR', { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric' + })} +
+
+
+
+ ); +}