Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
PPL KI Ganjil 2021 2022
Clicks - Ecosystem Business
clicks-frontend
Commits
9bc7b5f2
Commit
9bc7b5f2
authored
Oct 10, 2021
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/helpers/images.tsx
View file @
9bc7b5f2
...
...
@@ -26,6 +26,7 @@ export const uploadImgToFirebase = async (
):
Promise
<
string
>
=>
{
try
{
setLoading
&&
setLoading
(
true
);
console
.
log
(
"
ayam
"
);
const
blob
:
Blob
=
await
new
Promise
((
resolve
,
reject
)
=>
{
const
xhr
=
new
XMLHttpRequest
();
...
...
src/redux/user/actions.tsx
View file @
9bc7b5f2
...
...
@@ -19,13 +19,9 @@ export const getUser = (uid: string) => {
export
const
setProfilePic
=
(
url
:
string
,
id
:
string
)
=>
{
return
async
(
dispatch
:
Dispatch
<
any
>
)
=>
{
try
{
await
userService
.
addProfilePic
(
url
,
id
);
await
userService
.
addProfilePic
(
url
,
id
);
dispatch
({
type
:
"
SET_PIC
"
,
payload
:
{
pic
:
url
}
});
}
catch
(
e
)
{
console
.
log
(
e
);
}
return
dispatch
({
type
:
"
SET_PIC
"
,
payload
:
{
pic
:
url
}
});
};
};
...
...
src/screens/profile/AccountSettingsScreen.tsx
View file @
9bc7b5f2
import
{
useNavigation
}
from
"
@react-navigation/core
"
;
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
PlainForm
from
"
../../components/Forms/PlainForm
"
;
import
{
useState
}
from
"
react
"
;
...
...
@@ -29,13 +35,19 @@ export default function AccountSettingsScreen({
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
);
const
dispatch
=
useAppDispatch
();
const
handlePickImage
=
()
=>
{
setIsLoading
(
true
);
//
setIsLoading(true);
pickImage
().
then
((
res
)
=>
{
if
(
!
res
.
cancelled
)
{
setIsLoading
(
true
);
const
{
uri
}
=
res
as
ImageInfo
;
uploadImgToFirebase
(
uri
,
`profile/
${
user
.
id
}
`
).
then
((
res
)
=>
{
dispatch
(
setProfilePic
(
res
,
user
.
id
));
setIsLoading
(
false
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
dispatch
(
setProfilePic
(
res
,
user
.
id
))
.
then
(()
=>
setIsLoading
(
false
))
.
catch
(()
=>
{
setIsLoading
(
false
);
Alert
.
alert
(
"
Error
"
,
"
failed to upload image
"
);
});
});
}
});
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment