mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 03:11:38 +03:00
saving quick reply draft more frequently
This commit is contained in:
parent
2fae22c049
commit
63a9506f3c
@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
import EStyleSheet from 'react-native-extended-stylesheet';
|
||||
import styles from './quickReplyModalStyles';
|
||||
import { View, Text, Alert, TouchableOpacity, Keyboard, Platform } from 'react-native';
|
||||
@ -14,11 +14,12 @@ import {
|
||||
updateDraftCache,
|
||||
} from '../../redux/actions/cacheActions';
|
||||
import { default as ROUTES } from '../../constants/routeNames';
|
||||
import get from 'lodash/get';
|
||||
import {get, debounce} from 'lodash';
|
||||
import { navigate } from '../../navigation/service';
|
||||
import { postBodySummary } from '@ecency/render-helper';
|
||||
import { Draft } from '../../redux/reducers/cacheReducer';
|
||||
import { RootState } from '../../redux/store/store';
|
||||
import comment from '../../constants/options/comment';
|
||||
|
||||
export interface QuickReplyModalContentProps {
|
||||
fetchPost?: any;
|
||||
@ -73,13 +74,13 @@ export const QuickReplyModalContent = ({
|
||||
};
|
||||
|
||||
// add quick comment value into cache
|
||||
const _addQuickCommentIntoCache = () => {
|
||||
const _addQuickCommentIntoCache = (value = commentValue) => {
|
||||
const date = new Date();
|
||||
const updatedStamp = date.toISOString().substring(0, 19);
|
||||
|
||||
const quickCommentDraftData: Draft = {
|
||||
author: currentAccount.name,
|
||||
body: commentValue,
|
||||
body: value,
|
||||
created: quickCommentDraft ? quickCommentDraft.created : updatedStamp,
|
||||
updated: updatedStamp,
|
||||
expiresAt: date.getTime() + 604800000, // 7 days expiry time
|
||||
@ -88,10 +89,14 @@ export const QuickReplyModalContent = ({
|
||||
//add quick comment cache entry
|
||||
dispatch(updateDraftCache(draftId, quickCommentDraftData));
|
||||
};
|
||||
|
||||
|
||||
// handle close press
|
||||
const _handleClosePress = () => {
|
||||
sheetModalRef.current?.setModalVisible(false);
|
||||
};
|
||||
|
||||
|
||||
// navigate to post on summary press
|
||||
const _handleOnSummaryPress = () => {
|
||||
Keyboard.dismiss();
|
||||
@ -105,6 +110,7 @@ export const QuickReplyModalContent = ({
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// handle submit reply
|
||||
const _submitReply = async () => {
|
||||
let stateTimer;
|
||||
@ -207,12 +213,23 @@ export const QuickReplyModalContent = ({
|
||||
params: {
|
||||
isReply: true,
|
||||
post: selectedPost,
|
||||
quickReplyText: commentValue,
|
||||
draftId: draftId,
|
||||
fetchPost,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const _deboucedCacheUpdate = useCallback(debounce(_addQuickCommentIntoCache, 500),[])
|
||||
|
||||
const _onChangeText = (value) => {
|
||||
setCommentValue(value);
|
||||
_deboucedCacheUpdate(value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//VIEW_RENDERERS
|
||||
|
||||
const _renderSheetHeader = () => (
|
||||
@ -284,9 +301,7 @@ export const QuickReplyModalContent = ({
|
||||
<View style={styles.inputContainer}>
|
||||
<TextInput
|
||||
innerRef={inputRef}
|
||||
onChangeText={(value) => {
|
||||
setCommentValue(value);
|
||||
}}
|
||||
onChangeText={_onChangeText}
|
||||
value={commentValue}
|
||||
// autoFocus
|
||||
placeholder={intl.formatMessage({
|
||||
|
Loading…
Reference in New Issue
Block a user