-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miha/Kevin Audio Download/Delete #35
base: main
Are you sure you want to change the base?
Changes from 26 commits
e9aab74
724a6b4
7fce26a
ee67dd4
297abbd
58ae47a
6b23313
c3751f8
396ff91
9248eac
80e1438
4d31cad
a282d01
dc06797
898fa7b
9506462
f244217
66c8867
41a5595
6939605
244b6c7
1dc8283
1dadd2a
75afca6
4fd70b4
f3ef226
1950b21
c6fdef5
36dee18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"editor.formatOnSave": true | ||
"editor.formatOnSave": true, | ||
"git.ignoreLimitWarning": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ import * as Font from 'expo-font'; | |
import * as SplashScreen from 'expo-splash-screen'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
|
||
import RootNavigation from './src/navigation/RootNavigator'; | ||
// import QueriesDemo from './src/firebase/QueriesDemo'; | ||
// import AudioDemos from './src/firebase/AudioDemos'; | ||
|
||
async function loadResourcesAsync() { | ||
await Promise.all([ | ||
|
@@ -50,12 +53,14 @@ export default function App() { | |
// loading its initial state and rendering its first pixels. So instead, | ||
// we hide the splash screen once we know the root view has already | ||
// performed layout. | ||
|
||
await SplashScreen.hideAsync(); | ||
} | ||
}, [resourcesLoaded]); | ||
|
||
return !resourcesLoaded ? null : ( | ||
<View style={styles.container} onLayout={onLayoutRootView}> | ||
{/* <AudioDemos /> */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
<RootNavigation /> | ||
</View> | ||
); | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we shouldn't be using an audio demos file, move this elsewhere or delete the file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Simple demo component that renders a list of all grants. | ||
*/ | ||
|
||
import { useState } from 'react'; | ||
import { Button, Text, TextInput, View } from 'react-native'; | ||
import { getInfoAsync } from 'expo-file-system'; | ||
import { Audio } from '../types/schema'; | ||
// import { getAllAudio, getAudioID } from './queries/audioQueries'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
import { downLoadAudio, deleteAudio } from './queries/audioPlayback'; | ||
|
||
export default function QueriesDemo() { | ||
const [audio] = useState<Audio[]>([]); | ||
// eslint-disable-next-line camelcase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to camelcase |
||
const [audio_id, setAudioId] = useState<string>(''); | ||
/* fetch all audio on page load */ | ||
const handlePress = async () => { | ||
const audios = await downLoadAudio(audio_id); | ||
const didItDownload = await getInfoAsync(audios); | ||
// eslint-disable-next-line no-console | ||
console.log(didItDownload); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isDownloaded instead |
||
|
||
deleteAudio(audios); | ||
const didItDelete = await getInfoAsync(audios); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isDeleted instead |
||
// eslint-disable-next-line no-console | ||
console.log(didItDelete); | ||
}; | ||
|
||
// useEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be removed |
||
// const fetchData2 = async () => { | ||
// try { | ||
// console.log('hello'); | ||
// const allAudio1 = await downLoadAudio('1420969939'); | ||
// console.log(allAudio1); | ||
// } catch (error) { | ||
// // eslint-disable-next-line no-console | ||
// console.error('(useEffect)[AudioDemos]', error); | ||
// } | ||
// }; | ||
// fetchData2(); | ||
// }, []); | ||
|
||
return ( | ||
<View> | ||
<Text>{`All Audio (${audio.length})`}</Text> | ||
{audio.map(audios => ( | ||
<View key={audios.audio_id}> | ||
<Text>{`title: ${audios.title} | id: ${audios.audio_id}`}</Text> | ||
<Text>{`description: ${audios.description}`}</Text> | ||
<Text>{`link: ${audios.gcsLink}`}</Text> | ||
</View> | ||
))} | ||
<TextInput placeholder="ID to be queried" onChangeText={setAudioId} /> | ||
<Button title="Download" onPress={() => handlePress()} /> | ||
</View> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
documentDirectory, | ||
createDownloadResumable, | ||
deleteAsync, | ||
} from 'expo-file-system'; | ||
import { getAudioID } from './audioQueries'; | ||
|
||
export const downLoadAudio = async (audioID: string): Promise<string> => { | ||
const name = audioID; | ||
const url = (await getAudioID(audioID)).gcsLink; | ||
const dir = `${documentDirectory}${name}.mp3`; | ||
const downLoadable = createDownloadResumable(url, dir, {}); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const uri = await downLoadable.downloadAsync(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do we do with this uri? |
||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error(e); | ||
} | ||
return dir; | ||
}; | ||
|
||
export const deleteAudio = async (audioPath: string): Promise<void> => | ||
deleteAsync(audioPath); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
collection, | ||
doc, | ||
DocumentSnapshot, | ||
getDoc, | ||
getDocs, | ||
getFirestore, | ||
} from 'firebase/firestore'; | ||
import { Audio } from '../../types/schema'; | ||
import firebaseApp from '../firebaseApp'; | ||
|
||
const db = getFirestore(firebaseApp); | ||
|
||
const parseAudio = async (docSnap: DocumentSnapshot) => { | ||
const data = docSnap.data(); | ||
|
||
const audio = { | ||
audio_id: data?.audio_id, | ||
title: data?.title, | ||
description: data?.description, | ||
authors: data?.authors, | ||
audio_file: data?.audio_file, | ||
soundCloud: data?.soundCloud, | ||
theme: data?.theme, | ||
gcsLink: data?.gcsLink, | ||
thumbnail: data?.thumbnail, | ||
}; | ||
|
||
return audio as Audio; | ||
}; | ||
|
||
/** | ||
* Get all grants from the `grants` collection. | ||
*/ | ||
export const getAllAudio = async (): Promise<Audio[]> => { | ||
try { | ||
const itemsRef = collection(db, 'audio'); | ||
const promises: Promise<Audio>[] = []; | ||
const docSnap = await getDocs(itemsRef); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
docSnap.forEach((audio: any) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the audio should have a type |
||
promises.push(parseAudio(audio)); | ||
}); | ||
const audio = await Promise.all(promises); | ||
return audio; | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.warn(e); | ||
throw e; | ||
} | ||
}; | ||
|
||
export const getAudioID = async (audioId: string): Promise<Audio> => { | ||
try { | ||
const docRef = doc(db, 'audio', audioId); | ||
const docSnap = await getDoc(docRef); | ||
return await parseAudio(docSnap); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error(e); | ||
throw e; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,46 @@ | ||
import { Image, Text, View } from 'react-native'; | ||
// import { Image, Text, View } from 'react-native'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
import { useState } from 'react'; | ||
import { Button, Image, Text, TextInput, View } from 'react-native'; | ||
import { getInfoAsync } from 'expo-file-system'; | ||
import Icon from '../../../assets/icons'; | ||
import Colors from '../../styles/Colors'; | ||
import styles from './styles'; | ||
import { getAudioID } from '../../firebase/queries/audioQueries'; | ||
|
||
import { | ||
downLoadAudio, | ||
deleteAudio, | ||
} from '../../firebase/queries/audioPlayback'; | ||
|
||
// export const getImage = async (audioID: string): Promise<string> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
// const thumNail = (await getAudioID(audioID)).thumbnail; | ||
// return thumNail | ||
// } | ||
|
||
function PlayScreen() { | ||
const [audioId, setAudioId] = useState<string>(''); | ||
// eslint-disable-next-line no-var | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
// var a = ''; | ||
// getImage(audioId).then((holder) => { | ||
|
||
// a = holder | ||
// console.log('INSIDE'); | ||
// console.log(a); | ||
// }); | ||
|
||
/* fetch all audio on page load */ | ||
const handlePress = async () => { | ||
const audios = await downLoadAudio(audioId); | ||
const didItDownload = await getInfoAsync(audios); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isDownloaded |
||
// eslint-disable-next-line no-console | ||
console.log(didItDownload); | ||
|
||
deleteAudio(audios); | ||
const didItDelete = await getInfoAsync(audios); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isDeleted |
||
// eslint-disable-next-line no-console | ||
console.log(didItDelete); | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View | ||
|
@@ -22,7 +59,19 @@ function PlayScreen() { | |
</Text> | ||
</View> | ||
<View style={styles.container2}> | ||
{/* <Image | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
{styles={ | ||
height: 275, | ||
width: 275, | ||
backgroundColor: Colors.surfaceGrey, | ||
borderRadius: 9.5, | ||
marginTop: '3%', | ||
marginBottom: '3%', | ||
}} | ||
|
||
/> */} | ||
<Image | ||
source={{}} | ||
style={{ | ||
height: 275, | ||
width: 275, | ||
|
@@ -46,6 +95,15 @@ function PlayScreen() { | |
<Icon type="play_button" /> | ||
<Icon type="audio_forward" /> | ||
</View> | ||
<View | ||
style={{ | ||
paddingBottom: '7%', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. styles should be extracted to a file |
||
paddingLeft: '7%', | ||
}} | ||
> | ||
<TextInput placeholder="ID to be queried" onChangeText={setAudioId} /> | ||
<Button title="Download" onPress={() => handlePress()} /> | ||
</View> | ||
|
||
<View | ||
style={{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be removed