diff --git a/.gitignore b/.gitignore index a135040..e170750 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ node_modules /.pnp .pnp.js - +.env # testing /coverage diff --git a/components/Notes/LofiNotes.tsx b/components/Notes/LofiNotes.tsx new file mode 100644 index 0000000..c206d74 --- /dev/null +++ b/components/Notes/LofiNotes.tsx @@ -0,0 +1,335 @@ +import React,{ useState } from "react"; +import toast from "react-hot-toast"; +import { Notes } from "../../typings"; +import dynamic from "next/dynamic"; +const ReactQuill = dynamic(import("react-quill"), { ssr: false }); +import Dialog from "../../components/ChapterPopup/ChapterPopup"; + +function CategoryDropdown({ categories, handleCategoryChange }: any) { + return ( + + ); + } + + +const LofiNotes = ({ notes, user, setNotes }: any) => { + const [notetext, setNoteText] = useState(""); + const [topictext, setTopicText] = useState(""); + const [categorytext, setCategoryText] = useState(""); + const [tempNote, setTempNote] = useState(null); + + const [showTaskInput, setShowTaskInput] = useState(false); + const handleAddingTask = (event: { preventDefault: () => void }) => { + event.preventDefault(); + setShowTaskInput(true); + }; + + const [note, setNote] = useState({ text: "", topic: "", note: "", _id: "" }); + const [selectedCategory, setSelectedCategory] = useState(""); + + const handleCategoryChange = (event: any) => { + setSelectedCategory(event.target.value); + }; + + const notess = notes.filter( + (note:any) => note.email === user?.emailAddresses[0].emailAddress + ); + + let categories = new Set(); + notess.forEach((note:any) => { + categories.add(note.category); + }); + + + const handleNoteChange = async (id: string) => { + const mutations = { + _id: id, + note: notetext, + }; + + const result = await fetch("/api/setNotes", { + body: JSON.stringify(mutations), + method: "POST", + }); + const json = result.json(); + return json; + }; + + + const addDeleted = async (id: string | undefined) => { + try { + const noteInfo = { + // @ts-ignore + _id: id, + }; + //@ts-ignore + setNotes(notes.filter((t: any) => t._id != id)); + + const result = await fetch(`/api/deleteNote`, { + body: JSON.stringify(noteInfo), + method: "POST", + }); + const json = await result.json(); + toast.custom((t) => ( +
+
+
+
+ +
+
+

+ U Deleted a todos +

+

+ Try refreshing the page to see it! +

+
+
+
+
+ +
+
+ )); + return json; + } catch (err) { + console.error(err); + } + }; + + + const handleSubmit = async (e: any) => { + // e.preventDefault(); + const mutations: Notes = { + _type: "notes", + note: notetext, + topic: topictext, + category: categorytext, + email: user?.emailAddresses[0].emailAddress!, + }; + + setTempNote(mutations); + + fetch(`/api/addNotes`, { + body: JSON.stringify(mutations), + method: "POST", + }).then(async (res) => { + const json = await res.json(); + const newNote = json.message.results[0].document; + setNotes([...notes, newNote]); + setTempNote(null); + + toast.success("Successfully toasted!"); + toast.custom((t) => ( +
+
+
+
+ +
+
+

+ Todos Updated +

+

+ Try refreshing the page to see it! +

+
+
+
+ +
+
+
+ )); + }) + + }; + + + const filteredNotes = notess.filter( + (note:any) => selectedCategory == null || note.category === selectedCategory + ); + + console.log(filteredNotes) + + const [showModal, setShowModal] = React.useState(false); + const [selectedNote, setSelectedNote] = useState(""); + const [selectedNoteData, setSelectedNoteData] = useState(""); + + + const [showAddNotesModal, setShowAddNotesModal] = useState(false); + const handleAddingNewNote = () => { + setShowAddNotesModal(true); + }; + + return ( + <> +
+
+
+
+ +
+
+
+ +
+ {filteredNotes.map((note:any) => ( + <> + +
+
+ {selectedNote} +
+
+ +
+
+
+ { + setNoteText(e); + handleNoteChange(note._id!); + }} + /> +
+
+
+
{ + setShowModal(true); + console.log("note.topic", note.topic); + setSelectedNote(note.topic); + setSelectedNoteData(note.note); + }} + className="bg-[#212121] p-4 space-y-5 w-full rounded-lg" + > +
+

{note.topic}

+
+
+
+
+
+ + ))} +
+ + + {showTaskInput && ( +
+ {" "} +
+
+
+ setTopicText(e.target.value)} + /> + setCategoryText(e.target.value)} + /> +
+
+
+ {user ? ( +
+
+
+ + {/*