-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move note into seperate component
- Loading branch information
Showing
3 changed files
with
51 additions
and
32 deletions.
There are no files selected for viewing
File renamed without changes.
43 changes: 43 additions & 0 deletions
43
src/app/view/components/Body/components/Table/Note/Note.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import clsx from "clsx"; | ||
import { AiOutlineCalendar, AiOutlineUser } from "react-icons/ai"; | ||
|
||
import style from "./Note.module.css"; | ||
import formatDate from "@/lib/utils/formatDate"; | ||
import timeInterval from "@/lib/utils/timeInterval"; | ||
|
||
import { NoteDatabseType } from "@/types/notes"; | ||
import MarkdownRenderer from "@/components/MarkdownRenderer/MarkdownRenderer"; | ||
|
||
interface NoteProps { | ||
note: NoteDatabseType; | ||
intervalFomatDate: boolean; | ||
setIntervalFomatDate: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
export default function Note({ note, intervalFomatDate, setIntervalFomatDate }: NoteProps) { | ||
const toggleIntervalFomatDate = () => setIntervalFomatDate((prev) => !prev); | ||
|
||
return ( | ||
<li key={note._id} className={style.note}> | ||
<header className="flex flex-row w-fit text-gray-500"> | ||
<p className={style.chip}> | ||
<AiOutlineUser /> | ||
<span>{note.name}</span> | ||
</p> | ||
|
||
<button type="button" className={clsx(style.chip, "ml-3 mr-2")} onClick={toggleIntervalFomatDate}> | ||
<AiOutlineCalendar /> | ||
{intervalFomatDate && <span>{timeInterval(note.date)}</span>} | ||
{!intervalFomatDate && <span>{formatDate(note.date, false)}</span>} | ||
</button> | ||
|
||
{note.useMarkdown && ( | ||
<span className="gradient-600 text-white text-xs rounded-sm h-fit px-1 -translate-y-0.5">Md</span> | ||
)} | ||
</header> | ||
|
||
{note.useMarkdown && <MarkdownRenderer content={note.content} />} | ||
{!note.useMarkdown && <p className="whitespace-pre-wrap mt-3 text-gray-700">{note.content}</p>} | ||
</li> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters