Fakultas Ilmu Komputer UI

Commit 9bc7b5f2 authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

fix: add more accurate loading status for image upload

parent 835b0841
Pipeline #86262 passed with stage
in 11 minutes and 39 seconds
...@@ -26,6 +26,7 @@ export const uploadImgToFirebase = async ( ...@@ -26,6 +26,7 @@ export const uploadImgToFirebase = async (
): Promise<string> => { ): Promise<string> => {
try { try {
setLoading && setLoading(true); setLoading && setLoading(true);
console.log("ayam");
const blob: Blob = await new Promise((resolve, reject) => { const blob: Blob = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
......
...@@ -19,13 +19,9 @@ export const getUser = (uid: string) => { ...@@ -19,13 +19,9 @@ export const getUser = (uid: string) => {
export const setProfilePic = (url: string, id: string) => { export const setProfilePic = (url: string, id: string) => {
return async (dispatch: Dispatch<any>) => { return async (dispatch: Dispatch<any>) => {
try { await userService.addProfilePic(url, id);
await userService.addProfilePic(url, id);
dispatch({ type: "SET_PIC", payload: { pic: url } }); return dispatch({ type: "SET_PIC", payload: { pic: url } });
} catch (e) {
console.log(e);
}
}; };
}; };
......
import { useNavigation } from "@react-navigation/core"; import { useNavigation } from "@react-navigation/core";
import * as React from "react"; import * as React from "react";
import { Button, StyleSheet, Image, ActivityIndicator } from "react-native"; import {
Button,
StyleSheet,
Image,
ActivityIndicator,
Alert,
} from "react-native";
import { ScrollView, TouchableOpacity } from "react-native-gesture-handler"; import { ScrollView, TouchableOpacity } from "react-native-gesture-handler";
import PlainForm from "../../components/Forms/PlainForm"; import PlainForm from "../../components/Forms/PlainForm";
import { useState } from "react"; import { useState } from "react";
...@@ -29,13 +35,19 @@ export default function AccountSettingsScreen({ ...@@ -29,13 +35,19 @@ export default function AccountSettingsScreen({
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const handlePickImage = () => { const handlePickImage = () => {
setIsLoading(true); // setIsLoading(true);
pickImage().then((res) => { pickImage().then((res) => {
if (!res.cancelled) { if (!res.cancelled) {
setIsLoading(true);
const { uri } = res as ImageInfo; const { uri } = res as ImageInfo;
uploadImgToFirebase(uri, `profile/${user.id}`).then((res) => { uploadImgToFirebase(uri, `profile/${user.id}`).then((res) => {
dispatch(setProfilePic(res, user.id)); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
setIsLoading(false); dispatch(setProfilePic(res, user.id))
.then(() => setIsLoading(false))
.catch(() => {
setIsLoading(false);
Alert.alert("Error", "failed to upload image");
});
}); });
} }
}); });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment