load quick comment value from cache

This commit is contained in:
Sadaqat Ali 2022-06-07 09:16:54 +05:00
parent 93dd7e6508
commit ba5f3f1e33

View File

@ -13,6 +13,7 @@ import { default as ROUTES } from '../../constants/routeNames';
import get from 'lodash/get'; import get from 'lodash/get';
import { navigate } from '../../navigation/service'; import { navigate } from '../../navigation/service';
import { postBodySummary } from '@ecency/render-helper'; import { postBodySummary } from '@ecency/render-helper';
import { QuickComment } from '../../redux/reducers/cacheReducer';
export interface QuickReplyModalContentProps { export interface QuickReplyModalContentProps {
fetchPost?: any; fetchPost?: any;
@ -27,40 +28,47 @@ export const QuickReplyModalContent = ({
selectedPost, selectedPost,
inputRef, inputRef,
sheetModalRef, sheetModalRef,
handleCloseRef handleCloseRef,
}: QuickReplyModalContentProps) => { }: QuickReplyModalContentProps) => {
const intl = useIntl(); const intl = useIntl();
const dispatch = useDispatch(); const dispatch = useDispatch();
const currentAccount = useSelector((state) => state.account.currentAccount); const currentAccount = useSelector((state) => state.account.currentAccount);
const pinCode = useSelector((state) => state.application.pin); const pinCode = useSelector((state) => state.application.pin);
const quickComments = useSelector((state) => state.cache.quickComments);
const [commentValue, setCommentValue] = useState(''); const [commentValue, setCommentValue] = useState('');
const [isSending, setIsSending] = useState(false); const [isSending, setIsSending] = useState(false);
const headerText = const headerText =
selectedPost && (selectedPost.summary || postBodySummary(selectedPost, 150, Platform.OS)); selectedPost && (selectedPost.summary || postBodySummary(selectedPost, 150, Platform.OS));
const parentAuthor = selectedPost ? selectedPost.author : '';
const parentPermlink = selectedPost ? selectedPost.permlink : '';
const path = `${parentAuthor}/${parentPermlink}`;
useEffect(() => {
handleCloseRef.current = handleSheetClose;
}, [commentValue])
// reset the state when post changes
useEffect(() => { useEffect(() => {
setCommentValue(''); handleCloseRef.current = handleSheetClose;
}, [commentValue]);
// load quick comment value from cache
useEffect(() => {
if (quickComments.has(path)) {
const quickComment: QuickComment = quickComments.get(path);
setCommentValue(quickComment.body);
} else {
setCommentValue('');
}
}, [selectedPost]); }, [selectedPost]);
// handlers // handlers
const handleSheetClose = () => { const handleSheetClose = () => {
console.log('sheet closed!'); console.log('sheet closed!');
if(!commentValue){ if (!commentValue) {
return; return;
} }
console.log('commentValue : ', commentValue); console.log('commentValue : ', commentValue);
const parentAuthor = selectedPost.author;
const parentPermlink = selectedPost.permlink;
const date = new Date(); const date = new Date();
const updatedStamp = date.toISOString().substring(0, 19); const updatedStamp = date.toISOString().substring(0, 19);
@ -70,16 +78,11 @@ export const QuickReplyModalContent = ({
created: updatedStamp, created: updatedStamp,
updated: updatedStamp, updated: updatedStamp,
expiresAt: date.getTime() + 6000000, expiresAt: date.getTime() + 6000000,
} };
//add quick comment cache entry //add quick comment cache entry
dispatch( dispatch(updateQuickCommentCache(`${parentAuthor}/${parentPermlink}`, quickCommentCache));
updateQuickCommentCache( };
`${parentAuthor}/${parentPermlink}`,
quickCommentCache
),
);
}
// handle close press // handle close press
const _handleClosePress = () => { const _handleClosePress = () => {