From 40893069217f92024033bc0cdf3df7758cf76f69 Mon Sep 17 00:00:00 2001 From: DeveshPatel-14 Date: Thu, 5 Oct 2023 22:00:25 +0530 Subject: [PATCH 1/3] Added synced notes feature to lofi --- .gitignore | 2 +- pages/lofi.tsx | 285 ++++++++++++++++++++++++++++++++++---------- pages/workspace.tsx | 2 +- 3 files changed, 225 insertions(+), 64 deletions(-) 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/pages/lofi.tsx b/pages/lofi.tsx index 20a9d08..7e8661e 100644 --- a/pages/lofi.tsx +++ b/pages/lofi.tsx @@ -17,6 +17,11 @@ import { fetchNotes } from "../utils/fetchNotes"; import { fetchGoals } from "../utils/fetchGoals"; import LofiTodo from "../components/TodoList/LofiTodo"; import Draggable, { DraggableCore } from "react-draggable"; +import Notess from "../components/Notes/Notes"; + +import Dialog from "../components/ChapterPopup/ChapterPopup"; +import dynamic from "next/dynamic"; + interface Props { users: User[]; goals: Goals[]; @@ -39,6 +44,28 @@ const lofi = ({ users, goals, notes, setLoading }: Props) => { const [todos, setTodos] = useState([]); const [seconds, setSeconds] = useState(0); const [time, setTime] = useState(""); + + const ReactQuill = dynamic(import("react-quill"), { ssr: false }); + + function CategoryDropdown({ categories, handleCategoryChange }: any) { + return ( + + ); + } + useEffect(() => { setTodos( goals @@ -121,77 +148,211 @@ const lofi = ({ users, goals, notes, setLoading }: Props) => { console.log("posted 2 you gained points ", earnedPoints); }; + const notess = notes.filter( + (note) => note.email === user?.emailAddresses[0].emailAddress + ); + const [selectedCategory, setSelectedCategory] = useState(""); + + let categories = new Set(); + notess.forEach((note) => { + categories.add(note.category); + }); + + const handleCategoryChange = (event: any) => { + setSelectedCategory(event.target.value); + }; + + const filteredNotes = notess.filter( + (note) => selectedCategory === "" || note.category === selectedCategory + ); + + const [selectedNote, setSelectedNote] = useState(""); + const [selectedNoteData, setSelectedNoteData] = useState(""); + + const [text, setText] = useState(""); + const handleNoteChange = async (id: string) => { + const mutations = { + _id: id, + note: text, + }; + + const result = await fetch("/api/setNotes", { + body: JSON.stringify(mutations), + method: "POST", + }); + const json = result.json(); + return json; + }; + const [showModal, setShowModal] = React.useState(false); + const showNote = () => { + setShowModal(true); + }; + console.log(notess); + const [showAddNotesModal, setShowAddNotesModal] = useState(false); + + const handleAddingNewNote = () => { + setShowAddNotesModal(true); + }; + + const [dummyNote, setDummyNote] = useState(null); + return ( - -
- {sessionStarted && ( - <> - - {seconds > 0 && ( -
- {time}time -
- )} - - )} - {/* */} - -
- -
-
-
-
-
- + <> + +
+ {sessionStarted && ( + <> + + {seconds > 0 && ( +
+ {time}time +
+ )} + + )} + {/* */} + +
+
-
- + + + +
+
+
+
+
+ +
+
+ + +
+
-
-
+
+ {filteredNotes.map((note) => ( + <> + +
+
+ {selectedNote} +
+
+
+ { + setText(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}

+
+
+
+
+
+ + ))}
-
-
-
- + { + + } + +
+ + + + +
+
+
+ +
+
+ +
+
+
+
+
+
+
+ +
+
- -
- {activeSong?.title && ( -
- -
- )} -
- } - /> + {activeSong?.title && ( +
+ +
+ )} +
+ } + /> + ); }; diff --git a/pages/workspace.tsx b/pages/workspace.tsx index 9de2a1f..d049d94 100644 --- a/pages/workspace.tsx +++ b/pages/workspace.tsx @@ -812,7 +812,7 @@ const Home = ({ users, goals, notes, setLoading }: Props) => { ); }; -export const getServerSideProps: GetServerSideProps = async (context) => { +export const getServerSideProps: GetServerSideProps = async ({req,res}) => { const users = await fetchUsers(); const goals = await fetchGoals(); const notes = await fetchNotes(); From a7a799ff7f5e8032beea6af4b44757348fe31b7c Mon Sep 17 00:00:00 2001 From: DeveshPatel-14 Date: Fri, 6 Oct 2023 01:22:51 +0530 Subject: [PATCH 2/3] Added lofi notes --- components/Notes/LofiNotes.tsx | 335 +++++++++++++++++++++++++++++++++ pages/lofi.tsx | 12 +- 2 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 components/Notes/LofiNotes.tsx 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 ? ( +
+
+
+ + {/*