mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 15:29:15 +01:00
reorg again, absolute (module) imports
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Text, View } from 'react-native'
|
||||
import RNFS from 'react-native-fs'
|
||||
import paths from '@app/util/paths'
|
||||
|
||||
async function mkdir(path: string): Promise<void> {
|
||||
const exists = await RNFS.exists(path)
|
||||
if (exists) {
|
||||
const isDir = (await RNFS.stat(path)).isDirectory()
|
||||
if (!isDir) {
|
||||
throw new Error(`path exists and is not a directory: ${path}`)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return await RNFS.mkdir(path)
|
||||
}
|
||||
|
||||
const SplashPage: React.FC<{}> = ({ children }) => {
|
||||
const [ready, setReady] = useState(false)
|
||||
|
||||
const minSplashTime = new Promise(resolve => setTimeout(resolve, 1))
|
||||
|
||||
const prepare = async () => {
|
||||
await mkdir(paths.imageCache)
|
||||
await mkdir(paths.songCache)
|
||||
await mkdir(paths.songs)
|
||||
}
|
||||
|
||||
const promise = Promise.all([prepare(), minSplashTime])
|
||||
|
||||
useEffect(() => {
|
||||
promise.then(() => {
|
||||
setReady(true)
|
||||
})
|
||||
})
|
||||
|
||||
if (!ready) {
|
||||
return <Text>Loading THE GOOD SHIT...</Text>
|
||||
}
|
||||
return <View style={{ flex: 1 }}>{children}</View>
|
||||
}
|
||||
|
||||
export default SplashPage
|
||||
Reference in New Issue
Block a user