-
Notifications
You must be signed in to change notification settings - Fork 6
Redesign adding a new note #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
801ef2d
feat: redesign adding a new note
chmurson a692f5d
refactor: reuse useLatestCallback in few places
chmurson 68d53cf
fix: inconsistency in guards for null pageNumber and empty selectedBl…
chmurson 68cf5bb
feat: supprot adding labels
chmurson a64ee0a
fix: nitpick about clearing keepShowingNewNote ref
chmurson b97cd6f
fix: tests snapshots
chmurson 8e242cb
refactor: make NewNote component more compact
chmurson 95ef9e4
feat: auto focus on textarea + error on empty page
chmurson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
src/components/NoteManager/components/InactiveNoteSkeleton.tsx
This file contains hidden or 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,26 @@ | ||
| import { cn } from "@fluffylabs/shared-ui"; | ||
| import { NoteContainer } from "./SimpleComponents/NoteContainer"; | ||
|
|
||
| const skeletonLine = "rounded-md bg-gray-300/100 dark:bg-white/10"; | ||
|
|
||
| export const InactiveNoteSkeleton = ({ className }: { className?: string }) => ( | ||
| <NoteContainer | ||
| active={false} | ||
| aria-hidden="true" | ||
| className={cn( | ||
| "note relative rounded-xl p-4 bg-[var(--inactive-note-bg)] border border-[var(--border)]/60 select-none animate-pulse", | ||
| className, | ||
| )} | ||
| > | ||
| <div className="flex flex-col gap-3"> | ||
| <div className="flex items-center gap-2"> | ||
| <div className={cn("h-4 w-9/12 rounded-md bg-brand-primary/50")} /> | ||
| </div> | ||
| <div className="space-y-1"> | ||
| <div className={cn("h-4 w-full", skeletonLine)} /> | ||
| <div className={cn("h-4 w-11/12", skeletonLine)} /> | ||
| <div className={cn("h-4 w-8/12", skeletonLine)} /> | ||
| </div> | ||
| </div> | ||
| </NoteContainer> | ||
| ); |
This file contains hidden or 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,135 @@ | ||
| import type { ISynctexBlockId } from "@fluffylabs/links-metadata"; | ||
| import { Button } from "@fluffylabs/shared-ui"; | ||
| import { type ChangeEvent, useCallback, useMemo, useRef, useState } from "react"; | ||
| import { useLatestCallback } from "../../../hooks/useLatestCallback"; | ||
| import { validateMath } from "../../../utils/validateMath"; | ||
| import { type IDecoratedNote, NoteSource } from "../../NotesProvider/types/DecoratedNote"; | ||
| import type { INoteV3 } from "../../NotesProvider/types/StorageNote"; | ||
| import type { ISingleNoteContext } from "./NoteContext"; | ||
| import { NoteLayout } from "./NoteLayout"; | ||
| import { NoteContainer } from "./SimpleComponents/NoteContainer"; | ||
|
|
||
| type NewNoteProps = { | ||
| selectionStart: ISynctexBlockId; | ||
| selectionEnd: ISynctexBlockId; | ||
| version: string; | ||
| onCancel: () => void; | ||
| onSave: ({ noteContent }: { noteContent: string }) => void; | ||
| }; | ||
|
|
||
| export const NewNote = ({ selectionEnd, selectionStart, version, onCancel, onSave }: NewNoteProps) => { | ||
| const dateRef = useRef(new Date().getTime()); | ||
|
|
||
| const [noteContent, setNoteContent] = useState(""); | ||
| const [noteContentError, setNoteContentError] = useState<string | null>(null); | ||
|
|
||
| const latestOnCancel = useLatestCallback(onCancel); | ||
| const latestOnSave = useLatestCallback(onSave); | ||
|
|
||
| const handleCancelClick = useCallback(() => { | ||
| latestOnCancel.current(); | ||
| }, [latestOnCancel]); | ||
|
|
||
| const handleSaveClick = useCallback(() => { | ||
| const mathValidationError = validateMath(noteContent); | ||
| if (mathValidationError) { | ||
| setNoteContentError(mathValidationError); | ||
| return; | ||
| } | ||
|
|
||
| latestOnSave.current({ noteContent }); | ||
| }, [noteContent, latestOnSave]); | ||
|
|
||
| const currentVersionLink = ""; | ||
| const originalVersionLink = ""; | ||
|
|
||
| const handleNoteContentChange = useCallback((event: ChangeEvent<HTMLTextAreaElement>) => { | ||
| setNoteContent(event.target.value); | ||
| setNoteContentError(null); | ||
| }, []); | ||
|
|
||
| const noteDirty = useMemo( | ||
| () => | ||
| ({ | ||
| author: "", | ||
| content: noteContent, | ||
| labels: [], | ||
| date: dateRef.current, | ||
| noteVersion: 3, | ||
| selectionEnd, | ||
| selectionStart, | ||
| version, | ||
| }) satisfies INoteV3, | ||
| [noteContent, version, selectionStart, selectionEnd], | ||
| ); | ||
|
|
||
| const note = useMemo( | ||
| () => | ||
| ({ | ||
| current: { | ||
| isMigrated: true, | ||
| isUpToDate: true, | ||
| selectionEnd, | ||
| selectionStart, | ||
| version, | ||
| }, | ||
| key: "newNote", | ||
| original: { | ||
| author: "", | ||
| content: "", | ||
| date: dateRef.current, | ||
| labels: [], | ||
| noteVersion: 3, | ||
| selectionEnd, | ||
| selectionStart, | ||
| version, | ||
| }, | ||
| source: NoteSource.Local, | ||
| }) satisfies IDecoratedNote, | ||
| [selectionEnd, selectionStart, version], | ||
| ); | ||
|
|
||
| const noteLayoutContext = useMemo( | ||
| () => | ||
| ({ | ||
| active: true, | ||
| isEditable: true, | ||
| handleEditClick: () => {}, | ||
| handleSaveClick, | ||
| handleCancelClick, | ||
| onEditNote: () => {}, | ||
| isEditing: true, | ||
| note, | ||
| noteDirty, | ||
| handleNoteContentChange, | ||
| handleNoteLabelsChange: () => {}, | ||
| handleSelectNote: () => {}, | ||
| noteOriginalVersionShort: "", | ||
| currentVersionLink, | ||
| originalVersionLink, | ||
| }) satisfies ISingleNoteContext, | ||
| [noteDirty, handleNoteContentChange, note, handleCancelClick, handleSaveClick], | ||
| ); | ||
|
|
||
| return ( | ||
| <NoteLayout.Root value={noteLayoutContext}> | ||
| <NoteContainer active={true}> | ||
| <div className="flex flex-col gap-2"> | ||
| <NoteLayout.SelectedText /> | ||
| <NoteLayout.TextArea className={noteContentError ? "error" : ""} /> | ||
| {noteContentError ? <div className="validation-message">{noteContentError}</div> : null} | ||
| <NoteLayout.Labels /> | ||
| <div className="actions gap-2"> | ||
| <div className="fill" /> | ||
| <Button variant="tertiary" data-testid={"cancel-button"} onClick={handleCancelClick} size="sm"> | ||
| Cancel | ||
| </Button> | ||
| <Button data-testid={"save-button"} onClick={handleSaveClick} size="sm"> | ||
| Save | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </NoteContainer> | ||
| </NoteLayout.Root> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.