added versions flatlist

This commit is contained in:
Sadaqat Ali 2022-04-26 21:02:20 +05:00
parent 6ce8177ecd
commit 58d0d25128
4 changed files with 87 additions and 18 deletions

View File

@ -810,6 +810,7 @@
"detected_url": "Detected URL" "detected_url": "Detected URL"
}, },
"history": { "history": {
"edit": "Edit History" "edit": "Edit History",
"version": "Version"
} }
} }

View File

@ -1,37 +1,82 @@
import React, { Fragment } from 'react'; import React, { Fragment } from 'react';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { Alert, Text, View } from 'react-native'; import { Alert, FlatList, Text, TouchableOpacity, View } from 'react-native';
import { import { BasicHeader } from '../../components';
BasicHeader,
} from '../../components';
// styles // styles
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
import styles from './editHistoryScreenStyles'; import styles from './editHistoryScreenStyles';
import { getCommentHistory } from '../../providers/ecency/ecency'; import { getCommentHistory } from '../../providers/ecency/ecency';
import { CommentHistoryItem } from '../../providers/ecency/ecency.types'; import { CommentHistoryItem } from '../../providers/ecency/ecency.types';
import { dateToFormatted } from '../../utils/time';
const EditHistoryScreen = ({ navigation }) => { const EditHistoryScreen = ({ navigation }) => {
const { author, permlink } = navigation.state.params; const { author, permlink } = navigation.state.params;
const intl = useIntl(); const intl = useIntl();
const [editHistory, setEditHistory] = useState<CommentHistoryItem[]>([]) const [editHistory, setEditHistory] = useState<CommentHistoryItem[]>([]);
const [versionSelected, setVersionSelected] = useState(1);
useEffect(() => { useEffect(() => {
_getCommentHistory(); _getCommentHistory();
},[]) }, []);
const _getCommentHistory = async () => { const _getCommentHistory = async () => {
const responseData = await getCommentHistory(author, permlink); const responseData = await getCommentHistory(author, permlink);
if (!responseData) { if (!responseData) {
Alert.alert('No History found!') Alert.alert('No History found!');
return; return;
} }
setEditHistory(responseData); setEditHistory(responseData);
} };
console.log('author, permlink : ', author, permlink); console.log('author, permlink : ', author, permlink);
console.log('editHistory : ', editHistory); console.log('editHistory : ', editHistory);
const _renderVersionsListItem = ({
item,
index,
}: {
item: CommentHistoryItem;
index: number;
}) => {
const selected = versionSelected === item.v;
return (
<TouchableOpacity
onPress={() => setVersionSelected(item.v)}
style={[
styles.versionItemBtn,
{
backgroundColor: selected
? EStyleSheet.value('$primaryBlue')
: EStyleSheet.value('$primaryDarkGray'),
},
]}
>
<Text style={[styles.versionItemBtnText, { color: selected ? 'white' : 'black' }]}>
{intl.formatMessage({
id: 'history.version',
})}
{` ${item.v}`}
</Text>
<Text style={[styles.versionItemBtnDate, { color: selected ? 'white' : 'black' }]}>
{dateToFormatted(item.timestamp, 'LL')}
</Text>
</TouchableOpacity>
);
};
const _renderVersionsList = () => (
<View style={styles.versionsListContainer}>
<FlatList
data={editHistory}
keyExtractor={(item, index) => `item ${index}`}
removeClippedSubviews={false}
renderItem={_renderVersionsListItem}
contentContainerStyle={styles.versionsListContentContainer}
showsHorizontalScrollIndicator={false}
horizontal
/>
</View>
);
return ( return (
<Fragment> <Fragment>
<BasicHeader <BasicHeader
@ -39,11 +84,7 @@ const EditHistoryScreen = ({ navigation }) => {
id: 'history.edit', id: 'history.edit',
})} })}
/> />
<View style={styles.mainContainer}> <View style={styles.mainContainer}>{editHistory.length > 0 && _renderVersionsList()}</View>
<Text>
Edit History Screen
</Text>
</View>
</Fragment> </Fragment>
); );
}; };

View File

@ -5,5 +5,26 @@ export default EStyleSheet.create({
flex:1, flex:1,
backgroundColor: '$primaryBackgroundColor', backgroundColor: '$primaryBackgroundColor',
}, },
versionsListContentContainer: {
paddingHorizontal: 16
},
versionItemBtn: {
// backgroundColor: '$primaryBlue',
backgroundColor: '$primaryDarkGray',
marginRight: 16,
width: 150,
height: 48,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 100,
},
versionItemBtnText: {
color: '$black',
fontSize: 14,
fontWeight: '700'
},
versionItemBtnDate: {
color: '$black',
fontSize: 14,
}
}); });

View File

@ -140,3 +140,9 @@ export const daysTillDate = (dateObj) => {
var current = moment(); var current = moment();
return Math.round(moment.duration(given.diff(current)).asDays()); return Math.round(moment.duration(given.diff(current)).asDays());
}; };
export const dateToFormatted = (d, format = 'LLLL') => {
const isTimeZoned = d.indexOf('.') !== -1 || d.indexOf('+') !== -1 ? d : `${d}.000Z`;
const dm = moment(new Date(isTimeZoned));
return dm.format(format);
};