implementing progress bar

This commit is contained in:
noumantahir 2022-05-31 12:40:30 +05:00
parent 5597f53526
commit c95757aa92
4 changed files with 164 additions and 133 deletions

View File

@ -1 +1,2 @@
export * from './optionsModal'; export * from './optionsModal';
export * from './progressBar'

View File

@ -0,0 +1,18 @@
import React from 'react';
import { View } from "react-native"
export const ProgressBar = ({
progress
}) => {
return (
<View style={{height:16, flex:1, flexDirection:'row', color:'green'}}>
<View style={{flex:progress, color:'blue'}} />
<View style={{flex:100 - progress}} />
</View>
)
}

View File

@ -0,0 +1 @@
export * from './container/progressBar';

View File

@ -93,7 +93,7 @@ export const UploadsGalleryModal = forwardRef(({
await _getMediaUploads(); await _getMediaUploads();
setIndices(new Map()); setIndices(new Map());
setIsLoading(false); setIsLoading(false);
} catch(err){ } catch (err) {
console.warn("failed to remove image from gallery", err) console.warn("failed to remove image from gallery", err)
setIsLoading(false); setIsLoading(false);
} }
@ -102,23 +102,23 @@ export const UploadsGalleryModal = forwardRef(({
//fetch images from server //fetch images from server
const _getMediaUploads = async () => { const _getMediaUploads = async () => {
try{ try {
if (username) { if (username) {
setIsLoading(true); setIsLoading(true);
console.log("getting images for: " + username ) console.log("getting images for: " + username)
const images = await getImages() const images = await getImages()
console.log("images received", images) console.log("images received", images)
setMediaUploads(images); setMediaUploads(images);
setIsLoading(false); setIsLoading(false);
} }
}catch(err){ } catch (err) {
console.warn("Failed to get images") console.warn("Failed to get images")
setIsLoading(false); setIsLoading(false);
} }
} }
//inserts media items in post body //inserts media items in post body
const _insertMedia = async (selectedIndex?:number) => { const _insertMedia = async (selectedIndex?: number) => {
const map = selectedIndex > -1 ? new Map([[selectedIndex, true]]) : indices; const map = selectedIndex > -1 ? new Map([[selectedIndex, true]]) : indices;
const data = [] const data = []
@ -127,8 +127,8 @@ export const UploadsGalleryModal = forwardRef(({
const item = mediaUploads[index] const item = mediaUploads[index]
data.push({ data.push({
url:item.url, url: item.url,
hash:item.url.split('/').pop() hash: item.url.split('/').pop()
}) })
} }
@ -139,7 +139,7 @@ export const UploadsGalleryModal = forwardRef(({
//renders footer with add snipept button and shows new snippet modal //renders footer with add snipept button and shows new snippet modal
const _renderFloatingPanel = () => { const _renderFloatingPanel = () => {
if(!indices.size){ if (!indices.size) {
return null return null
} }
@ -148,14 +148,14 @@ export const UploadsGalleryModal = forwardRef(({
_deleteMedia() _deleteMedia()
} }
Alert.alert( Alert.alert(
intl.formatMessage({id:'alert.delete'}), intl.formatMessage({ id: 'alert.delete' }),
intl.formatMessage({id:'alert.remove_alert'}), intl.formatMessage({ id: 'alert.remove_alert' }),
[{ [{
text:intl.formatMessage({id:'alert.cancel'}), text: intl.formatMessage({ id: 'alert.cancel' }),
style:'cancel' style: 'cancel'
},{ }, {
text:intl.formatMessage({id:'alert.confirm'}), text: intl.formatMessage({ id: 'alert.confirm' }),
onPress:_onConfirm onPress: _onConfirm
}] }]
) )
@ -171,7 +171,7 @@ export const UploadsGalleryModal = forwardRef(({
})} })}
/> />
<MainButton <MainButton
style={{ width: 136, marginLeft:12}} style={{ width: 136, marginLeft: 12 }}
onPress={_insertMedia} onPress={_insertMedia}
iconName="plus" iconName="plus"
iconType="MaterialCommunityIcons" iconType="MaterialCommunityIcons"
@ -187,13 +187,13 @@ export const UploadsGalleryModal = forwardRef(({
//render list item for snippet and handle actions; //render list item for snippet and handle actions;
const _renderItem = ({ item, index }:{item:UploadedMedia, index:number}) => { const _renderItem = ({ item, index }: { item: UploadedMedia, index: number }) => {
const _onCheckPress = () => { const _onCheckPress = () => {
//update selection indices //update selection indices
if(indices.has(index)){ if (indices.has(index)) {
indices.delete(index); indices.delete(index);
}else { } else {
indices.set(index, true); indices.set(index, true);
} }
@ -202,9 +202,9 @@ export const UploadsGalleryModal = forwardRef(({
const _onPress = () => { const _onPress = () => {
if(indices.size){ if (indices.size) {
_onCheckPress() _onCheckPress()
}else { } else {
_insertMedia(index) _insertMedia(index)
} }
} }
@ -214,7 +214,7 @@ export const UploadsGalleryModal = forwardRef(({
return ( return (
<TouchableOpacity onPress={_onPress} onLongPress={_onCheckPress}> <TouchableOpacity onPress={_onPress} onLongPress={_onCheckPress}>
<FastImage <FastImage
source={{uri:thumbUrl}} source={{ uri: thumbUrl }}
style={styles.mediaItem} style={styles.mediaItem}
/> />
<View style={styles.checkContainer}> <View style={styles.checkContainer}>
@ -234,18 +234,29 @@ export const UploadsGalleryModal = forwardRef(({
const _renderEmptyContent = () => { const _renderEmptyContent = () => {
return ( return (
<> <>
<Text style={styles.title}>{intl.formatMessage({id:'uploads_modal.label_no_images'})}</Text> <Text style={styles.title}>{intl.formatMessage({ id: 'uploads_modal.label_no_images' })}</Text>
</> </>
); );
}; };
const _renderUploadProgress = () => {
return (
<View>
</View>
)
}
const _renderContent = ( const _renderContent = (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.bodyWrapper}> <View style={styles.bodyWrapper}>
{true && <ProgressBar progress={30} />}
<FlatList <FlatList
data={mediaUploads} data={mediaUploads}
keyExtractor={(item) => `item_${item.url}`} keyExtractor={(item) => `item_${item.url}`}
@ -256,7 +267,7 @@ export const UploadsGalleryModal = forwardRef(({
numColumns={2} numColumns={2}
refreshControl={ refreshControl={
<RefreshControl <RefreshControl
refreshing={isLoading} refreshing={isLoading || isUploading}
onRefresh={_getMediaUploads} onRefresh={_getMediaUploads}
/> />
} }
@ -275,7 +286,7 @@ export const UploadsGalleryModal = forwardRef(({
isCloseButton isCloseButton
presentationStyle="formSheet" presentationStyle="formSheet"
title={intl.formatMessage({ title={intl.formatMessage({
id:'uploads_modal.title' id: 'uploads_modal.title'
})} })}
animationType="slide" animationType="slide"
style={styles.modalStyle} style={styles.modalStyle}