Merge remote-tracking branch 'origin/development' into nt/navigation

This commit is contained in:
noumantahir 2022-08-17 23:18:18 +05:00
commit 7fd2d3471e
4 changed files with 21 additions and 55 deletions

View File

@ -44,6 +44,7 @@ const BeneficiarySelectionContent = ({
const beneficiariesMap = useAppSelector((state) => state.editor.beneficiariesMap); const beneficiariesMap = useAppSelector((state) => state.editor.beneficiariesMap);
const username = useAppSelector((state) => state.account.currentAccount.name); const username = useAppSelector((state) => state.account.currentAccount.name);
const DEFAULT_BENEFICIARY = { account: username, weight: 10000 };
const [beneficiaries, setBeneficiaries] = useState<Beneficiary[]>([ const [beneficiaries, setBeneficiaries] = useState<Beneficiary[]>([
{ account: username, weight: 10000, autoPowerUp: false }, { account: username, weight: 10000, autoPowerUp: false },
@ -94,8 +95,9 @@ const BeneficiarySelectionContent = ({
const readTempBeneficiaries = async () => { const readTempBeneficiaries = async () => {
if (beneficiariesMap) { if (beneficiariesMap) {
const tempBeneficiaries = beneficiariesMap[draftId || TEMP_BENEFICIARIES_ID]; const savedBeneficiareis = beneficiariesMap[draftId || TEMP_BENEFICIARIES_ID];
const tempBeneficiaries = savedBeneficiareis && savedBeneficiareis.length ? [DEFAULT_BENEFICIARY, ...beneficiariesMap[draftId || TEMP_BENEFICIARIES_ID]] : [DEFAULT_BENEFICIARY];
if (isArray(tempBeneficiaries) && tempBeneficiaries.length > 0) { if (isArray(tempBeneficiaries) && tempBeneficiaries.length > 0) {
//weight correction algorithm. //weight correction algorithm.
let othersWeight = 0; let othersWeight = 0;
@ -105,17 +107,17 @@ const BeneficiarySelectionContent = ({
} }
}); });
tempBeneficiaries[0].weight = 10000 - othersWeight; tempBeneficiaries[0].weight = 10000 - othersWeight;
setBeneficiaries(tempBeneficiaries); setBeneficiaries(tempBeneficiaries);
} }
} }
}; };
const _saveBeneficiaries = (value: Beneficiary[]) => { const _saveBeneficiaries = (value: Beneficiary[]) => {
const filteredBeneficiaries = value.filter((item) => item.account !== username); //remove default beneficiary from array while saving
if (handleSaveBeneficiary) { if (handleSaveBeneficiary) {
handleSaveBeneficiary(value); handleSaveBeneficiary(filteredBeneficiaries);
} else { } else {
dispatch(setBeneficiariesAction(draftId || TEMP_BENEFICIARIES_ID, value)); dispatch(setBeneficiariesAction(draftId || TEMP_BENEFICIARIES_ID, filteredBeneficiaries));
} }
}; };

View File

@ -37,7 +37,6 @@ interface PostOptionsModalProps {
isEdit:boolean; isEdit:boolean;
isCommunityPost:boolean; isCommunityPost:boolean;
rewardType: string; rewardType: string;
scheduledForDate: string | null;
handleRewardChange:(rewardType:string)=>void; handleRewardChange:(rewardType:string)=>void;
handleThumbSelection:(index:number)=>void; handleThumbSelection:(index:number)=>void;
handleScheduleChange:(datetime:string|null)=>void; handleScheduleChange:(datetime:string|null)=>void;
@ -52,7 +51,6 @@ const PostOptionsModal = forwardRef(({
isEdit, isEdit,
isCommunityPost, isCommunityPost,
rewardType, rewardType,
scheduledForDate,
handleRewardChange, handleRewardChange,
handleThumbSelection, handleThumbSelection,
handleScheduleChange, handleScheduleChange,
@ -63,13 +61,13 @@ const PostOptionsModal = forwardRef(({
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const [rewardTypeIndex, setRewardTypeIndex] = useState(0); const [rewardTypeIndex, setRewardTypeIndex] = useState(0);
const [scheduleLater, setScheduleLater] = useState(scheduledForDate ? true : false); const [scheduleLater, setScheduleLater] = useState(false);
const [shouldReblog, setShouldReblog] = useState(false); const [shouldReblog, setShouldReblog] = useState(false);
const [scheduledFor, setScheduledFor] = useState(''); const [scheduledFor, setScheduledFor] = useState('');
const [disableDone, setDisableDone] = useState(false); const [disableDone, setDisableDone] = useState(false);
// removed the useeffect causing index reset bug // removed the useeffect causing index reset bug
/*
useEffect(()=>{ useEffect(()=>{
if(!scheduleLater){ if(!scheduleLater){
handleScheduleChange(null) handleScheduleChange(null)
@ -77,22 +75,6 @@ const PostOptionsModal = forwardRef(({
handleScheduleChange(scheduledFor) handleScheduleChange(scheduledFor)
} }
}, [scheduleLater, scheduledFor]) }, [scheduleLater, scheduledFor])
*/
useEffect(() => {
if(scheduledFor){
handleScheduleChange(scheduledFor);
}
},[scheduledFor])
useEffect(() => {
if (scheduledForDate) {
setScheduleLater(true);
setScheduledFor(scheduledForDate);
} else {
setScheduleLater(false);
setScheduledFor('');
}
},[scheduledForDate])
useEffect(() => { useEffect(() => {
handleShouldReblogChange(shouldReblog) handleShouldReblogChange(shouldReblog)
@ -168,7 +150,6 @@ const PostOptionsModal = forwardRef(({
<AnimatedView animation="flipInX" duration={700}> <AnimatedView animation="flipInX" duration={700}>
<DateTimePicker <DateTimePicker
type="datetime" type="datetime"
selectedDate={scheduledForDate}
onChanged={_handleDatePickerChange} onChanged={_handleDatePickerChange}
disabled={true} disabled={true}
/> />

View File

@ -5,6 +5,7 @@ import { Alert } from 'react-native';
import ImagePicker from 'react-native-image-crop-picker'; import ImagePicker from 'react-native-image-crop-picker';
import get from 'lodash/get'; import get from 'lodash/get';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import { isArray } from 'lodash';
// Services and Actions // Services and Actions
import { Buffer } from 'buffer'; import { Buffer } from 'buffer';
@ -76,7 +77,6 @@ class EditorContainer extends Component<any, any> {
isDraft: false, isDraft: false,
community: [], community: [],
rewardType: 'default', rewardType: 'default',
scheduledForDate: null,
sharedSnippetText: null, sharedSnippetText: null,
onLoadDraftPress: false, onLoadDraftPress: false,
thumbIndex: 0, thumbIndex: 0,
@ -254,7 +254,7 @@ class EditorContainer extends Component<any, any> {
// load meta from local/param drfat into state // load meta from local/param drfat into state
_loadMeta = (draft: any) => { _loadMeta = (draft: any) => {
const { dispatch } = this.props; const { dispatch, currentAccount } = this.props;
// if meta exist on draft, get the index of 1st image in meta from images urls in body // if meta exist on draft, get the index of 1st image in meta from images urls in body
const body = draft.body; const body = draft.body;
if (draft.meta && draft.meta.image) { if (draft.meta && draft.meta.image) {
@ -264,12 +264,6 @@ class EditorContainer extends Component<any, any> {
thumbIndex: draftThumbIndex, thumbIndex: draftThumbIndex,
}); });
} }
// load schedule date
if (draft.meta && draft.meta.scheduledFor) {
this.setState({
scheduledForDate: draft.meta.scheduledFor,
});
}
// load beneficiaries and rewards data from meta field of draft // load beneficiaries and rewards data from meta field of draft
if (draft.meta && draft.meta.rewardType) { if (draft.meta && draft.meta.rewardType) {
@ -279,7 +273,10 @@ class EditorContainer extends Component<any, any> {
} }
if (draft._id && draft.meta && draft.meta.beneficiaries) { if (draft._id && draft.meta && draft.meta.beneficiaries) {
dispatch(setBeneficiaries(draft._id || TEMP_BENEFICIARIES_ID, draft.meta.beneficiaries)); if(isArray(draft.meta.beneficiaries)){
const filteredBeneficiaries = draft.meta.beneficiaries.filter((item) => item.account !== currentAccount.username); //remove default beneficiary from array while saving
dispatch(setBeneficiaries(draft._id || TEMP_BENEFICIARIES_ID, filteredBeneficiaries));
}
} }
} }
_requestKeyboardFocus = () => { _requestKeyboardFocus = () => {
@ -625,8 +622,8 @@ class EditorContainer extends Component<any, any> {
draftId: response._id, draftId: response._id,
}); });
} }
const filteredBeneficiaries = beneficiaries.filter((item) => item.account !== currentAccount.username); //remove default beneficiary from array while saving
dispatch(setBeneficiaries(response._id, beneficiaries)); dispatch(setBeneficiaries(response._id, filteredBeneficiaries));
dispatch(removeBeneficiaries(TEMP_BENEFICIARIES_ID)); dispatch(removeBeneficiaries(TEMP_BENEFICIARIES_ID));
//clear local copy if darft save is successful //clear local copy if darft save is successful
@ -1231,9 +1228,6 @@ class EditorContainer extends Component<any, any> {
this.setState({ rewardType: value }); this.setState({ rewardType: value });
}; };
_handleScheduleDateChange = (value) => {
this.setState({ scheduledForDate: value })
};
_handleShouldReblogChange = (value: boolean) => { _handleShouldReblogChange = (value: boolean) => {
this.setState({ this.setState({
@ -1270,7 +1264,6 @@ class EditorContainer extends Component<any, any> {
thumbIndex, thumbIndex,
uploadProgress, uploadProgress,
rewardType, rewardType,
scheduledForDate,
} = this.state; } = this.state;
const tags = route.params?.tags; const tags = route.params?.tags;
@ -1279,7 +1272,6 @@ class EditorContainer extends Component<any, any> {
autoFocusText={autoFocusText} autoFocusText={autoFocusText}
draftPost={draftPost} draftPost={draftPost}
handleRewardChange={this._handleRewardChange} handleRewardChange={this._handleRewardChange}
handleScheduleDateChange={this._handleScheduleDateChange}
handleShouldReblogChange={this._handleShouldReblogChange} handleShouldReblogChange={this._handleShouldReblogChange}
handleSchedulePress={this._handleSchedulePress} handleSchedulePress={this._handleSchedulePress}
handleFormChanged={this._handleFormChanged} handleFormChanged={this._handleFormChanged}
@ -1312,7 +1304,6 @@ class EditorContainer extends Component<any, any> {
setThumbIndex={this._handleSetThumbIndex} setThumbIndex={this._handleSetThumbIndex}
uploadProgress={uploadProgress} uploadProgress={uploadProgress}
rewardType={rewardType} rewardType={rewardType}
scheduledForDate={scheduledForDate}
getBeneficiaries={this._extractBeneficiaries} getBeneficiaries={this._extractBeneficiaries}
/> />

View File

@ -51,13 +51,13 @@ class EditorScreen extends Component {
isCommunitiesListModalOpen: false, isCommunitiesListModalOpen: false,
selectedCommunity: null, selectedCommunity: null,
selectedAccount: null, selectedAccount: null,
scheduledFor: (props.scheduledForDate && props.scheduledForDate) || null, scheduledFor: null,
}; };
} }
// Component Life Cycles // Component Life Cycles
componentDidMount() { componentDidMount() {
const { draftPost, currentAccount, scheduledForDate } = this.props; const { draftPost, currentAccount } = this.props;
if (draftPost) { if (draftPost) {
if (draftPost.tags?.length > 0 && isCommunity(draftPost.tags[0])) { if (draftPost.tags?.length > 0 && isCommunity(draftPost.tags[0])) {
@ -68,9 +68,6 @@ class EditorScreen extends Component {
}); });
} }
} }
if(scheduledForDate){
this._handleScheduleChange(scheduledForDate);
}
} }
componentWillUnmount() { componentWillUnmount() {
@ -204,11 +201,9 @@ class EditorScreen extends Component {
_handleScheduleChange = (datetime:string|null) => { _handleScheduleChange = (datetime:string|null) => {
const { handleScheduleDateChange } = this.props;
this.setState({ this.setState({
scheduledFor:datetime, scheduledFor:datetime,
}) })
handleScheduleDateChange(datetime);
} }
_handleRewardChange = (value) => { _handleRewardChange = (value) => {
@ -241,8 +236,8 @@ class EditorScreen extends Component {
}; };
_handleFormUpdate = (componentID, content) => { _handleFormUpdate = (componentID, content) => {
const { handleFormChanged, thumbIndex, rewardType, getBeneficiaries, scheduledForDate } = this.props; const { handleFormChanged, thumbIndex, rewardType, getBeneficiaries } = this.props;
const { fields: _fields, scheduledFor } = this.state; const { fields: _fields } = this.state;
const fields = { ..._fields }; const fields = { ..._fields };
if (componentID === 'body') { if (componentID === 'body') {
@ -257,7 +252,6 @@ class EditorScreen extends Component {
tags: fields.tags, tags: fields.tags,
beneficiaries: getBeneficiaries(), beneficiaries: getBeneficiaries(),
rewardType, rewardType,
scheduledFor: scheduledFor ? scheduledFor : scheduledForDate,
}); });
const jsonMeta = makeJsonMetadata(meta, fields.tags); const jsonMeta = makeJsonMetadata(meta, fields.tags);
fields.meta = jsonMeta; fields.meta = jsonMeta;
@ -389,7 +383,6 @@ class EditorScreen extends Component {
thumbIndex, thumbIndex,
uploadProgress, uploadProgress,
rewardType, rewardType,
scheduledForDate
} = this.props; } = this.props;
const rightButtonText = intl.formatMessage({ const rightButtonText = intl.formatMessage({
@ -491,7 +484,6 @@ class EditorScreen extends Component {
isEdit={isEdit} isEdit={isEdit}
isCommunityPost={selectedCommunity !== null} isCommunityPost={selectedCommunity !== null}
rewardType={rewardType} rewardType={rewardType}
scheduledForDate={scheduledForDate}
handleThumbSelection={this._handleOnThumbSelection} handleThumbSelection={this._handleOnThumbSelection}
handleRewardChange={this._handleRewardChange} handleRewardChange={this._handleRewardChange}
handleScheduleChange={this._handleScheduleChange} handleScheduleChange={this._handleScheduleChange}