Skip to content

Commit

Permalink
Merge pull request #56 from Capstone-Projects-2021-Fall/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Phaceial committed Nov 1, 2021
2 parents 9a26618 + f8e60b4 commit 3072e29
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 2 additions & 4 deletions components/CatMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ export default function CatMap() {
const newState: Cat[] = [];

useEffect(() => {
catsRef.on('child_added', async (snapshot) => {
const picUri = await firebase.storage().ref().child(`${snapshot.val().accountID}/${snapshot.val().catID}/`).getDownloadURL();
newState.push({ ...snapshot.val(), media: picUri });

catsRef.on('child_added', (snapshot) => {
newState.push(snapshot.val());
setCats([...newState]);
});
}, []);
Expand Down
28 changes: 24 additions & 4 deletions screens/CatForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Platform,
} from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker';
import { add } from 'react-native-reanimated';
import { Cat } from '../types';
import { addCat, addPicture } from '../utils/dbInterface';
import LocationPicker from './LocationPicker';
Expand Down Expand Up @@ -103,15 +104,34 @@ export default CatForm = () => {
showMode('time');
};

function submitCat() {
async function submitCat() {
if (cat.media === '' || null) return alert('Add picture to report a cat');
if (cat.location === '' || null) return alert('Add location to report a cat');
if (cat.date === '' || null) return alert('Add date to report a cat');
if (cat.time === '' || null) return alert('Add time to report a cat');

addCat(cat);
addPicture(cat);
return alert('Cat submitted');
const response = await fetch(cat.media);
const blob = await response.blob();

const uploadTask = firebase
.storage()
.ref()
.child(`${firebase.auth().currentUser?.uid}/${cat.catID}`)
.put(blob);
uploadTask
.then((uploadTaskSnapshot) => {
// The upload is complete!
window.alert('Upload complete');

// In addition, if needed you can get a Download URL, as follows
return uploadTaskSnapshot.ref.getDownloadURL();
})
.then((url) => {
cat.media = url;
}).then(() => addCat(cat))
.catch((err) => { console.log(err); });
// addCat(cat);
// return alert('Cat submitted');
}

return (
Expand Down

0 comments on commit 3072e29

Please sign in to comment.