From 58d0d25128145ed986acd9dfd7e1041da58766f7 Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Tue, 26 Apr 2022 21:02:20 +0500 Subject: [PATCH] added versions flatlist --- src/config/locales/en-US.json | 3 +- .../editHistoryScreen/editHistoryScreen.tsx | 73 +++++++++++++++---- .../editHistoryScreenStyles.ts | 23 +++++- src/utils/time.js | 6 ++ 4 files changed, 87 insertions(+), 18 deletions(-) diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 295015ff2..b9b16a12c 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -810,6 +810,7 @@ "detected_url": "Detected URL" }, "history": { - "edit": "Edit History" + "edit": "Edit History", + "version": "Version" } } diff --git a/src/screens/editHistoryScreen/editHistoryScreen.tsx b/src/screens/editHistoryScreen/editHistoryScreen.tsx index 1b85cf8a4..984a8066e 100644 --- a/src/screens/editHistoryScreen/editHistoryScreen.tsx +++ b/src/screens/editHistoryScreen/editHistoryScreen.tsx @@ -1,37 +1,82 @@ import React, { Fragment } from 'react'; import { useEffect, useState } from 'react'; import { useIntl } from 'react-intl'; -import { Alert, Text, View } from 'react-native'; -import { - BasicHeader, -} from '../../components'; +import { Alert, FlatList, Text, TouchableOpacity, View } from 'react-native'; +import { BasicHeader } from '../../components'; // styles import EStyleSheet from 'react-native-extended-stylesheet'; import styles from './editHistoryScreenStyles'; import { getCommentHistory } from '../../providers/ecency/ecency'; import { CommentHistoryItem } from '../../providers/ecency/ecency.types'; +import { dateToFormatted } from '../../utils/time'; const EditHistoryScreen = ({ navigation }) => { - const {author, permlink} = navigation.state.params; + const { author, permlink } = navigation.state.params; const intl = useIntl(); - const [editHistory, setEditHistory] = useState([]) + const [editHistory, setEditHistory] = useState([]); + const [versionSelected, setVersionSelected] = useState(1); useEffect(() => { _getCommentHistory(); - },[]) + }, []); const _getCommentHistory = async () => { const responseData = await getCommentHistory(author, permlink); - if(!responseData){ - Alert.alert('No History found!') + if (!responseData) { + Alert.alert('No History found!'); return; } setEditHistory(responseData); - } + }; console.log('author, permlink : ', author, permlink); console.log('editHistory : ', editHistory); - + + const _renderVersionsListItem = ({ + item, + index, + }: { + item: CommentHistoryItem; + index: number; + }) => { + const selected = versionSelected === item.v; + return ( + setVersionSelected(item.v)} + style={[ + styles.versionItemBtn, + { + backgroundColor: selected + ? EStyleSheet.value('$primaryBlue') + : EStyleSheet.value('$primaryDarkGray'), + }, + ]} + > + + {intl.formatMessage({ + id: 'history.version', + })} + {` ${item.v}`} + + + {dateToFormatted(item.timestamp, 'LL')} + + + ); + }; + const _renderVersionsList = () => ( + + `item ${index}`} + removeClippedSubviews={false} + renderItem={_renderVersionsListItem} + contentContainerStyle={styles.versionsListContentContainer} + showsHorizontalScrollIndicator={false} + horizontal + /> + + ); return ( { id: 'history.edit', })} /> - - - Edit History Screen - - + {editHistory.length > 0 && _renderVersionsList()} ); }; diff --git a/src/screens/editHistoryScreen/editHistoryScreenStyles.ts b/src/screens/editHistoryScreen/editHistoryScreenStyles.ts index c45f9f9be..98bd42576 100644 --- a/src/screens/editHistoryScreen/editHistoryScreenStyles.ts +++ b/src/screens/editHistoryScreen/editHistoryScreenStyles.ts @@ -5,5 +5,26 @@ export default EStyleSheet.create({ flex:1, 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, + } }); diff --git a/src/utils/time.js b/src/utils/time.js index 567602208..34d16da79 100644 --- a/src/utils/time.js +++ b/src/utils/time.js @@ -140,3 +140,9 @@ export const daysTillDate = (dateObj) => { var current = moment(); 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); +};