chore: dont show embedded file export options if no selected super note has them

This commit is contained in:
Aman Harwara
2023-11-11 22:17:32 +05:30
parent 991a7a521f
commit 7d9dabb818
3 changed files with 9 additions and 5 deletions

View File

@@ -504,7 +504,7 @@ const NotesOptions = ({ notes, closeMenu }: NotesOptionsProps) => {
)} )}
<ModalOverlay isOpen={showExportSuperModal} close={closeSuperExportModal}> <ModalOverlay isOpen={showExportSuperModal} close={closeSuperExportModal}>
<SuperExportModal exportNotes={downloadSelectedItems} close={closeSuperExportModal} /> <SuperExportModal notes={notes} exportNotes={downloadSelectedItems} close={closeSuperExportModal} />
</ModalOverlay> </ModalOverlay>
</> </>
) )

View File

@@ -1,17 +1,19 @@
import { PrefKey, PrefValue } from '@standardnotes/snjs' import { PrefKey, PrefValue, SNNote } from '@standardnotes/snjs'
import { useApplication } from '../ApplicationProvider' import { useApplication } from '../ApplicationProvider'
import Modal from '../Modal/Modal' import Modal from '../Modal/Modal'
import usePreference from '@/Hooks/usePreference' import usePreference from '@/Hooks/usePreference'
import RadioButtonGroup from '../RadioButtonGroup/RadioButtonGroup' import RadioButtonGroup from '../RadioButtonGroup/RadioButtonGroup'
import { useEffect } from 'react' import { useEffect } from 'react'
import Switch from '../Switch/Switch' import Switch from '../Switch/Switch'
import { noteHasEmbeddedFiles } from '@/Utils/NoteExportUtils'
type Props = { type Props = {
notes: SNNote[]
exportNotes: () => void exportNotes: () => void
close: () => void close: () => void
} }
const SuperExportModal = ({ exportNotes, close }: Props) => { const SuperExportModal = ({ notes, exportNotes, close }: Props) => {
const application = useApplication() const application = useApplication()
const superNoteExportFormat = usePreference(PrefKey.SuperNoteExportFormat) const superNoteExportFormat = usePreference(PrefKey.SuperNoteExportFormat)
const superNoteExportEmbedBehavior = usePreference(PrefKey.SuperNoteExportEmbedBehavior) const superNoteExportEmbedBehavior = usePreference(PrefKey.SuperNoteExportEmbedBehavior)
@@ -26,6 +28,8 @@ const SuperExportModal = ({ exportNotes, close }: Props) => {
} }
}, [application, superNoteExportEmbedBehavior, superNoteExportFormat]) }, [application, superNoteExportEmbedBehavior, superNoteExportFormat])
const someNotesHaveEmbeddedFiles = notes.some(noteHasEmbeddedFiles)
return ( return (
<Modal <Modal
title="Export notes" title="Export notes"
@@ -89,7 +93,7 @@ const SuperExportModal = ({ exportNotes, close }: Props) => {
</Switch> </Switch>
</div> </div>
)} )}
{superNoteExportFormat !== 'json' && ( {superNoteExportFormat !== 'json' && someNotesHaveEmbeddedFiles && (
<div className="mb-2 mt-4"> <div className="mb-2 mt-4">
<div className="mb-1">How do you want embedded files to be handled?</div> <div className="mb-1">How do you want embedded files to be handled?</div>
<RadioButtonGroup <RadioButtonGroup

View File

@@ -120,7 +120,7 @@ const isSuperNote = (note: SNNote) => {
return note.noteType === NoteType.Super return note.noteType === NoteType.Super
} }
const noteHasEmbeddedFiles = (note: SNNote) => { export const noteHasEmbeddedFiles = (note: SNNote) => {
return note.text.includes('"type":"snfile"') return note.text.includes('"type":"snfile"')
} }