fix: Files uploaded to a protected Super note will also be marked as protected

This commit is contained in:
Aman Harwara
2023-03-30 12:19:15 +05:30
parent 08a20e25b4
commit 09fd65903b
3 changed files with 15 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ import { FilesController } from '@/Controllers/FilesController'
import { LinkingController } from '@/Controllers/LinkingController' import { LinkingController } from '@/Controllers/LinkingController'
import { SNNote } from '@standardnotes/snjs' import { SNNote } from '@standardnotes/snjs'
import { useEffect } from 'react' import { useEffect } from 'react'
import { useApplication } from '../ApplicationProvider'
import { useFileDragNDrop } from '../FileDragNDropProvider' import { useFileDragNDrop } from '../FileDragNDropProvider'
type Props = { type Props = {
@@ -12,6 +13,7 @@ type Props = {
} }
const NoteViewFileDropTarget = ({ note, linkingController, noteViewElement, filesController }: Props) => { const NoteViewFileDropTarget = ({ note, linkingController, noteViewElement, filesController }: Props) => {
const application = useApplication()
const { isDraggingFiles, addDragTarget, removeDragTarget } = useFileDragNDrop() const { isDraggingFiles, addDragTarget, removeDragTarget } = useFileDragNDrop()
useEffect(() => { useEffect(() => {
@@ -22,6 +24,9 @@ const NoteViewFileDropTarget = ({ note, linkingController, noteViewElement, file
tooltipText: 'Drop your files to upload and link them to the current note', tooltipText: 'Drop your files to upload and link them to the current note',
callback: async (uploadedFile) => { callback: async (uploadedFile) => {
await linkingController.linkItems(note, uploadedFile) await linkingController.linkItems(note, uploadedFile)
void application.mutator.changeAndSaveItem(uploadedFile, (mutator) => {
mutator.protected = note.protected
})
filesController.notifyObserversOfUploadedFileLinkingToCurrentNote(uploadedFile.uuid) filesController.notifyObserversOfUploadedFileLinkingToCurrentNote(uploadedFile.uuid)
}, },
}) })
@@ -32,7 +37,7 @@ const NoteViewFileDropTarget = ({ note, linkingController, noteViewElement, file
removeDragTarget(target) removeDragTarget(target)
} }
} }
}, [addDragTarget, linkingController, note, noteViewElement, removeDragTarget, filesController]) }, [addDragTarget, linkingController, note, noteViewElement, removeDragTarget, filesController, application.mutator])
return isDraggingFiles ? ( return isDraggingFiles ? (
// Required to block drag events to editor iframe // Required to block drag events to editor iframe

View File

@@ -16,8 +16,11 @@ import { $wrapNodeInElement, mergeRegister } from '@lexical/utils'
import { useFilesController } from '@/Controllers/FilesControllerProvider' import { useFilesController } from '@/Controllers/FilesControllerProvider'
import { FilesControllerEvent } from '@/Controllers/FilesController' import { FilesControllerEvent } from '@/Controllers/FilesController'
import { useLinkingController } from '@/Controllers/LinkingControllerProvider' import { useLinkingController } from '@/Controllers/LinkingControllerProvider'
import { useApplication } from '@/Components/ApplicationProvider'
import { SNNote } from '@standardnotes/snjs'
export default function FilePlugin(): JSX.Element | null { export default function FilePlugin({ currentNote }: { currentNote: SNNote }): JSX.Element | null {
const application = useApplication()
const [editor] = useLexicalComposerContext() const [editor] = useLexicalComposerContext()
const filesController = useFilesController() const filesController = useFilesController()
const linkingController = useLinkingController() const linkingController = useLinkingController()
@@ -34,6 +37,9 @@ export default function FilePlugin(): JSX.Element | null {
if (uploadedFile) { if (uploadedFile) {
editor.dispatchCommand(INSERT_FILE_COMMAND, uploadedFile.uuid) editor.dispatchCommand(INSERT_FILE_COMMAND, uploadedFile.uuid)
void linkingController.linkItemToSelectedItem(uploadedFile) void linkingController.linkItemToSelectedItem(uploadedFile)
void application.mutator.changeAndSaveItem(uploadedFile, (mutator) => {
mutator.protected = currentNote.protected
})
} }
} catch (error) { } catch (error) {
console.error(error) console.error(error)
@@ -70,7 +76,7 @@ export default function FilePlugin(): JSX.Element | null {
COMMAND_PRIORITY_NORMAL, COMMAND_PRIORITY_NORMAL,
), ),
) )
}, [editor, filesController, linkingController]) }, [application.mutator, currentNote.protected, editor, filesController, linkingController])
useEffect(() => { useEffect(() => {
const disposer = filesController.addEventObserver((event, data) => { const disposer = filesController.addEventObserver((event, data) => {

View File

@@ -183,7 +183,7 @@ export const SuperEditor: FunctionComponent<Props> = ({
spellcheck={spellcheck} spellcheck={spellcheck}
> >
<ItemSelectionPlugin currentNote={note.current} /> <ItemSelectionPlugin currentNote={note.current} />
<FilePlugin /> <FilePlugin currentNote={note.current} />
<ItemBubblePlugin /> <ItemBubblePlugin />
<BlockPickerMenuPlugin /> <BlockPickerMenuPlugin />
<GetMarkdownPlugin ref={getMarkdownPlugin} /> <GetMarkdownPlugin ref={getMarkdownPlugin} />