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,197 +93,208 @@ 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);
} }
} }
//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 = []
for (const index of map.keys()) { for (const index of map.keys()) {
console.log(index) console.log(index)
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()
}) })
} }
handleOnSelect(data) handleOnSelect(data)
setShowModal(false); setShowModal(false);
} }
//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
}
const _onRemovePress = async () => {
const _onConfirm = () => {
_deleteMedia()
}
Alert.alert(
intl.formatMessage({id:'alert.delete'}),
intl.formatMessage({id:'alert.remove_alert'}),
[{
text:intl.formatMessage({id:'alert.cancel'}),
style:'cancel'
},{
text:intl.formatMessage({id:'alert.confirm'}),
onPress:_onConfirm
}]
)
}
return (
<View style={styles.floatingContainer}>
<TextButton
style={styles.cancelButton}
onPress={_onRemovePress}
text={intl.formatMessage({
id: 'uploads_modal.btn_delete',
})}
/>
<MainButton
style={{ width: 136, marginLeft:12}}
onPress={_insertMedia}
iconName="plus"
iconType="MaterialCommunityIcons"
iconColor="white"
text={intl.formatMessage({
id: 'uploads_modal.btn_insert',
})}
/>
</View>
);
};
//render list item for snippet and handle actions;
const _renderItem = ({ item, index }:{item:UploadedMedia, index:number}) => {
const _onCheckPress = () => {
//update selection indices
if(indices.has(index)){
indices.delete(index);
}else {
indices.set(index, true);
} }
setIndices(new Map([...indices])); const _onRemovePress = async () => {
} const _onConfirm = () => {
_deleteMedia()
}
Alert.alert(
intl.formatMessage({ id: 'alert.delete' }),
intl.formatMessage({ id: 'alert.remove_alert' }),
[{
text: intl.formatMessage({ id: 'alert.cancel' }),
style: 'cancel'
}, {
text: intl.formatMessage({ id: 'alert.confirm' }),
onPress: _onConfirm
}]
)
const _onPress = () => { }
if(indices.size){
_onCheckPress()
}else {
_insertMedia(index)
}
}
const thumbUrl = proxifyImageSrc(item.url, 600, 500, Platform.OS === 'ios' ? 'match' : 'webp'); return (
<View style={styles.floatingContainer}>
<TextButton
style={styles.cancelButton}
onPress={_onRemovePress}
text={intl.formatMessage({
id: 'uploads_modal.btn_delete',
})}
/>
<MainButton
style={{ width: 136, marginLeft: 12 }}
onPress={_insertMedia}
iconName="plus"
iconType="MaterialCommunityIcons"
iconColor="white"
text={intl.formatMessage({
id: 'uploads_modal.btn_insert',
})}
/>
</View>
);
};
return (
<TouchableOpacity onPress={_onPress} onLongPress={_onCheckPress}>
<FastImage //render list item for snippet and handle actions;
source={{uri:thumbUrl}} const _renderItem = ({ item, index }: { item: UploadedMedia, index: number }) => {
style={styles.mediaItem}
/> const _onCheckPress = () => {
<View style={styles.checkContainer}> //update selection indices
<CheckBox if (indices.has(index)) {
isChecked={indices.has(index)} indices.delete(index);
clicked={_onCheckPress} } else {
style={styles.checkStyle} indices.set(index, true);
/> }
</View>
setIndices(new Map([...indices]));
</TouchableOpacity> }
)
}; const _onPress = () => {
if (indices.size) {
_onCheckPress()
} else {
_insertMedia(index)
}
}
const thumbUrl = proxifyImageSrc(item.url, 600, 500, Platform.OS === 'ios' ? 'match' : 'webp');
return (
<TouchableOpacity onPress={_onPress} onLongPress={_onCheckPress}>
<FastImage
source={{ uri: thumbUrl }}
style={styles.mediaItem}
/>
<View style={styles.checkContainer}>
<CheckBox
isChecked={indices.has(index)}
clicked={_onCheckPress}
style={styles.checkStyle}
/>
</View>
</TouchableOpacity>
)
};
//render empty list placeholder //render empty list placeholder
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}>
<FlatList {true && <ProgressBar progress={30} />}
data={mediaUploads}
keyExtractor={(item) => `item_${item.url}`} <FlatList
renderItem={_renderItem} data={mediaUploads}
ListEmptyComponent={_renderEmptyContent} keyExtractor={(item) => `item_${item.url}`}
ListFooterComponent={<View style={styles.listEmptyFooter} />} renderItem={_renderItem}
extraData={indices} ListEmptyComponent={_renderEmptyContent}
numColumns={2} ListFooterComponent={<View style={styles.listEmptyFooter} />}
refreshControl={ extraData={indices}
<RefreshControl numColumns={2}
refreshing={isLoading} refreshControl={
onRefresh={_getMediaUploads} <RefreshControl
/> refreshing={isLoading || isUploading}
} onRefresh={_getMediaUploads}
/> />
}
/>
</View> </View>
{_renderFloatingPanel()} {_renderFloatingPanel()}
</View> </View>
) )
return ( return (
<Modal <Modal
isOpen={showModal} isOpen={showModal}
handleOnModalClose={() => setShowModal(false)} handleOnModalClose={() => setShowModal(false)}
isFullScreen isFullScreen
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}
> >
{_renderContent} {_renderContent}
</Modal> </Modal>
); );
}); });