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

View File

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