mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-23 13:22:02 +03:00
fixed bug in editorSettingsModal causing reset of index
This commit is contained in:
parent
26a2d7b214
commit
dd32a427c8
@ -5,7 +5,7 @@ import serverList from '../../config/serverListApi';
|
||||
import bugsnagInstance from '../../config/bugsnag';
|
||||
import { SERVER_LIST } from '../../constants/options/api';
|
||||
import { parsePost } from '../../utils/postParser';
|
||||
import { extractMetadata } from '../../utils/editor';
|
||||
import { extractMetadata, makeJsonMetadata } from '../../utils/editor';
|
||||
|
||||
export const getCurrencyRate = (currency) =>
|
||||
api
|
||||
@ -66,7 +66,7 @@ export const deleteDraft = async (draftId:string) => {
|
||||
*/
|
||||
export const addDraft = async (title:string, body:string, tags:string, thumbIndex:number ) => {
|
||||
try {
|
||||
const meta = extractMetadata(body, thumbIndex)
|
||||
const meta = makeJsonMetadata(extractMetadata(body, thumbIndex), tags)
|
||||
const data = { title, body, tags, meta }
|
||||
const res = await ecencyApi.post('/private-api/drafts-add', data)
|
||||
const { drafts } = res.data;
|
||||
@ -91,7 +91,7 @@ export const addDraft = async (title:string, body:string, tags:string, thumbInde
|
||||
*/
|
||||
export const updateDraft = async (draftId:string, title:string, body:string, tags:string, thumbIndex:number, ) => {
|
||||
try {
|
||||
const meta = extractMetadata(body, thumbIndex)
|
||||
const meta = makeJsonMetadata(extractMetadata(body, thumbIndex), tags)
|
||||
const data = {id:draftId, title, body, tags, meta }
|
||||
const res = await ecencyApi.post(`/private-api/drafts-update`, data)
|
||||
if(res.data){
|
||||
|
@ -35,6 +35,7 @@ export interface EditorSettingsModalRef {
|
||||
interface EditorSettingsModalProps {
|
||||
body:string;
|
||||
draftId:string;
|
||||
thumbIndex:number,
|
||||
isEdit:boolean;
|
||||
isCommunityPost:boolean;
|
||||
handleRewardChange:(rewardType:string)=>void;
|
||||
@ -46,6 +47,7 @@ interface EditorSettingsModalProps {
|
||||
const EditorSettingsModal = forwardRef(({
|
||||
body,
|
||||
draftId,
|
||||
thumbIndex,
|
||||
isEdit,
|
||||
isCommunityPost,
|
||||
handleRewardChange,
|
||||
@ -57,17 +59,12 @@ const EditorSettingsModal = forwardRef(({
|
||||
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
const [rewardTypeIndex, setRewardTypeIndex] = useState(0);
|
||||
const [thumbIndex, setThumbIndex] = useState(0);
|
||||
const [scheduleLater, setScheduleLater] = useState(false)
|
||||
const [shouldReblog, setShouldReblog] = useState(false);
|
||||
const [scheduledFor, setScheduledFor] = useState('');
|
||||
const [disableDone, setDisableDone] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if(handleThumbSelection){
|
||||
handleThumbSelection(thumbIndex);
|
||||
}
|
||||
}, [thumbIndex])
|
||||
// removed the useeffect causing index reset bug
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
@ -112,6 +109,10 @@ const EditorSettingsModal = forwardRef(({
|
||||
setShowModal(false);
|
||||
}
|
||||
|
||||
// handle index change here instead of useeffetc
|
||||
const _handleThumbIndexSelection = (index:number) => {
|
||||
handleThumbSelection(index)
|
||||
}
|
||||
|
||||
const _renderContent = (
|
||||
<View style={{flex:1}}>
|
||||
@ -176,7 +177,7 @@ const EditorSettingsModal = forwardRef(({
|
||||
<ThumbSelectionContent
|
||||
body={body}
|
||||
thumbIndex={thumbIndex}
|
||||
onThumbSelection={setThumbIndex}
|
||||
onThumbSelection={_handleThumbIndexSelection}
|
||||
/>
|
||||
|
||||
{!isEdit && (
|
||||
|
@ -34,14 +34,14 @@ const ThumbSelectionContent = ({body, thumbIndex, onThumbSelection}: ThumbSelect
|
||||
|
||||
//VIEW_RENDERERS
|
||||
const _renderImageItem = ({item, index}:{item:string, index:number}) => {
|
||||
const _onPress = () => {
|
||||
const _onPress = () => {
|
||||
onThumbSelection(index);
|
||||
}
|
||||
|
||||
const selectedStyle = index === thumbIndex ? styles.selectedStyle : null
|
||||
|
||||
return (
|
||||
<TouchableOpacity onPress={_onPress} >
|
||||
<TouchableOpacity onPress={() => _onPress()} >
|
||||
<FastImage
|
||||
source={{uri:item}}
|
||||
style={{...styles.thumbStyle, ...selectedStyle}}
|
||||
|
@ -60,7 +60,7 @@ const ThumbSelectionModal = ({ onThumbSelection, thumbIndex }:ThumbSelectionModa
|
||||
const selectedStyle = index === thumbIndex ? styles.selectedStyle : null
|
||||
|
||||
return (
|
||||
<TouchableOpacity onPress={_onPress} >
|
||||
<TouchableOpacity onPress={() => _onPress()} >
|
||||
<FastImage
|
||||
source={{uri:item}}
|
||||
style={{...styles.thumbStyle, ...selectedStyle}}
|
||||
|
@ -38,6 +38,7 @@ import {
|
||||
makeJsonMetadataReply,
|
||||
makeJsonMetadataForUpdate,
|
||||
createPatch,
|
||||
extractImageUrls,
|
||||
} from '../../../utils/editor';
|
||||
// import { generateSignature } from '../../../utils/image';
|
||||
// Component
|
||||
@ -75,7 +76,7 @@ class EditorContainer extends Component {
|
||||
sharedSnippetText: null,
|
||||
onLoadDraftPress: false,
|
||||
thumbIndex: 0,
|
||||
shouldReblog:false
|
||||
shouldReblog:false,
|
||||
};
|
||||
}
|
||||
|
||||
@ -96,6 +97,17 @@ class EditorContainer extends Component {
|
||||
|
||||
if (navigationParams.draft) {
|
||||
_draft = navigationParams.draft;
|
||||
|
||||
// if meta exist on draft, get the index of 1st image in meta from images urls in body
|
||||
const body = _draft.body
|
||||
if(_draft.meta){
|
||||
const urls = extractImageUrls({body});
|
||||
const draftThumbIndex = urls.indexOf(_draft.meta.image[0])
|
||||
this.setState({
|
||||
thumbIndex:draftThumbIndex,
|
||||
})
|
||||
}
|
||||
|
||||
this.setState({
|
||||
draftId: _draft._id,
|
||||
isDraft: true,
|
||||
@ -1119,7 +1131,7 @@ class EditorContainer extends Component {
|
||||
} = this.state;
|
||||
|
||||
const tags = navigation.state.params && navigation.state.params.tags;
|
||||
|
||||
|
||||
return (
|
||||
<EditorScreen
|
||||
autoFocusText={autoFocusText}
|
||||
|
@ -462,6 +462,7 @@ class EditorScreen extends Component {
|
||||
ref={(componentRef) => (this.editorSettingsModalRef = componentRef)}
|
||||
body={fields.body}
|
||||
draftId={draftId}
|
||||
thumbIndex={thumbIndex}
|
||||
isEdit={isEdit}
|
||||
isCommunityPost={selectedCommunity !== null}
|
||||
handleThumbSelection={this._handleOnThumbSelection}
|
||||
|
Loading…
Reference in New Issue
Block a user