From 398b17442ba7a8a02dbdbf5c5a987ca126e7f556 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Tue, 30 Nov 2021 17:53:18 +0500 Subject: [PATCH 01/17] added editor settings modal frame --- .../basicHeader/view/basicHeaderView.js | 4 +- .../editor/children/editorSettingsModal.tsx | 54 +++++++++ .../children/editorSettingsModalStyles.ts | 103 ++++++++++++++++++ .../{editorScreen.js => editorScreen.tsx} | 13 ++- 4 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 src/screens/editor/children/editorSettingsModal.tsx create mode 100644 src/screens/editor/children/editorSettingsModalStyles.ts rename src/screens/editor/screen/{editorScreen.js => editorScreen.tsx} (96%) diff --git a/src/components/basicHeader/view/basicHeaderView.js b/src/components/basicHeader/view/basicHeaderView.js index 1940b6f21..5bef6e655 100644 --- a/src/components/basicHeader/view/basicHeaderView.js +++ b/src/components/basicHeader/view/basicHeaderView.js @@ -34,7 +34,6 @@ const BasicHeaderView = ({ isHasIcons, isHasSearch, isLoading, - isLoggedIn, isModalHeader, isPreviewActive, isReply, @@ -49,6 +48,7 @@ const BasicHeaderView = ({ handleRewardChange, handleBeneficiaries, enableViewModeToggle, + handleSettingsPress, showThumbSelectionModal, }) => { const [isInputVisible, setIsInputVisible] = useState(false); @@ -179,7 +179,7 @@ const BasicHeaderView = ({ iconStyle={[styles.backIcon, isModalHeader && styles.closeIcon]} iconType="MaterialIcons" name="settings" - onPress={() => settingMenuRef.current.show()} + onPress={handleSettingsPress && handleSettingsPress} disabled={disabled} /> )} diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx new file mode 100644 index 000000000..87a3df8b9 --- /dev/null +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -0,0 +1,54 @@ +import React, { forwardRef, useImperativeHandle, useState } from 'react'; +import { useIntl } from 'react-intl'; +import {Text, View} from 'react-native'; +import { Modal } from '../../../components'; +import styles from './editorSettingsModalStyles'; + + +export interface EditorSettingsModalRef { + showModal:()=>void; +} + + +interface EditorSettingsModalProps { +} + +const EditorSettingsModal = forwardRef(({}: EditorSettingsModalProps, ref) => { + const intl = useIntl(); + const [showModal, setShowModal] = useState(false); + + + useImperativeHandle(ref, () => ({ + show: () => { + setShowModal(true); + }, + })); + + + const _renderContent = ( + + This is a modal + + ) + + + return ( + setShowModal(false)} + isFullScreen + isCloseButton + presentationStyle="formSheet" + title={"Editor Settings"} + animationType="slide" + style={styles.modalStyle} + > + {_renderContent} + + + ); +}); + +export default EditorSettingsModal + + diff --git a/src/screens/editor/children/editorSettingsModalStyles.ts b/src/screens/editor/children/editorSettingsModalStyles.ts new file mode 100644 index 000000000..d7555dd21 --- /dev/null +++ b/src/screens/editor/children/editorSettingsModalStyles.ts @@ -0,0 +1,103 @@ +import { TextStyle, StyleSheet, ViewStyle, Dimensions, ImageStyle } from 'react-native'; +import EStyleSheet from 'react-native-extended-stylesheet'; + +const gridItemWidth = ((Dimensions.get('window').width/2) - 32); +const gridItemHeight = (gridItemWidth * 500)/600 + +export default EStyleSheet.create({ + modalStyle: { + flex: 1, + backgroundColor: '$primaryBackgroundColor', + margin: 0, + paddingTop: 32, + paddingBottom: 16, + }, + container: { + flex: 1, + justifyContent: 'space-between', + paddingVertical: 8, + }, + bodyWrapper: { + flex: 3, + paddingHorizontal:16 + }, + floatingContainer:{ + position:'absolute', + bottom:0, + right:20, + justifyContent:'flex-end', + zIndex:10 + } as ViewStyle, + + mediaItem:{ + margin:8, + height:gridItemHeight, + width:gridItemWidth, + borderRadius:16, + backgroundColor:'$primaryLightGray' + } as ImageStyle, + + inputContainer:{ + flex:1 + } as ViewStyle, + titleInput:{ + color: '$primaryBlack', + fontWeight: 'bold', + fontSize: 18, + textAlignVertical: 'top', + paddingVertical: 0, + backgroundColor:'$primaryBackgroundColor', + borderBottomWidth:StyleSheet.hairlineWidth, + borderBottomColor:'$primaryDarkGray' + } as TextStyle, + + title: { + fontWeight: '700', + flex:1, + fontSize:16, + color:'$primaryBlack' + } as TextStyle, + + btnText:{ + color:'$pureWhite' + } as TextStyle, + saveButton:{ + + backgroundColor:'$primaryBlue', + width:150, + paddingVertical:16, + borderRadius:32, + justifyContent:'center', + alignItems:'center' + } as ViewStyle, + closeButton:{ + marginRight:16, + paddingVertical:8, + borderRadius:16, + justifyContent:'center', + alignItems:'center' + } as ViewStyle, + actionPanel:{ + flexDirection:'row', + justifyContent:'flex-end', + alignItems:'center', + marginBottom:16 + } as ViewStyle, + + itemIcon:{ + color:'$white', + } as ViewStyle, + + itemIconWrapper:{ + justifyContent:'center', + alignItems:'center', + backgroundColor:'$primaryRed', + + } as ViewStyle, + + removeItemContainer:{ + position:'absolute', + top:16, + right:16 + } as ViewStyle +}) \ No newline at end of file diff --git a/src/screens/editor/screen/editorScreen.js b/src/screens/editor/screen/editorScreen.tsx similarity index 96% rename from src/screens/editor/screen/editorScreen.js rename to src/screens/editor/screen/editorScreen.tsx index 32c438612..55699c5d1 100644 --- a/src/screens/editor/screen/editorScreen.js +++ b/src/screens/editor/screen/editorScreen.tsx @@ -32,6 +32,7 @@ import { isCommunity } from '../../../utils/communityValidation'; import styles from './editorScreenStyles'; import ThumbSelectionModal from '../children/thumbSelectionModal'; +import EditorSettingsModal from '../children/editorSettingsModal'; class EditorScreen extends Component { /* Props @@ -39,6 +40,7 @@ class EditorScreen extends Component { * @prop { type } name - Description.... */ thumbSelectionModalRef = null; + editorSettingsModalRef = null; constructor(props) { super(props); @@ -186,6 +188,12 @@ class EditorScreen extends Component { } }; + _handleSettingsPress = () => { + if(this.editorSettingsModalRef){ + this.editorSettingsModalRef.show(); + } + } + _handleIsFormValid = (bodyText) => { const { fields } = this.state; const { isReply, isLoggedIn } = this.props; @@ -313,7 +321,6 @@ class EditorScreen extends Component { isPreviewActive, wordsCount, isFormValid, - isRemoveTag, isCommunitiesListModalOpen, selectedCommunity, selectedAccount, @@ -387,6 +394,7 @@ class EditorScreen extends Component { quickTitle={wordsCount > 0 && `${wordsCount} words`} rightButtonText={rightButtonText} showThumbSelectionModal={this._showThumbSelectionModal} + handleSettingsPress={this._handleSettingsPress} /> + (this.editorSettingsModalRef = componentRef)} + /> ); } From 813e3c84267306619454d6328f4be75c18fff960 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Tue, 30 Nov 2021 18:48:57 +0500 Subject: [PATCH 02/17] handling reward type set --- .../editor/children/editorSettingsModal.tsx | 54 ++++++++++++++++--- .../children/editorSettingsModalStyles.ts | 1 + 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 87a3df8b9..14bba5b50 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -1,21 +1,42 @@ import React, { forwardRef, useImperativeHandle, useState } from 'react'; import { useIntl } from 'react-intl'; -import {Text, View} from 'react-native'; -import { Modal } from '../../../components'; +import { View } from 'react-native'; +import { Modal, SettingsItem } from '../../../components'; import styles from './editorSettingsModalStyles'; +const REWARD_TYPES = [ + { + key:'default', + intlId:'editor.reward_default' + }, + { + key:'sp', + intlId:'editor.reward_power_up' + }, + { + key:'dp', + intlId:'editor.reward_decline' + }, +] + + + export interface EditorSettingsModalRef { showModal:()=>void; } interface EditorSettingsModalProps { + handleRewardChange:(rewardType:string)=>void } -const EditorSettingsModal = forwardRef(({}: EditorSettingsModalProps, ref) => { +const EditorSettingsModal = forwardRef(({ + handleRewardChange +}: EditorSettingsModalProps, ref) => { const intl = useIntl(); - const [showModal, setShowModal] = useState(false); + const [showModal, setShowModal] = useState(false); + const [rewardTypeIndex, setRewardTypeIndex] = useState(0); useImperativeHandle(ref, () => ({ @@ -23,11 +44,32 @@ const EditorSettingsModal = forwardRef(({}: EditorSettingsModalProps, ref) => { setShowModal(true); }, })); - + + + + const _handleRewardChange = (index:number) => { + setRewardTypeIndex(index) + const rewardTypeKey = REWARD_TYPES[index].key + if (handleRewardChange) { + handleRewardChange(rewardTypeKey); + } + } + const _renderContent = ( - This is a modal + intl.formatMessage({ id: type.intlId})) + } + selectedOptionIndex={rewardTypeIndex} + handleOnChange={_handleRewardChange} + /> ) diff --git a/src/screens/editor/children/editorSettingsModalStyles.ts b/src/screens/editor/children/editorSettingsModalStyles.ts index d7555dd21..846f96dd1 100644 --- a/src/screens/editor/children/editorSettingsModalStyles.ts +++ b/src/screens/editor/children/editorSettingsModalStyles.ts @@ -16,6 +16,7 @@ export default EStyleSheet.create({ flex: 1, justifyContent: 'space-between', paddingVertical: 8, + paddingHorizontal: 32, }, bodyWrapper: { flex: 3, From acaaf8ebc6c7409beefa27bedd02b780413188b7 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Wed, 1 Dec 2021 15:55:30 +0500 Subject: [PATCH 03/17] support for thumb selection in settings modal --- .../editor/children/editorSettingsModal.tsx | 31 ++++++-- .../children/editorSettingsModalStyles.ts | 1 - ...thumbSelectionModalStyles.ts => styles.ts} | 19 +++-- .../editor/children/thumbSelectionContent.tsx | 76 +++++++++++++++++++ .../editor/children/thumbSelectionModal.tsx | 4 +- src/screens/editor/screen/editorScreen.tsx | 3 + 6 files changed, 115 insertions(+), 19 deletions(-) rename src/screens/editor/children/{thumbSelectionModalStyles.ts => styles.ts} (75%) create mode 100644 src/screens/editor/children/thumbSelectionContent.tsx diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 14bba5b50..9d1e1ffdd 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -1,8 +1,9 @@ -import React, { forwardRef, useImperativeHandle, useState } from 'react'; +import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react'; import { useIntl } from 'react-intl'; -import { View } from 'react-native'; +import { Button, View } from 'react-native'; import { Modal, SettingsItem } from '../../../components'; import styles from './editorSettingsModalStyles'; +import ThumbSelectionContent from './thumbSelectionContent'; const REWARD_TYPES = [ @@ -28,15 +29,27 @@ export interface EditorSettingsModalRef { interface EditorSettingsModalProps { - handleRewardChange:(rewardType:string)=>void + body:string; + handleRewardChange:(rewardType:string)=>void; + handleThumbSelection:(index:number)=>void; } const EditorSettingsModal = forwardRef(({ - handleRewardChange + body, + handleRewardChange, + handleThumbSelection, }: EditorSettingsModalProps, ref) => { const intl = useIntl(); + const [showModal, setShowModal] = useState(false); - const [rewardTypeIndex, setRewardTypeIndex] = useState(0); + const [rewardTypeIndex, setRewardTypeIndex] = useState(0); + const [thumbIndex, setThumbIndex] = useState(0); + + useEffect(() => { + if(handleThumbSelection){ + handleThumbSelection(thumbIndex); + } + }, [thumbIndex]) useImperativeHandle(ref, () => ({ @@ -46,7 +59,6 @@ const EditorSettingsModal = forwardRef(({ })); - const _handleRewardChange = (index:number) => { setRewardTypeIndex(index) const rewardTypeKey = REWARD_TYPES[index].key @@ -70,6 +82,13 @@ const EditorSettingsModal = forwardRef(({ selectedOptionIndex={rewardTypeIndex} handleOnChange={_handleRewardChange} /> + + + ) diff --git a/src/screens/editor/children/editorSettingsModalStyles.ts b/src/screens/editor/children/editorSettingsModalStyles.ts index 846f96dd1..473be5425 100644 --- a/src/screens/editor/children/editorSettingsModalStyles.ts +++ b/src/screens/editor/children/editorSettingsModalStyles.ts @@ -14,7 +14,6 @@ export default EStyleSheet.create({ }, container: { flex: 1, - justifyContent: 'space-between', paddingVertical: 8, paddingHorizontal: 32, }, diff --git a/src/screens/editor/children/thumbSelectionModalStyles.ts b/src/screens/editor/children/styles.ts similarity index 75% rename from src/screens/editor/children/thumbSelectionModalStyles.ts rename to src/screens/editor/children/styles.ts index ec4624f22..cd532031e 100644 --- a/src/screens/editor/children/thumbSelectionModalStyles.ts +++ b/src/screens/editor/children/styles.ts @@ -12,9 +12,10 @@ export default EStyleSheet.create({ zIndex:999 }, thumbStyle:{ - width:100, - height:100, - margin:8, + width:72, + height:72, + marginVertical:8, + marginRight:8, borderRadius:12, backgroundColor:'$primaryLightGray' }, @@ -22,15 +23,13 @@ export default EStyleSheet.create({ borderWidth:4, borderColor:'$primaryBlack' }, - title:{ - color: '$primaryBlack', + settingLabel:{ + color: '$primaryDarkGray', + fontSize: 14, fontWeight: 'bold', - fontSize: 18, - padding: 16, - textAlign:'center' + flexGrow: 1, }, listContainer:{ - paddingHorizontal:8, paddingBottom:getBottomSpace() + 16, - } + }, }); diff --git a/src/screens/editor/children/thumbSelectionContent.tsx b/src/screens/editor/children/thumbSelectionContent.tsx new file mode 100644 index 000000000..1e36941ac --- /dev/null +++ b/src/screens/editor/children/thumbSelectionContent.tsx @@ -0,0 +1,76 @@ +import React, { useEffect, useState } from 'react'; +import { useIntl } from 'react-intl'; +import { Alert, Text, View } from 'react-native'; +import FastImage from 'react-native-fast-image'; +import { FlatList, TouchableOpacity } from 'react-native-gesture-handler'; +import { extractImageUrls } from '../../../utils/editor'; +import styles from './styles'; + +interface ThumbSelectionContentProps { + body:string; + thumbIndex:number; + onThumbSelection:(index:number)=>void; +} + +const ThumbSelectionContent = ({body, thumbIndex, onThumbSelection}: ThumbSelectionContentProps) => { + const intl = useIntl(); + + const [imageUrls, setImageUrls] = useState([]); + const [needMore, setNeedMore] = useState(true); + + useEffect(() => { + const urls = extractImageUrls({body}); + + if(urls.length < 2){ + setNeedMore(true); + onThumbSelection(0); + setImageUrls([]) + }else{ + setNeedMore(false); + setImageUrls(urls) + } + }, [body]) + + + //VIEW_RENDERERS + const _renderImageItem = ({item, index}:{item:string, index:number}) => { + const _onPress = () => { + onThumbSelection(index); + } + + const selectedStyle = index === thumbIndex ? styles.selectedStyle : null + + return ( + + + + ) + } + + + return ( + + {intl.formatMessage({id:'editor.select_thumb'})} + { + needMore ? ( + Add more images to select thumbnail + ):( + `${item}-${index}`} + horizontal={true} + contentContainerStyle={styles.listContainer} + showsHorizontalScrollIndicator={false}/> + ) + } + + + ); +}; + +export default ThumbSelectionContent; diff --git a/src/screens/editor/children/thumbSelectionModal.tsx b/src/screens/editor/children/thumbSelectionModal.tsx index 442ca5a58..0f329b074 100644 --- a/src/screens/editor/children/thumbSelectionModal.tsx +++ b/src/screens/editor/children/thumbSelectionModal.tsx @@ -2,13 +2,14 @@ import React, { useImperativeHandle, useRef, useState } from 'react'; import { FlatList, TouchableOpacity } from 'react-native-gesture-handler'; import ActionSheet from 'react-native-actions-sheet'; import EStyleSheet from 'react-native-extended-stylesheet'; -import styles from './thumbSelectionModalStyles'; +import styles from './styles'; import { extractImageUrls } from '../../../utils/editor'; import FastImage from 'react-native-fast-image'; import { forwardRef } from 'react'; import { View, Text, Alert } from 'react-native'; import { useIntl } from 'react-intl'; + export interface ThumbSelectionModalProps { thumbIndex:number; onThumbSelection:(index:number)=>void; @@ -57,7 +58,6 @@ const ThumbSelectionModal = ({ onThumbSelection, thumbIndex }:ThumbSelectionModa } const selectedStyle = index === thumbIndex ? styles.selectedStyle : null - return ( diff --git a/src/screens/editor/screen/editorScreen.tsx b/src/screens/editor/screen/editorScreen.tsx index 55699c5d1..a88ee87a8 100644 --- a/src/screens/editor/screen/editorScreen.tsx +++ b/src/screens/editor/screen/editorScreen.tsx @@ -446,6 +446,9 @@ class EditorScreen extends Component { /> (this.editorSettingsModalRef = componentRef)} + body={fields.body} + handleThumbSelection={this._handleOnThumbSelection} + handleRewardChange={handleRewardChange} /> ); From 550faa2fba05427bf9d6704393583f63f587f89f Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Fri, 3 Dec 2021 19:28:27 +0500 Subject: [PATCH 04/17] added partial datetime picker in settings modal --- .../editor/children/editorSettingsModal.tsx | 37 ++++++++++++++++++- .../children/editorSettingsModalStyles.ts | 5 ++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 9d1e1ffdd..3664d79d7 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -1,9 +1,11 @@ import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react'; import { useIntl } from 'react-intl'; -import { Button, View } from 'react-native'; -import { Modal, SettingsItem } from '../../../components'; +import {View } from 'react-native'; +import { DateTimePicker, Modal, SettingsItem } from '../../../components'; import styles from './editorSettingsModalStyles'; import ThumbSelectionContent from './thumbSelectionContent'; +import {View as AnimatedView} from 'react-native-animatable'; +import Animated from 'react-native-reanimated'; const REWARD_TYPES = [ @@ -44,6 +46,8 @@ const EditorSettingsModal = forwardRef(({ const [showModal, setShowModal] = useState(false); const [rewardTypeIndex, setRewardTypeIndex] = useState(0); const [thumbIndex, setThumbIndex] = useState(0); + const [showScheduleModal, setShowScheduleModal] = useState(false) + const [scheduleLater, setScheduleLater] = useState(false) useEffect(() => { if(handleThumbSelection){ @@ -70,6 +74,31 @@ const EditorSettingsModal = forwardRef(({ const _renderContent = ( + { + setScheduleLater(index === 1) + }} + /> + + {scheduleLater && ( + + {}} + disabled={true} + /> + + + )} + + + + + ) diff --git a/src/screens/editor/children/editorSettingsModalStyles.ts b/src/screens/editor/children/editorSettingsModalStyles.ts index 473be5425..fd2e21bc8 100644 --- a/src/screens/editor/children/editorSettingsModalStyles.ts +++ b/src/screens/editor/children/editorSettingsModalStyles.ts @@ -50,7 +50,10 @@ export default EStyleSheet.create({ borderBottomWidth:StyleSheet.hairlineWidth, borderBottomColor:'$primaryDarkGray' } as TextStyle, - + dateTimeModa:{ + backgroundColor: 'white', + alignItems: 'center', + } as ViewStyle, title: { fontWeight: '700', flex:1, From b2ba4022c4e7d8271c6a12f2dbe557e37aba5bbe Mon Sep 17 00:00:00 2001 From: noumantahir Date: Mon, 6 Dec 2021 23:08:04 +0500 Subject: [PATCH 05/17] updated schedule post flow --- src/config/locales/en-US.json | 3 +- .../editor/children/editorSettingsModal.tsx | 51 +++++++++++-------- .../editor/container/editorContainer.tsx | 5 +- src/screens/editor/screen/editorScreen.tsx | 26 ++++++++-- 4 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 7495def67..2bac07d30 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -281,7 +281,8 @@ "publish": "Publish", "search": "Search", "update": "Update", - "reply": "Reply" + "reply": "Reply", + "schedule":"Schedule" }, "editor": { "title": "Title", diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 3664d79d7..f99441e11 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -1,12 +1,10 @@ import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react'; import { useIntl } from 'react-intl'; -import {View } from 'react-native'; +import { View } from 'react-native'; import { DateTimePicker, Modal, SettingsItem } from '../../../components'; import styles from './editorSettingsModalStyles'; import ThumbSelectionContent from './thumbSelectionContent'; import {View as AnimatedView} from 'react-native-animatable'; -import Animated from 'react-native-reanimated'; - const REWARD_TYPES = [ { @@ -34,26 +32,37 @@ interface EditorSettingsModalProps { body:string; handleRewardChange:(rewardType:string)=>void; handleThumbSelection:(index:number)=>void; + handleScheduleChange:(datetime:string|null)=>void; } const EditorSettingsModal = forwardRef(({ body, handleRewardChange, handleThumbSelection, + handleScheduleChange }: EditorSettingsModalProps, ref) => { const intl = useIntl(); const [showModal, setShowModal] = useState(false); const [rewardTypeIndex, setRewardTypeIndex] = useState(0); const [thumbIndex, setThumbIndex] = useState(0); - const [showScheduleModal, setShowScheduleModal] = useState(false) const [scheduleLater, setScheduleLater] = useState(false) + const [scheduledFor, setScheduledFor] = useState(''); useEffect(() => { if(handleThumbSelection){ handleThumbSelection(thumbIndex); } }, [thumbIndex]) + + + useEffect(()=>{ + if(!scheduleLater){ + handleScheduleChange(null) + }else if(scheduledFor) { + handleScheduleChange(scheduledFor) + } + }, [scheduleLater, scheduledFor]) useImperativeHandle(ref, () => ({ @@ -70,29 +79,33 @@ const EditorSettingsModal = forwardRef(({ handleRewardChange(rewardTypeKey); } } + + const _handleDatePickerChange = (date:string) => { + setScheduledFor(date); + } const _renderContent = ( { - setScheduleLater(index === 1) - }} - /> + title={"Scheduled For"} + type="dropdown" + actionType="reward" + options={[ + "Immediate", + "Later", + ]} + selectedOptionIndex={scheduleLater ? 1 : 0} + handleOnChange={(index)=>{ + setScheduleLater(index === 1) + }} + /> {scheduleLater && ( {}} + onChanged={_handleDatePickerChange} disabled={true} /> @@ -117,10 +130,6 @@ const EditorSettingsModal = forwardRef(({ thumbIndex={thumbIndex} onThumbSelection={setThumbIndex} /> - - - - ) diff --git a/src/screens/editor/container/editorContainer.tsx b/src/screens/editor/container/editorContainer.tsx index 972f0e6c7..e117d1ed2 100644 --- a/src/screens/editor/container/editorContainer.tsx +++ b/src/screens/editor/container/editorContainer.tsx @@ -925,7 +925,8 @@ class EditorContainer extends Component { } }; - _handleDatePickerChange = async (datePickerValue, fields) => { + + _handleSchedulePress = async (datePickerValue, fields) => { const { currentAccount, pinCode, intl } = this.props; if (fields.title === '' || fields.body === '') { @@ -1094,7 +1095,7 @@ class EditorContainer extends Component { draftPost={draftPost} handleRewardChange={this._handleRewardChange} handleBeneficiaries={this._handleBeneficiaries} - handleDatePickerChange={this._handleDatePickerChange} + handleSchedulePress={this._handleSchedulePress} handleFormChanged={this._handleFormChanged} handleOnBackPress={() => { }} handleOnImagePicker={this._handleRoutingAction} diff --git a/src/screens/editor/screen/editorScreen.tsx b/src/screens/editor/screen/editorScreen.tsx index a88ee87a8..edb9fd7bd 100644 --- a/src/screens/editor/screen/editorScreen.tsx +++ b/src/screens/editor/screen/editorScreen.tsx @@ -59,6 +59,7 @@ class EditorScreen extends Component { isCommunitiesListModalOpen: false, selectedCommunity: null, selectedAccount: null, + scheduledFor:null }; } @@ -166,8 +167,13 @@ class EditorScreen extends Component { }; _handleOnSubmit = () => { - const { handleOnSubmit } = this.props; - const { fields } = this.state; + const { handleOnSubmit, handleSchedulePress } = this.props; + const { fields, scheduledFor } = this.state; + + if(scheduledFor && handleSchedulePress){ + handleSchedulePress(scheduledFor, fields); + return; + } if (handleOnSubmit) { handleOnSubmit({ fields }); @@ -188,6 +194,12 @@ class EditorScreen extends Component { } }; + _handleScheduleChange = (datetime:string|null) => { + this.setState({ + scheduledFor:datetime + }) + } + _handleSettingsPress = () => { if(this.editorSettingsModalRef){ this.editorSettingsModalRef.show(); @@ -324,6 +336,7 @@ class EditorScreen extends Component { isCommunitiesListModalOpen, selectedCommunity, selectedAccount, + scheduledFor, } = this.state; const { handleOnImagePicker, @@ -339,7 +352,7 @@ class EditorScreen extends Component { post, uploadedImage, handleOnBackPress, - handleDatePickerChange, + handleSchedulePress, handleRewardChange, handleBeneficiaries, currentAccount, @@ -348,10 +361,12 @@ class EditorScreen extends Component { onLoadDraftPress, thumbIndex, } = this.props; + const rightButtonText = intl.formatMessage({ - id: isEdit ? 'basic_header.update' : isReply ? 'basic_header.reply' : 'basic_header.publish', + id: isEdit ? 'basic_header.update' : isReply ? 'basic_header.reply' : scheduledFor ? 'basic_header.schedule' : 'basic_header.publish', }); + const _renderCommunityModal = () => { return ( handleDatePickerChange(date, fields)} + handleSchedulePress={(date) => handleSchedulePress(date, fields)} handleRewardChange={handleRewardChange} handleBeneficiaries={handleBeneficiaries} handleOnBackPress={handleOnBackPress} @@ -449,6 +464,7 @@ class EditorScreen extends Component { body={fields.body} handleThumbSelection={this._handleOnThumbSelection} handleRewardChange={handleRewardChange} + handleScheduleChange={this._handleScheduleChange} /> ); From 7126b3093384ce169f6261170dcf1bad3346a529 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Tue, 7 Dec 2021 13:11:38 +0500 Subject: [PATCH 06/17] added support for beneficiaries --- src/config/locales/en-US.json | 1 + .../children/beneficiarySelectionContent.tsx | 284 ++++++++++++++++++ .../editor/children/editorSettingsModal.tsx | 35 ++- src/screens/editor/children/styles.ts | 18 ++ src/screens/editor/screen/editorScreen.tsx | 2 + 5 files changed, 336 insertions(+), 4 deletions(-) create mode 100644 src/screens/editor/children/beneficiarySelectionContent.tsx diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 2bac07d30..2f510dd12 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -304,6 +304,7 @@ "limited_lastchar": "Tag must end with letter or number", "setting_schedule": "Scheduling Time", "setting_reward": "Reward", + "setting_reblog": "Reblog", "setting_beneficiary": "Beneficiary", "setting_thumb": "Set Thumbnail", "reward_default": "Default 50% / 50%", diff --git a/src/screens/editor/children/beneficiarySelectionContent.tsx b/src/screens/editor/children/beneficiarySelectionContent.tsx new file mode 100644 index 000000000..5056a04d6 --- /dev/null +++ b/src/screens/editor/children/beneficiarySelectionContent.tsx @@ -0,0 +1,284 @@ +import React, { useState, useEffect } from 'react'; +import { View, FlatList, Text } from 'react-native'; +import { useIntl } from 'react-intl'; +import { isArray, debounce } from 'lodash'; + +import styles from './styles'; +import EStyleSheet from 'react-native-extended-stylesheet'; + +import { useAppSelector } from '../../../hooks'; +import { FormInput, IconButton, TextButton } from '../../../components'; +import { Beneficiary } from '../../../redux/reducers/editorReducer'; +import { lookupAccounts } from '../../../providers/hive/dhive'; + +interface BeneficiarySelectionContent { + username:string, + draftId:string, + handleOnSaveBeneficiaries:()=>void +} + +const BeneficiarySelectionContent = ({ username, handleOnSaveBeneficiaries, draftId }) => { + const intl = useIntl(); + + const beneficiariesMap = useAppSelector(state => state.editor.beneficiariesMap) + + const [beneficiaries, setBeneficiaries] = useState([ + { account: username, weight: 10000, isValid: true}, + ]); + + const [newUsername, setNewUsername] = useState(''); + const [newWeight, setNewWeight] = useState(0); + const [isUsernameValid, setIsUsernameValid] = useState(false); + const [isWeightValid, setIsWeightValid] = useState(false); + const [newEditable, setNewEditable] = useState(false); + + useEffect(() => { + readTempBeneficiaries(); + }, [draftId]); + + + const readTempBeneficiaries = async () => { + if(beneficiariesMap){ + const tempBeneficiaries = beneficiariesMap[draftId || 'temp-beneficiaries']; + + if (isArray(tempBeneficiaries)) { + tempBeneficiaries.forEach((item) => { + item.isValid = true; + }); + setBeneficiaries(tempBeneficiaries); + } + } + + }; + + + const _onSavePress = () => { + if(newEditable){ + beneficiaries.push({ + account:newUsername, + weight:newWeight + }) + } + handleOnSaveBeneficiaries(beneficiaries); + _resetInputs(); + } + + + const _addAccount = () => { + + if(isUsernameValid && isWeightValid){ + beneficiaries.push({ + account:newUsername, + weight:newWeight, + }) + setBeneficiaries([...beneficiaries]); + } + + setIsUsernameValid(false); + setIsWeightValid(false); + setNewWeight(0); + setNewUsername(''); + setNewEditable(true); + }; + + + + const _onWeightInputChange = (value) => { + let _value = (parseInt(value, 10) || 0) * 100; + const _diff = _value - newWeight; + beneficiaries[0].weight = beneficiaries[0].weight - _diff; + setNewWeight(_value) + setIsWeightValid(_value > 0 && _value <= 10000) + setBeneficiaries([...beneficiaries]); + }; + + + const _lookupAccounts = debounce((username) => { + + lookupAccounts(username).then((res) => { + const isValid = res.includes(username) + //check if username duplicates else lookup contacts, done here to avoid debounce and post call mismatch + const notExistAlready = !beneficiaries.find((item)=>item.account === username); + setIsUsernameValid(isValid && notExistAlready) + }); + }, 1000) + + + + const _onUsernameInputChange = (value) => { + setNewUsername(value); + _lookupAccounts(value); + }; + + const _resetInputs = () => { + if(newWeight){ + beneficiaries[0].weight = beneficiaries[0].weight + newWeight; + setBeneficiaries([...beneficiaries]) + setNewWeight(0); + } + setNewEditable(false); + setIsWeightValid(false); + setIsUsernameValid(false); + setNewUsername(''); + + } + + + + + const _renderHeader = () => ( + + + + {intl.formatMessage({ + id: 'beneficiary_modal.percent', + })} + + + + + {intl.formatMessage({ + id: 'beneficiary_modal.username', + })} + + + + ) + + + + const _renderInput = () => { + + return ( + + + _onWeightInputChange(value)} + onBlur={() => {}}//_onBlur(item)} + keyboardType='numeric' + /> + + + + _onUsernameInputChange(value)} + placeholder={intl.formatMessage({ + id: 'beneficiary_modal.username', + })} + type="username" + isFirstImage + value={newUsername} + inputStyle={styles.usernameInput} + wrapperStyle={styles.usernameFormInputWrapper} + /> + + + {isWeightValid && isUsernameValid ? ( + + ) : } + + + ); + }; + + + const _renderFooter = () => ( + <> + {newEditable && _renderInput()} + + + + + + + ) + + + const _renderItem = ({ item, index }) => { + const _isCurrentUser = item.account === username; + + const _onRemovePress = () => { + beneficiaries[0].weight = beneficiaries[0].weight + item.weight; + beneficiaries.splice(index, 1); + setBeneficiaries([...beneficiaries]); + } + + + return ( + + + + + + + + + {!_isCurrentUser ? ( + + ):( + + )} + + + ); + }; + + return ( + + {intl.formatMessage({id:'editor.beneficiaries'})} + + {_renderFooter()} + + ); +}; + +export default BeneficiarySelectionContent; \ No newline at end of file diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index f99441e11..f762cb7a2 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -1,10 +1,14 @@ import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react'; import { useIntl } from 'react-intl'; -import { View } from 'react-native'; -import { DateTimePicker, Modal, SettingsItem } from '../../../components'; +import { ScrollView, View } from 'react-native'; + +import { BeneficiaryModal, DateTimePicker, Modal, SettingsItem } from '../../../components'; import styles from './editorSettingsModalStyles'; import ThumbSelectionContent from './thumbSelectionContent'; import {View as AnimatedView} from 'react-native-animatable'; +import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; +import BeneficiarySelectionContent from './beneficiarySelectionContent'; +import { Beneficiary } from '../../../redux/reducers/editorReducer'; const REWARD_TYPES = [ { @@ -30,16 +34,20 @@ export interface EditorSettingsModalRef { interface EditorSettingsModalProps { body:string; + draftId:string; handleRewardChange:(rewardType:string)=>void; handleThumbSelection:(index:number)=>void; handleScheduleChange:(datetime:string|null)=>void; + handleBeneficiariesChange:(beneficiaries:Beneficiary[])=>void; } const EditorSettingsModal = forwardRef(({ body, + draftId, handleRewardChange, handleThumbSelection, - handleScheduleChange + handleScheduleChange, + handleBeneficiariesChange, }: EditorSettingsModalProps, ref) => { const intl = useIntl(); @@ -86,6 +94,7 @@ const EditorSettingsModal = forwardRef(({ const _renderContent = ( + + {/* */} + + + + + ) @@ -142,7 +169,7 @@ const EditorSettingsModal = forwardRef(({ isFullScreen isCloseButton presentationStyle="formSheet" - title={"Editor Settings"} + title={"Post Settings"} animationType="slide" style={styles.modalStyle} > diff --git a/src/screens/editor/children/styles.ts b/src/screens/editor/children/styles.ts index cd532031e..9448482ec 100644 --- a/src/screens/editor/children/styles.ts +++ b/src/screens/editor/children/styles.ts @@ -32,4 +32,22 @@ export default EStyleSheet.create({ listContainer:{ paddingBottom:getBottomSpace() + 16, }, + container:{ + paddingVertical:16 + }, + bodyWrapper: { flex: 1, paddingTop: 20, paddingBottom:20}, + inputWrapper: { flexDirection: 'row', alignItems: 'center' }, + contentLabel: { color: '$iconColor', marginTop:4 }, + weightInput: {width:80}, + weightFormInput: { textAlign: 'center', color: '$primaryBlack' }, + weightFormInputWrapper: { marginTop: 8 }, + usernameInput: { flex:1, color: '$primaryBlack', marginLeft: 16 }, + usernameFormInputWrapper: { marginTop: 8 }, + footerWrapper: { paddingTop:16 }, + saveButton: { + width: 140, + height: 44, + alignSelf: 'flex-end', + justifyContent: 'center', + }, }); diff --git a/src/screens/editor/screen/editorScreen.tsx b/src/screens/editor/screen/editorScreen.tsx index edb9fd7bd..47181d16d 100644 --- a/src/screens/editor/screen/editorScreen.tsx +++ b/src/screens/editor/screen/editorScreen.tsx @@ -462,9 +462,11 @@ class EditorScreen extends Component { (this.editorSettingsModalRef = componentRef)} body={fields.body} + draftId={draftId} handleThumbSelection={this._handleOnThumbSelection} handleRewardChange={handleRewardChange} handleScheduleChange={this._handleScheduleChange} + handleBeneficiariesChange={handleBeneficiaries} /> ); From 2cffa636eae205e37a6f8f83e4228460316afe45 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Tue, 7 Dec 2021 13:11:53 +0500 Subject: [PATCH 07/17] updated thumb empty label style --- src/screens/editor/children/thumbSelectionContent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screens/editor/children/thumbSelectionContent.tsx b/src/screens/editor/children/thumbSelectionContent.tsx index 1e36941ac..cb7b6448f 100644 --- a/src/screens/editor/children/thumbSelectionContent.tsx +++ b/src/screens/editor/children/thumbSelectionContent.tsx @@ -57,7 +57,7 @@ const ThumbSelectionContent = ({body, thumbIndex, onThumbSelection}: ThumbSelect {intl.formatMessage({id:'editor.select_thumb'})} { needMore ? ( - Add more images to select thumbnail + Add more images to post ):( Date: Tue, 7 Dec 2021 13:16:10 +0500 Subject: [PATCH 08/17] reading username in beneficiary content --- ios/Podfile.lock | 2 +- .../children/beneficiarySelectionContent.tsx | 5 ++--- src/screens/editor/screen/editorScreen.tsx | 14 +++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 9ad7d0c49..a0f02f3ba 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -772,4 +772,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 9c48318ea254e2c78005a7a0c2d8bfc14ddd783d -COCOAPODS: 1.10.1 +COCOAPODS: 1.10.2 diff --git a/src/screens/editor/children/beneficiarySelectionContent.tsx b/src/screens/editor/children/beneficiarySelectionContent.tsx index 5056a04d6..2a2b187b7 100644 --- a/src/screens/editor/children/beneficiarySelectionContent.tsx +++ b/src/screens/editor/children/beneficiarySelectionContent.tsx @@ -12,15 +12,15 @@ import { Beneficiary } from '../../../redux/reducers/editorReducer'; import { lookupAccounts } from '../../../providers/hive/dhive'; interface BeneficiarySelectionContent { - username:string, draftId:string, handleOnSaveBeneficiaries:()=>void } -const BeneficiarySelectionContent = ({ username, handleOnSaveBeneficiaries, draftId }) => { +const BeneficiarySelectionContent = ({handleOnSaveBeneficiaries, draftId }) => { const intl = useIntl(); const beneficiariesMap = useAppSelector(state => state.editor.beneficiariesMap) + const username = useAppSelector(state=>state.account.currentAccount.name) const [beneficiaries, setBeneficiaries] = useState([ { account: username, weight: 10000, isValid: true}, @@ -125,7 +125,6 @@ const BeneficiarySelectionContent = ({ username, handleOnSaveBeneficiaries, draf - const _renderHeader = () => ( diff --git a/src/screens/editor/screen/editorScreen.tsx b/src/screens/editor/screen/editorScreen.tsx index 47181d16d..6d921fb10 100644 --- a/src/screens/editor/screen/editorScreen.tsx +++ b/src/screens/editor/screen/editorScreen.tsx @@ -460,13 +460,13 @@ class EditorScreen extends Component { onThumbSelection={this._handleOnThumbSelection} /> (this.editorSettingsModalRef = componentRef)} - body={fields.body} - draftId={draftId} - handleThumbSelection={this._handleOnThumbSelection} - handleRewardChange={handleRewardChange} - handleScheduleChange={this._handleScheduleChange} - handleBeneficiariesChange={handleBeneficiaries} + ref={(componentRef) => (this.editorSettingsModalRef = componentRef)} + body={fields.body} + draftId={draftId} + handleThumbSelection={this._handleOnThumbSelection} + handleRewardChange={handleRewardChange} + handleScheduleChange={this._handleScheduleChange} + handleBeneficiariesChange={handleBeneficiaries} /> ); From 1f83c5c1a7a3a09f2e6e80be22125b7c7286f16b Mon Sep 17 00:00:00 2001 From: noumantahir Date: Tue, 7 Dec 2021 13:26:50 +0500 Subject: [PATCH 09/17] triming user input --- src/screens/editor/children/beneficiarySelectionContent.tsx | 2 +- src/screens/editor/children/editorSettingsModal.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/screens/editor/children/beneficiarySelectionContent.tsx b/src/screens/editor/children/beneficiarySelectionContent.tsx index 2a2b187b7..c28ea9cb8 100644 --- a/src/screens/editor/children/beneficiarySelectionContent.tsx +++ b/src/screens/editor/children/beneficiarySelectionContent.tsx @@ -167,7 +167,7 @@ const BeneficiarySelectionContent = ({handleOnSaveBeneficiaries, draftId }) => { rightIconName="at" iconType="MaterialCommunityIcons" isValid={isUsernameValid} - onChange={(value) => _onUsernameInputChange(value)} + onChange={(value) => _onUsernameInputChange(value.trim())} placeholder={intl.formatMessage({ id: 'beneficiary_modal.username', })} diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index f762cb7a2..6d41360cb 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -151,7 +151,6 @@ const EditorSettingsModal = forwardRef(({ /> From 3addec09c581d6fbbe3599cd27f6c55ee8891c7d Mon Sep 17 00:00:00 2001 From: noumantahir Date: Tue, 7 Dec 2021 23:31:17 +0500 Subject: [PATCH 10/17] added reblog setting support --- .../editor/children/editorSettingsModal.tsx | 25 ++++++++++++++----- src/screens/editor/screen/editorScreen.tsx | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 6d41360cb..6ae9391ac 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -1,8 +1,8 @@ import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react'; import { useIntl } from 'react-intl'; -import { ScrollView, View } from 'react-native'; +import { View } from 'react-native'; -import { BeneficiaryModal, DateTimePicker, Modal, SettingsItem } from '../../../components'; +import { DateTimePicker, Modal, SettingsItem } from '../../../components'; import styles from './editorSettingsModalStyles'; import ThumbSelectionContent from './thumbSelectionContent'; import {View as AnimatedView} from 'react-native-animatable'; @@ -35,19 +35,23 @@ export interface EditorSettingsModalRef { interface EditorSettingsModalProps { body:string; draftId:string; + isCommunityPost:boolean; handleRewardChange:(rewardType:string)=>void; handleThumbSelection:(index:number)=>void; handleScheduleChange:(datetime:string|null)=>void; handleBeneficiariesChange:(beneficiaries:Beneficiary[])=>void; + handleShouldReblogChange:(shouldReblog:boolean)=>void; } const EditorSettingsModal = forwardRef(({ body, draftId, + isCommunityPost, handleRewardChange, handleThumbSelection, handleScheduleChange, handleBeneficiariesChange, + handleShouldReblogChange, }: EditorSettingsModalProps, ref) => { const intl = useIntl(); @@ -55,6 +59,7 @@ const EditorSettingsModal = forwardRef(({ const [rewardTypeIndex, setRewardTypeIndex] = useState(0); const [thumbIndex, setThumbIndex] = useState(0); const [scheduleLater, setScheduleLater] = useState(false) + const [shouldReblog, setShouldReblog] = useState(false); const [scheduledFor, setScheduledFor] = useState(''); useEffect(() => { @@ -71,6 +76,10 @@ const EditorSettingsModal = forwardRef(({ handleScheduleChange(scheduledFor) } }, [scheduleLater, scheduledFor]) + + useEffect(() => { + handleShouldReblogChange(shouldReblog) + }, [shouldReblog]) useImperativeHandle(ref, () => ({ @@ -134,15 +143,19 @@ const EditorSettingsModal = forwardRef(({ handleOnChange={_handleRewardChange} /> - {/* */} + isOn={shouldReblog} + handleOnChange={setShouldReblog} + /> + )} + (this.editorSettingsModalRef = componentRef)} body={fields.body} draftId={draftId} + isCommunityPost={false} handleThumbSelection={this._handleOnThumbSelection} handleRewardChange={handleRewardChange} handleScheduleChange={this._handleScheduleChange} handleBeneficiariesChange={handleBeneficiaries} + handleShouldReblogChange={()=>{}} /> ); From 46695eb13f8d7c051af20f212864dc07350d65a8 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 8 Dec 2021 00:05:24 +0500 Subject: [PATCH 11/17] connected shouldReblog option to community selection and editorContainer --- .../editor/children/editorSettingsModal.tsx | 6 ++++++ .../editor/container/editorContainer.tsx | 17 +++++++++++++++-- src/screens/editor/screen/editorScreen.tsx | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 6ae9391ac..6a7acd901 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -80,6 +80,12 @@ const EditorSettingsModal = forwardRef(({ useEffect(() => { handleShouldReblogChange(shouldReblog) }, [shouldReblog]) + + useEffect(() => { + if(!isCommunityPost && shouldReblog){ + setShouldReblog(false); + } + }, [isCommunityPost]) useImperativeHandle(ref, () => ({ diff --git a/src/screens/editor/container/editorContainer.tsx b/src/screens/editor/container/editorContainer.tsx index e117d1ed2..bb9740819 100644 --- a/src/screens/editor/container/editorContainer.tsx +++ b/src/screens/editor/container/editorContainer.tsx @@ -74,6 +74,7 @@ class EditorContainer extends Component { sharedSnippetText: null, onLoadDraftPress: false, thumbIndex: 0, + shouldReblog:false }; } @@ -573,6 +574,7 @@ class EditorContainer extends Component { }; _submitPost = async ({ fields, scheduleDate }: { fields: any, scheduleDate?: string }) => { + const { currentAccount, dispatch, @@ -581,7 +583,9 @@ class EditorContainer extends Component { pinCode, // isDefaultFooter, } = this.props; - const { rewardType, beneficiaries, isPostSending, thumbIndex, draftId } = this.state; + const { rewardType, beneficiaries, isPostSending, thumbIndex, draftId} = this.state; + + if (isPostSending) { return; @@ -855,9 +859,10 @@ class EditorContainer extends Component { }; _handleSubmit = (form: any) => { - const { isReply, isEdit } = this.state; + const { isReply, isEdit, shouldReblog } = this.state; const { intl } = this.props; + if (isReply && !isEdit) { this._submitReply(form.fields); } else if (isEdit) { @@ -1060,6 +1065,13 @@ class EditorContainer extends Component { dispatch(setBeneficiaries(draftId || 'temp-beneficiaries', value)); }; + _handleShouldReblogChange = (value:boolean) => { + this.setState({ + shouldReblog:value + }) + } + + _handleSetThumbIndex = (index: number) => { this.setState({ thumbIndex: index @@ -1095,6 +1107,7 @@ class EditorContainer extends Component { draftPost={draftPost} handleRewardChange={this._handleRewardChange} handleBeneficiaries={this._handleBeneficiaries} + handleShouldReblogChange={this._handleShouldReblogChange} handleSchedulePress={this._handleSchedulePress} handleFormChanged={this._handleFormChanged} handleOnBackPress={() => { }} diff --git a/src/screens/editor/screen/editorScreen.tsx b/src/screens/editor/screen/editorScreen.tsx index 80388f06b..46cd22cf0 100644 --- a/src/screens/editor/screen/editorScreen.tsx +++ b/src/screens/editor/screen/editorScreen.tsx @@ -355,6 +355,7 @@ class EditorScreen extends Component { handleSchedulePress, handleRewardChange, handleBeneficiaries, + handleShouldReblogChange, currentAccount, autoFocusText, sharedSnippetText, @@ -463,12 +464,12 @@ class EditorScreen extends Component { ref={(componentRef) => (this.editorSettingsModalRef = componentRef)} body={fields.body} draftId={draftId} - isCommunityPost={false} + isCommunityPost={selectedCommunity !== null} handleThumbSelection={this._handleOnThumbSelection} handleRewardChange={handleRewardChange} handleScheduleChange={this._handleScheduleChange} handleBeneficiariesChange={handleBeneficiaries} - handleShouldReblogChange={()=>{}} + handleShouldReblogChange={handleShouldReblogChange} /> ); From dd7df3f7cb13bb585c6297909ce1443836c6c24d Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 15 Dec 2021 15:20:58 +0500 Subject: [PATCH 12/17] fixed bug, no beneficiaries showing up --- src/screens/editor/children/beneficiarySelectionContent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screens/editor/children/beneficiarySelectionContent.tsx b/src/screens/editor/children/beneficiarySelectionContent.tsx index c28ea9cb8..dfbad293f 100644 --- a/src/screens/editor/children/beneficiarySelectionContent.tsx +++ b/src/screens/editor/children/beneficiarySelectionContent.tsx @@ -41,7 +41,7 @@ const BeneficiarySelectionContent = ({handleOnSaveBeneficiaries, draftId }) => { if(beneficiariesMap){ const tempBeneficiaries = beneficiariesMap[draftId || 'temp-beneficiaries']; - if (isArray(tempBeneficiaries)) { + if (isArray(tempBeneficiaries) && tempBeneficiaries.length > 0) { tempBeneficiaries.forEach((item) => { item.isValid = true; }); From ee4779f4155ed0e65ea160fe9a448700f125037b Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 15 Dec 2021 16:59:24 +0500 Subject: [PATCH 13/17] reblog post after publish if reblog flag is active --- .../editor/container/editorContainer.tsx | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/screens/editor/container/editorContainer.tsx b/src/screens/editor/container/editorContainer.tsx index bb9740819..d495daa60 100644 --- a/src/screens/editor/container/editorContainer.tsx +++ b/src/screens/editor/container/editorContainer.tsx @@ -22,6 +22,7 @@ import { getPurePost, grantPostingPermission, signImage, + reblog, } from '../../../providers/hive/dhive'; import { setDraftPost, getDraftPost } from '../../../realm/realm'; @@ -583,7 +584,7 @@ class EditorContainer extends Component { pinCode, // isDefaultFooter, } = this.props; - const { rewardType, beneficiaries, isPostSending, thumbIndex, draftId} = this.state; + const { rewardType, beneficiaries, isPostSending, thumbIndex, draftId, shouldReblog} = this.state; @@ -648,7 +649,24 @@ class EditorContainer extends Component { options, voteWeight, ) - .then(async () => { + .then((response) => { + + console.log(response); + + //reblog if flag is active + if(shouldReblog){ + reblog( + currentAccount, + pinCode, + author, + permlink + ).then((resp)=>{ + console.log("Successfully reblogged post", resp) + }).catch((err)=>{ + console.warn("Failed to reblog post", err) + }) + } + //post publish updates setDraftPost( { @@ -859,7 +877,7 @@ class EditorContainer extends Component { }; _handleSubmit = (form: any) => { - const { isReply, isEdit, shouldReblog } = this.state; + const { isReply, isEdit } = this.state; const { intl } = this.props; From 68aeb0e005dd1a3b431e724ce4fef737f22a3b6d Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 15 Dec 2021 18:25:25 +0500 Subject: [PATCH 14/17] support for updating thumbnail of already published posts --- .../basicHeader/view/basicHeaderView.js | 3 +- .../editor/children/editorSettingsModal.tsx | 119 ++++++++++-------- .../editor/container/editorContainer.tsx | 4 +- src/screens/editor/screen/editorScreen.tsx | 1 + 4 files changed, 68 insertions(+), 59 deletions(-) diff --git a/src/components/basicHeader/view/basicHeaderView.js b/src/components/basicHeader/view/basicHeaderView.js index 5bef6e655..a0482b012 100644 --- a/src/components/basicHeader/view/basicHeaderView.js +++ b/src/components/basicHeader/view/basicHeaderView.js @@ -37,7 +37,6 @@ const BasicHeaderView = ({ isModalHeader, isPreviewActive, isReply, - isEdit, quickTitle, rightButtonText, rightIconName, @@ -173,7 +172,7 @@ const BasicHeaderView = ({ onPress={() => (isModalHeader ? handleOnPressClose() : handleOnPressBackButton())} disabled={disabled} /> - {isHasIcons && !isReply && !isEdit && ( + {isHasIcons && !isReply && ( void; handleThumbSelection:(index:number)=>void; @@ -46,6 +47,7 @@ interface EditorSettingsModalProps { const EditorSettingsModal = forwardRef(({ body, draftId, + isEdit, isCommunityPost, handleRewardChange, handleThumbSelection, @@ -111,57 +113,61 @@ const EditorSettingsModal = forwardRef(({ const _renderContent = ( - { - setScheduleLater(index === 1) - }} - /> - - {scheduleLater && ( - - + { + setScheduleLater(index === 1) + }} /> - - + + {scheduleLater && ( + + + + + )} + + intl.formatMessage({ id: type.intlId})) + } + selectedOptionIndex={rewardTypeIndex} + handleOnChange={_handleRewardChange} + /> + + + {isCommunityPost && ( + + )} + )} - - intl.formatMessage({ id: type.intlId})) - } - selectedOptionIndex={rewardTypeIndex} - handleOnChange={_handleRewardChange} - /> - - - {isCommunityPost && ( - - )} - + - + {!isEdit && ( + + )} + @@ -190,8 +199,8 @@ const EditorSettingsModal = forwardRef(({ title={"Post Settings"} animationType="slide" style={styles.modalStyle} - > - {_renderContent} + > + {_renderContent} ); diff --git a/src/screens/editor/container/editorContainer.tsx b/src/screens/editor/container/editorContainer.tsx index d495daa60..2fd0f8a0d 100644 --- a/src/screens/editor/container/editorContainer.tsx +++ b/src/screens/editor/container/editorContainer.tsx @@ -758,7 +758,7 @@ class EditorContainer extends Component { _submitEdit = async (fields) => { const { currentAccount, pinCode } = this.props; - const { post, isEdit, isPostSending } = this.state; + const { post, isEdit, isPostSending, thumbIndex } = this.state; if (isPostSending) { return; @@ -784,7 +784,7 @@ class EditorContainer extends Component { newBody = patch; } - const meta = extractMetadata(fields.body); + const meta = extractMetadata(fields.body, thumbIndex); let jsonMeta = {}; diff --git a/src/screens/editor/screen/editorScreen.tsx b/src/screens/editor/screen/editorScreen.tsx index 46cd22cf0..cbdee9d91 100644 --- a/src/screens/editor/screen/editorScreen.tsx +++ b/src/screens/editor/screen/editorScreen.tsx @@ -464,6 +464,7 @@ class EditorScreen extends Component { ref={(componentRef) => (this.editorSettingsModalRef = componentRef)} body={fields.body} draftId={draftId} + isEdit={isEdit} isCommunityPost={selectedCommunity !== null} handleThumbSelection={this._handleOnThumbSelection} handleRewardChange={handleRewardChange} From 7f1dd524ce4eb04d6bb9da67e2c6d4f41945595c Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 15 Dec 2021 18:57:28 +0500 Subject: [PATCH 15/17] beneficiary weight calculation adjustments --- .../editor/children/beneficiarySelectionContent.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/screens/editor/children/beneficiarySelectionContent.tsx b/src/screens/editor/children/beneficiarySelectionContent.tsx index dfbad293f..a45c105cf 100644 --- a/src/screens/editor/children/beneficiarySelectionContent.tsx +++ b/src/screens/editor/children/beneficiarySelectionContent.tsx @@ -42,9 +42,14 @@ const BeneficiarySelectionContent = ({handleOnSaveBeneficiaries, draftId }) => { const tempBeneficiaries = beneficiariesMap[draftId || 'temp-beneficiaries']; if (isArray(tempBeneficiaries) && tempBeneficiaries.length > 0) { - tempBeneficiaries.forEach((item) => { + let othersWeight = 0; + tempBeneficiaries.forEach((item, index) => { item.isValid = true; + if(index > 0){ + othersWeight += item.weight + } }); + tempBeneficiaries[0].weight = 10000 - othersWeight; setBeneficiaries(tempBeneficiaries); } } @@ -223,6 +228,7 @@ const BeneficiarySelectionContent = ({handleOnSaveBeneficiaries, draftId }) => { beneficiaries[0].weight = beneficiaries[0].weight + item.weight; beneficiaries.splice(index, 1); setBeneficiaries([...beneficiaries]); + handleOnSaveBeneficiaries(beneficiaries); } From 1734885f9b905c23f79f5ce0c04667aaef84b5f8 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 15 Dec 2021 22:02:04 +0500 Subject: [PATCH 16/17] updated strings in favour of translations --- .../postDropdown/container/postDropdownContainer.tsx | 2 +- src/config/locales/en-US.json | 9 +++++++-- .../editor/children/beneficiarySelectionContent.tsx | 8 +++++--- src/screens/editor/children/editorSettingsModal.tsx | 8 ++++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/postDropdown/container/postDropdownContainer.tsx b/src/components/postDropdown/container/postDropdownContainer.tsx index 688476459..7b8e5df7d 100644 --- a/src/components/postDropdown/container/postDropdownContainer.tsx +++ b/src/components/postDropdown/container/postDropdownContainer.tsx @@ -1,7 +1,7 @@ import React, { PureComponent, Fragment } from 'react'; import { connect } from 'react-redux'; import { withNavigation } from 'react-navigation'; -import { Share, Alert } from 'react-native'; +import { Share } from 'react-native'; import ActionSheet from 'react-native-actionsheet'; import { injectIntl } from 'react-intl'; import get from 'lodash/get'; diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 2f510dd12..d810ac709 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -330,7 +330,11 @@ "draft_save_success":"Draft Saved", "draft_save_fail":"Failed to save draft", "select_thumb":"Select Post Thumbnail", - "two_thumbs_required":"Add more images in your post before setting thumbnail" + "two_thumbs_required":"Add more images in your post before setting thumbnail", + "scheduled_for":"Scheduled For", + "scheduled_immediate":"Immediate", + "scheduled_later":"Later", + "settings_title":"Post Settings" }, "snippets":{ "label_no_snippets":"No Snippets Found", @@ -673,7 +677,8 @@ "percent": "Percent", "username": "Username", "addAccount": "Add Account", - "save": "Save" + "save": "Save", + "cancel":"Cancel" }, "welcome":{ "label":"Welcome to", diff --git a/src/screens/editor/children/beneficiarySelectionContent.tsx b/src/screens/editor/children/beneficiarySelectionContent.tsx index a45c105cf..ebb25bf76 100644 --- a/src/screens/editor/children/beneficiarySelectionContent.tsx +++ b/src/screens/editor/children/beneficiarySelectionContent.tsx @@ -205,9 +205,11 @@ const BeneficiarySelectionContent = ({handleOnSaveBeneficiaries, draftId }) => { {newEditable && _renderInput()} { ); }; -export default BeneficiarySelectionContent; \ No newline at end of file +export default BeneficiarySelectionContent; diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 74b85ac81..0ed2548a6 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -116,12 +116,12 @@ const EditorSettingsModal = forwardRef(({ {!isEdit && ( <> { @@ -196,7 +196,7 @@ const EditorSettingsModal = forwardRef(({ isFullScreen isCloseButton presentationStyle="formSheet" - title={"Post Settings"} + title={intl.formatMessage({id:"editor.settings_title"})} animationType="slide" style={styles.modalStyle} > From b4094efe16e077263e71bfff71332944ffec6b33 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 15 Dec 2021 22:03:55 +0500 Subject: [PATCH 17/17] end of lines added --- src/screens/editor/children/editorSettingsModal.tsx | 2 -- src/screens/editor/children/editorSettingsModalStyles.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/screens/editor/children/editorSettingsModal.tsx b/src/screens/editor/children/editorSettingsModal.tsx index 0ed2548a6..65b3d0234 100644 --- a/src/screens/editor/children/editorSettingsModal.tsx +++ b/src/screens/editor/children/editorSettingsModal.tsx @@ -207,5 +207,3 @@ const EditorSettingsModal = forwardRef(({ }); export default EditorSettingsModal - - diff --git a/src/screens/editor/children/editorSettingsModalStyles.ts b/src/screens/editor/children/editorSettingsModalStyles.ts index fd2e21bc8..6758d9a3d 100644 --- a/src/screens/editor/children/editorSettingsModalStyles.ts +++ b/src/screens/editor/children/editorSettingsModalStyles.ts @@ -103,4 +103,4 @@ export default EStyleSheet.create({ top:16, right:16 } as ViewStyle -}) \ No newline at end of file +})