Skip to content

Commit

Permalink
Show upload progress for assignment submission (close #686)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertying committed Mar 30, 2020
1 parent 85d8c5d commit 5e7c536
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 373 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@react-native-community/push-notification-ios": "1.0.6",
"@react-native-firebase/app": "6.3.4",
"@react-native-firebase/messaging": "6.3.4",
"axios": "0.19.2",
"darkreader": "4.9.2",
"dayjs": "1.8.23",
"expo-document-picker": "8.1.0",
Expand Down
14 changes: 8 additions & 6 deletions src/redux/dataSource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Learn2018Helper} from 'thu-learn-lib-no-native';
import mime from 'mime-types';
import axios from 'axios';

let dataSource = new Learn2018Helper();

Expand All @@ -22,6 +23,7 @@ const submitAssignment = async (
uri: string;
name: string;
},
onProgress?: (progress: number) => void,
remove: boolean = false,
) => {
if (!content && !attachment && !remove) {
Expand All @@ -41,15 +43,15 @@ const submitAssignment = async (
}

try {
const res = await fetch(submitAssignmentUrl, {
method: 'POST',
body,
const res = await axios.post(submitAssignmentUrl, body, {
onUploadProgress: (e) => onProgress?.(e.loaded / e.total),
});
if (!res.ok) {
throw new Error('Sumbit assignment failed');

if (res.status !== 200) {
throw new Error('Submit assignment failed');
}
} catch {
throw new Error('Sumbit assignment failed');
throw new Error('Submit assignment failed');
}
};

Expand Down
Loading

0 comments on commit 5e7c536

Please sign in to comment.