1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00
vault-frontend/src/containers/settings/SettingsNotes/index.tsx
2022-08-12 13:21:43 +07:00

70 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { FC, useState, VFC } from "react";
import { Filler } from "~/components/containers/Filler";
import { Group } from "~/components/containers/Group";
import { Button } from "~/components/input/Button";
import { NoteCard } from "~/components/notes/NoteCard";
import { NoteCreationForm } from "~/components/notes/NoteCreationForm";
import { NoteProvider, useNotesContext } from "~/utils/providers/NoteProvider";
import styles from "./styles.module.scss";
interface SettingsNotesProps {}
const List = () => {
const { notes } = useNotesContext();
return (
<>
{notes.map(note => (
<NoteCard
key={note.id}
content={note.content}
createdAt={note.created_at}
/>
))}
</>
);
};
const Form: FC<{ onCancel: () => void }> = ({ onCancel }) => {
const { submit } = useNotesContext();
return <NoteCreationForm onSubmit={submit} onCancel={onCancel} />;
};
const SettingsNotes: VFC<SettingsNotesProps> = () => {
const [formIsShown, setFormIsShown] = useState(false);
return (
<NoteProvider>
<div className={styles.grid}>
<div className={styles.head}>
{formIsShown ? (
<Form onCancel={() => setFormIsShown(false)} />
) : (
<Group className={styles.showForm} horizontal>
<Filler />
<Button
onClick={() => setFormIsShown(true)}
size="mini"
iconRight="plus"
color="secondary"
>
Добавить
</Button>
</Group>
)}
</div>
<div className={styles.list}>
<Group>
<Group>
<List />
</Group>
</Group>
</div>
</div>
</NoteProvider>
);
};
export { SettingsNotes };