diff --git a/src/components/index.ts b/src/components/index.ts index 063eff7c..760fbb08 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -13,3 +13,4 @@ export { default as ColorPreferenceItem } from './ColorPreferenceItem/ColorPrefe export { default as LoadingMoreIndicator } from './LoadingMoreIndicator/LoadingMoreIndicator'; export { Checkbox } from './Checkbox/Checkbox'; export { RadioButton } from './RadioButton/RadioButton'; +export { default as ConfirmationDialog } from './ConfirmationDialog/ConfirmationDialog'; diff --git a/src/screens/settings/SettingsReaderScreen/Modals/CustomFileModal.tsx b/src/screens/settings/SettingsReaderScreen/Modals/CustomFileModal.tsx new file mode 100644 index 00000000..a0d8d6f1 --- /dev/null +++ b/src/screens/settings/SettingsReaderScreen/Modals/CustomFileModal.tsx @@ -0,0 +1,130 @@ +import React, { useState } from 'react'; +import { StyleSheet, Text, View } from 'react-native'; +import { Modal, overlay, TextInput } from 'react-native-paper'; +import { StorageAccessFramework } from 'expo-file-system'; +import * as DocumentPicker from 'expo-document-picker'; + +import { Button } from '@components/index'; + +import { showToast } from '@utils/showToast'; +import { useTheme } from '@hooks/persisted'; +import { getString } from '@strings/translations'; + +interface CustomFileModal { + visible: boolean; + onDismiss: () => void; + defaultValue: string; + onSave: (val: string) => void; + title: string; + mimeType: 'text/css' | 'application/javascript'; + openFileLabel: string; + placeholder?: string; + description?: string; +} + +const CustomFileModal: React.FC = ({ + onDismiss, + visible, + defaultValue, + onSave, + title, + mimeType, + openFileLabel, + placeholder, + description, +}) => { + const theme = useTheme(); + const [text, setText] = useState(''); + + const openDocumentPicker = async () => { + try { + const file = await DocumentPicker.getDocumentAsync({ + copyToCacheDirectory: false, + type: mimeType, + }); + + if (file.type === 'success') { + const content = await StorageAccessFramework.readAsStringAsync( + file.uri, + ); + + onSave(content.trim()); + onDismiss(); + } + } catch (error: any) { + showToast(error.message); + } + }; + + return ( + + + {title} + + {description} + + +