diff --git a/.flowconfig b/.flowconfig deleted file mode 100644 index 786366c..0000000 --- a/.flowconfig +++ /dev/null @@ -1,74 +0,0 @@ -[ignore] -; We fork some components by platform -.*/*[.]android.js - -; Ignore "BUCK" generated dirs -/\.buckd/ - -; Ignore polyfills -node_modules/react-native/Libraries/polyfills/.* - -; These should not be required directly -; require from fbjs/lib instead: require('fbjs/lib/warning') -node_modules/warning/.* - -; Flow doesn't support platforms -.*/Libraries/Utilities/LoadingView.js - -[untyped] -.*/node_modules/@react-native-community/cli/.*/.* - -[include] - -[libs] -node_modules/react-native/interface.js -node_modules/react-native/flow/ - -[options] -emoji=true - -esproposal.optional_chaining=enable -esproposal.nullish_coalescing=enable - -module.file_ext=.js -module.file_ext=.json -module.file_ext=.ios.js - -munge_underscores=true - -module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' -module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' - -suppress_type=$FlowIssue -suppress_type=$FlowFixMe -suppress_type=$FlowFixMeProps -suppress_type=$FlowFixMeState - -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ -suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError - -[lints] -sketchy-null-number=warn -sketchy-null-mixed=warn -sketchy-number=warn -untyped-type-import=warn -nonstrict-import=warn -deprecated-type=warn -unsafe-getters-setters=warn -inexact-spread=warn -unnecessary-invariant=warn -signature-verification-failure=warn -deprecated-utility=error - -[strict] -deprecated-type -nonstrict-import -sketchy-null -unclear-type -unsafe-getters-setters -untyped-import -untyped-type-import - -[version] -^0.113.0 diff --git a/App.js b/App.js index 23cd158..850bd79 100644 --- a/App.js +++ b/App.js @@ -1,113 +1,145 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - * - * @format - * @flow strict-local - */ - -import React from 'react'; +import React, {useState, useCallback, useRef} from 'react'; import { SafeAreaView, StyleSheet, ScrollView, View, Text, + Button, + TextInput, StatusBar, } from 'react-native'; +import storage from './storage'; +import apiFactory from '@sammacbeth/dat-api-v1'; -import { - Header, - LearnMoreLinks, - Colors, - DebugInstructions, - ReloadInstructions, -} from 'react-native/Libraries/NewAppScreen'; +const defaultAddress = + '41f8a987cfeba80a037e51cc8357d513b62514de36f2f9b3d3eeec7a8fb3b5a5'; + +// create an API using file persistence +const api = apiFactory({ + persistantStorageFactory: address => + Promise.resolve(file => storage('hyperdrive')(`${address}/${file}`)), +}); + +const load = async address => { + // load an existing dat in memory + const existing = await api.getDat(address, { + persist: true, + driveOptions: { + sparse: true, + }, + }); -const App: () => React$Node = () => { + // wait for data + await new Promise(async (resolve, reject) => { + setTimeout(reject.bind(null, 'timeout'), 10000); + await existing.ready; + resolve(); + }); + + const files = await new Promise((resolve, reject) => { + existing.drive.readdir('/', (err, files) => { + if (err) { + return reject('error listing directory'); + } + resolve(files); + }); + }); + return files; +}; + +const App = () => { + const [files, setFiles] = useState([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + const [address, setAddress] = useState(defaultAddress); + const inputRef = useRef(); + const loadCallback = useCallback(async () => { + setLoading(true); + setError(false); + try { + const newFiles = await load(address); + setFiles(newFiles); + } catch (e) { + setError(e); + } + setLoading(false); + }, [address]); return ( <> - - -
- {global.HermesInternal == null ? null : ( - - Engine: Hermes - - )} - - - Step One - - Edit App.js to change this - screen and then come back to see your edits. - - - - See Your Changes - - - - - - Debug - - - - - - Learn More - - Read the docs to discover what to do next: - - - + + + + +