import React, {Fragment, useEffect, useRef, useState} from 'react'; import {Platform, StyleSheet, TouchableOpacity, View} from 'react-native'; import FileViewer from 'react-native-file-viewer'; import Share from 'react-native-share'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {notesnook} from '../../../e2e/test.ids'; import {useTracked} from '../../provider'; import {DDS} from '../../services/DeviceDetection'; import {ToastEvent} from '../../services/EventManager'; import Exporter from '../../services/Exporter'; import {getElevation} from '../../utils'; import {ph, pv, SIZE} from '../../utils/SizeUtils'; import {sleep} from '../../utils/TimeUtils'; import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper'; import {GetPremium} from '../ActionSheetComponent/GetPremium'; import {Button} from '../Button'; import BaseDialog from '../Dialog/base-dialog'; import DialogButtons from '../Dialog/dialog-buttons'; import DialogHeader from '../Dialog/dialog-header'; import {PressableButton} from '../PressableButton'; import Seperator from '../Seperator'; import Heading from '../Typography/Heading'; import Paragraph from '../Typography/Paragraph'; const { eSubscribeEvent, eUnSubscribeEvent } = require('../../services/EventManager'); const { eOpenExportDialog, eCloseExportDialog, eShowGetPremium } = require('../../utils/Events'); const ExportDialog = () => { const [state] = useTracked(); const {colors} = state; const [visible, setVisible] = useState(false); const actionSheetRef = useRef(); const [notes, setNotes] = useState([]); const [exporting, setExporting] = useState(false); const [complete, setComplete] = useState(false); const [doneText, setDoneText] = useState(null); const [result, setResult] = useState({}); useEffect(() => { eSubscribeEvent(eOpenExportDialog, open); eSubscribeEvent(eCloseExportDialog, close); return () => { eUnSubscribeEvent(eOpenExportDialog, open); eUnSubscribeEvent(eCloseExportDialog, close); }; }, []); const open = data => { setVisible(true); setNotes(data); }; const close = data => { setComplete(false); setExporting(false); setVisible(false); setNotes([]); }; const save = async (func, name) => { if (exporting) return; setExporting(true); setComplete(false); let res; for (var i = 0; i < notes.length; i++) { let note = notes[i]; res = await func(note); if (!res) { setExporting(false); return; } } setDoneText( `Note exported successfully! You can find the exported note in ${ Platform.OS === 'ios' ? 'Files Manager/Notesnook' : `Storage/Notesnook/exported/${name}` }.` ); setResult(res); setExporting(false); setComplete(true); }; useEffect(() => { if (visible) { actionSheetRef.current.show(); } }, [visible]); const actions = [ { title: 'PDF', func: async () => { await save(Exporter.saveToPDF, 'PDF'); }, icon: 'file-pdf-box', desc: 'Can be opened in a pdf reader like Adobe or Foxit Reader', id: notesnook.ids.dialogs.export.pdf }, { title: 'Markdown', func: async () => { await save(Exporter.saveToMarkdown, 'Markdown'); }, icon: 'language-markdown', desc: 'Can be opened in any text or markdown editor', id: notesnook.ids.dialogs.export.md }, { title: 'Plain Text', func: async () => { await save(Exporter.saveToText, 'Text'); }, icon: 'card-text', desc: 'Can be opened in any text editor', id: notesnook.ids.dialogs.export.text }, { title: 'HTML', func: async () => { await save(Exporter.saveToHTML, 'Html'); }, icon: 'language-html5', desc: 'Can be opened in any web browser', id: notesnook.ids.dialogs.export.html } ]; return !visible ? null : ( {actions.map(item => ( {item.title} {item.desc} ))} {complete && ( <>