From 25743ddc2c57a55ad55475d61e305b0a7126450f Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sun, 31 Aug 2025 21:31:13 +0100 Subject: [PATCH] Overhauled notes system. --- .../Dashboard/common/MarkdownInput.jsx | 32 + .../Dashboard/common/NewObjectButtons.jsx | 16 +- src/components/Dashboard/common/NoteItem.jsx | 313 ++++++++++ .../Dashboard/common/NotesPanel.jsx | 588 ++---------------- .../Dashboard/common/ObjectProperty.jsx | 7 + .../Dashboard/common/WizardView.jsx | 67 ++ 6 files changed, 475 insertions(+), 548 deletions(-) create mode 100644 src/components/Dashboard/common/MarkdownInput.jsx create mode 100644 src/components/Dashboard/common/NoteItem.jsx create mode 100644 src/components/Dashboard/common/WizardView.jsx diff --git a/src/components/Dashboard/common/MarkdownInput.jsx b/src/components/Dashboard/common/MarkdownInput.jsx new file mode 100644 index 0000000..3ca12c5 --- /dev/null +++ b/src/components/Dashboard/common/MarkdownInput.jsx @@ -0,0 +1,32 @@ +import { Card, Splitter } from 'antd' +import PropTypes from 'prop-types' +import CodeBlockEditor from './CodeBlockEditor' +import MarkdownDisplay from './MarkdownDisplay' + +const MarkdownInput = ({ value, onChange }) => { + return ( + + + + + + + + + + + + + ) +} + +MarkdownInput.propTypes = { + value: PropTypes.string.isRequired, + onChange: PropTypes.func +} + +export default MarkdownInput diff --git a/src/components/Dashboard/common/NewObjectButtons.jsx b/src/components/Dashboard/common/NewObjectButtons.jsx index 9d08419..9888b92 100644 --- a/src/components/Dashboard/common/NewObjectButtons.jsx +++ b/src/components/Dashboard/common/NewObjectButtons.jsx @@ -13,13 +13,15 @@ const NewObjectButtons = ({ }) => { return ( - + {totalSteps > 1 ? ( + + ) : null} {currentStep < totalSteps - 1 ? ( + + + Type: + + {note.noteType.name} + + + + User ID: + + + + Created At: + + + + + , + + ]} + > + Are you sure you want to delete this note? + + + ) +} + +NoteItem.propTypes = { + note: PropTypes.object.isRequired +} + +export default NoteItem diff --git a/src/components/Dashboard/common/NotesPanel.jsx b/src/components/Dashboard/common/NotesPanel.jsx index 17d0851..d32f83f 100644 --- a/src/components/Dashboard/common/NotesPanel.jsx +++ b/src/components/Dashboard/common/NotesPanel.jsx @@ -1,4 +1,4 @@ -import { useCallback, useContext, useEffect, useState } from 'react' +import { useCallback, useContext, useEffect, useState, useRef } from 'react' import PropTypes from 'prop-types' import { Card, @@ -7,292 +7,35 @@ import { Typography, Flex, Modal, - Form, - Input, - Switch, Spin, Alert, message, - Divider, - Tag, Dropdown } from 'antd' -import { CaretLeftFilled, LoadingOutlined } from '@ant-design/icons' +import { LoadingOutlined } from '@ant-design/icons' import PlusIcon from '../../Icons/PlusIcon' -import BinIcon from '../../Icons/BinIcon' -import PersonIcon from '../../Icons/PersonIcon' -import TimeDisplay from './TimeDisplay' -import MarkdownDisplay from './MarkdownDisplay' -import axios from 'axios' -import config from '../../../config' import { AuthContext } from '../context/AuthContext' import { ApiServerContext } from '../context/ApiServerContext' import InfoCircleIcon from '../../Icons/InfoCircleIcon' -import IdDisplay from './IdDisplay' import ReloadIcon from '../../Icons/ReloadIcon' -import ExclamationOctagonIcon from '../../Icons/ExclamationOctagonIcon' -import ObjectProperty from './ObjectProperty' +import NewNote from '../Management/Notes/NewNote' +import NoteItem from './NoteItem' -const { Text, Title } = Typography -const { TextArea } = Input +const { Text } = Typography -const NoteItem = ({ - note, - expandedNotes, - setExpandedNotes, - fetchData, - onNewNote, - onDeleteNote, - userProfile, - onChildNoteAdded -}) => { - const [childNotes, setChildNotes] = useState({}) - const [loadingChildNotes, setLoadingChildNotes] = useState(null) - - const isExpanded = expandedNotes[note._id] - const hasChildNotes = childNotes[note._id] && childNotes[note._id].length > 0 - const isThisNoteLoading = loadingChildNotes === note._id - - let transformValue = 'rotate(0deg)' - if (isExpanded) { - transformValue = 'rotate(-90deg)' - } - - const handleNoteExpand = async (noteId) => { - const newExpandedState = !expandedNotes[noteId] - - setExpandedNotes((prev) => ({ - ...prev, - [noteId]: newExpandedState - })) - - if (newExpandedState && !childNotes[noteId]) { - setLoadingChildNotes(noteId) - try { - const childNotesData = await fetchData(noteId) - setChildNotes((prev) => ({ - ...prev, - [noteId]: childNotesData - })) - } catch (error) { - console.error('Error fetching child notes:', error) - } finally { - setLoadingChildNotes(null) - } - } - } - - const handleNewChildNote = () => { - if (onNewNote) { - onNewNote(note._id) - } - } - - const handleDeleteNote = () => { - if (onDeleteNote) { - onDeleteNote(note._id) - } - } - - // Reload child notes when a new child note is added - const reloadChildNotes = useCallback(async () => { - // Always fetch child notes when this function is called - // This ensures child notes are loaded even if the parent wasn't expanded before - setLoadingChildNotes(note._id) - try { - const childNotesData = await fetchData(note._id) - setChildNotes((prev) => ({ - ...prev, - [note._id]: childNotesData - })) - } catch (error) { - console.error('Error fetching child notes:', error) - } finally { - setLoadingChildNotes(null) - } - }, [fetchData, note._id]) - - // Listen for child note additions - useEffect(() => { - if (onChildNoteAdded) { - onChildNoteAdded(note._id, reloadChildNotes) - } - }, [note._id, onChildNoteAdded, reloadChildNotes]) - - // Check if the current user can delete this note - const canDeleteNote = userProfile && userProfile._id === note.user._id - - const dropdownItems = [ - { - key: 'new', - icon: , - label: 'New Note', - onClick: handleNewChildNote - } - ] - - // Only add delete option if user owns the note - if (canDeleteNote) { - dropdownItems.push({ - key: 'delete', - label: 'Delete Note', - icon: , - onClick: handleDeleteNote, - danger: true - }) - } - - return ( - - - - - - {note.user.name}: - -
- -
-
- - - - - - - Type: - - {note.noteType.name} - - - - User ID: - - - - Created At: - - - - -