-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Huge note revamp; added markdown and note insertion into board
- Loading branch information
1 parent
9609a74
commit fba7309
Showing
13 changed files
with
917 additions
and
114 deletions.
There are no files selected for viewing
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,111 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
import Markdown from 'react-markdown'; | ||
import { useNotesStore } from '@/lib/hooks/stores/useNotesStore'; | ||
|
||
interface NotesEditorProps { | ||
id: string | number; | ||
showDisplayOption?: boolean; | ||
className?: string; | ||
title?: string; | ||
} | ||
|
||
export default function NotesEditor({ | ||
id, | ||
showDisplayOption = false, | ||
title, | ||
}: NotesEditorProps) { | ||
const { notes, setNote } = useNotesStore(); | ||
const [isEditing, setIsEditing] = useState(false); | ||
const [editValue, setEditValue] = useState(notes[id]?.note || ''); | ||
const [displayNextToSemester, setDisplayNextToSemester] = useState( | ||
notes[id]?.displayNextToSemester || false | ||
); | ||
const textAreaRef = useRef<HTMLTextAreaElement>(null); | ||
|
||
useEffect(() => { | ||
if (textAreaRef.current) { | ||
textAreaRef.current.style.height = 'auto'; | ||
textAreaRef.current.style.height = | ||
textAreaRef.current.scrollHeight + 'px'; | ||
} | ||
}, [editValue, isEditing]); | ||
|
||
const handleSave = () => { | ||
setNote(id, { | ||
note: editValue, | ||
displayNextToSemester, | ||
}); | ||
setIsEditing(false); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className='mb-2 flex items-center justify-between'> | ||
{title && <h2 className='text-lg font-bold'>{title}</h2>} | ||
{!title && <h3 className='text-sm font-medium'>Notes:</h3>} | ||
<button | ||
onClick={isEditing ? handleSave : () => setIsEditing(true)} | ||
className='text-sm text-blue-600 hover:text-blue-800' | ||
> | ||
{isEditing ? 'Save' : 'Edit'} | ||
</button> | ||
</div> | ||
|
||
{showDisplayOption && ( | ||
<div className='mb-2 flex items-center'> | ||
<input | ||
type='checkbox' | ||
checked={displayNextToSemester} | ||
onChange={(e) => { | ||
setDisplayNextToSemester(e.target.checked); | ||
setNote(id, { | ||
note: editValue, | ||
displayNextToSemester: e.target.checked, | ||
}); | ||
}} | ||
className='mr-2' | ||
/> | ||
<label className='text-sm text-gray-600'> | ||
Display next to semester | ||
</label> | ||
</div> | ||
)} | ||
|
||
{isEditing ? ( | ||
<div className='space-y-2'> | ||
<textarea | ||
ref={textAreaRef} | ||
value={editValue} | ||
onChange={(e) => setEditValue(e.target.value)} | ||
className='h-32 w-full rounded-md border px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500' | ||
placeholder='Add your notes here...' | ||
/> | ||
<div className='text-xs text-gray-500'> | ||
Markdown supported: **bold**, *italic*, # heading, - list, | ||
[link](url) | ||
<br /> | ||
<a | ||
href='https://www.markdownguide.org/basic-syntax/' | ||
target='_blank' | ||
rel='noopener noreferrer' | ||
className='text-blue-600 hover:text-blue-800' | ||
> | ||
Learn more about Markdown | ||
</a> | ||
</div> | ||
</div> | ||
) : ( | ||
<article | ||
className='prose prose-sm cursor-pointer overflow-scroll rounded-md p-2 hover:bg-gray-100' | ||
onClick={() => setIsEditing(true)} | ||
> | ||
{notes[id]?.note ? ( | ||
<Markdown>{notes[id].note}</Markdown> | ||
) : ( | ||
<span className='text-gray-500'>No notes added yet</span> | ||
)} | ||
</article> | ||
)} | ||
</div> | ||
); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
app/features/middlePanel/dashboard/components/NotesBox.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,17 @@ | ||
import { useNotesStore } from '@/lib/hooks/stores/useNotesStore'; | ||
import { useScheduleStore } from '@/lib/hooks/stores/useScheduleStore'; | ||
import { SemesterID } from '@/types/models'; | ||
import NotesEditor from '@/app/components/NotesEditor'; | ||
|
||
function NotesBox({ semesterID }: { semesterID: SemesterID }) { | ||
const notes = useNotesStore((state) => state.notes); | ||
const semester = useScheduleStore((state) => state.semesterByID[semesterID]); | ||
const { title } = semester; | ||
|
||
if (!notes[semesterID]) return null; | ||
if (!notes[semesterID].displayNextToSemester) return null; | ||
|
||
return <NotesEditor id={semesterID} title={title} />; | ||
} | ||
|
||
export default NotesBox; |
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
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
54 changes: 0 additions & 54 deletions
54
app/features/rightPanel/courseInfoDisplay/components/NotesArea.tsx
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -37,6 +37,7 @@ export const useSettingsStore = create<SettingsStore>()( | |
}), | ||
{ | ||
name: 'settings-storage', | ||
version: 1, | ||
} | ||
) | ||
); |
Oops, something went wrong.