chore: don't show convert as-is button when changing to super if text is not json
This commit is contained in:
@@ -18,8 +18,18 @@ type Props = {
|
|||||||
onComplete: () => void
|
onComplete: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidJson(string: string) {
|
||||||
|
try {
|
||||||
|
JSON.parse(string)
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application, closeDialog, onComplete }) => {
|
export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application, closeDialog, onComplete }) => {
|
||||||
const isSeamlessConvert = note.text.length === 0
|
const isSeamlessConvert = note.text.length === 0
|
||||||
|
const canBeConvertedAsIs = isValidJson(note.text)
|
||||||
const [lastValue, setLastValue] = useState({ text: '', previewPlain: '' })
|
const [lastValue, setLastValue] = useState({ text: '', previewPlain: '' })
|
||||||
|
|
||||||
const format =
|
const format =
|
||||||
@@ -79,8 +89,8 @@ export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application,
|
|||||||
onComplete()
|
onComplete()
|
||||||
}, [closeDialog, application, note, onComplete, performConvert])
|
}, [closeDialog, application, note, onComplete, performConvert])
|
||||||
|
|
||||||
const modalActions: ModalAction[] = useMemo(
|
const modalActions = useMemo(
|
||||||
() => [
|
(): ModalAction[] => [
|
||||||
{
|
{
|
||||||
label: 'Cancel',
|
label: 'Cancel',
|
||||||
onClick: closeDialog,
|
onClick: closeDialog,
|
||||||
@@ -97,9 +107,10 @@ export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application,
|
|||||||
label: 'Convert As-Is',
|
label: 'Convert As-Is',
|
||||||
onClick: convertAsIs,
|
onClick: convertAsIs,
|
||||||
type: 'secondary',
|
type: 'secondary',
|
||||||
|
hidden: !canBeConvertedAsIs,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[closeDialog, confirmConvert, convertAsIs],
|
[canBeConvertedAsIs, closeDialog, confirmConvert, convertAsIs],
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isSeamlessConvert) {
|
if (isSeamlessConvert) {
|
||||||
|
|||||||
Reference in New Issue
Block a user