added quick comment cache when sheet is closed

This commit is contained in:
Sadaqat Ali 2022-06-07 09:02:23 +05:00
parent 1b1b6d0175
commit 93dd7e6508
7 changed files with 99 additions and 9 deletions

View File

@ -833,4 +833,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311 PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311
COCOAPODS: 1.11.3 COCOAPODS: 1.11.2

View File

@ -8,7 +8,7 @@ import { useSelector, useDispatch } from 'react-redux';
import { delay, generateReplyPermlink } from '../../utils/editor'; import { delay, generateReplyPermlink } from '../../utils/editor';
import { postComment } from '../../providers/hive/dhive'; import { postComment } from '../../providers/hive/dhive';
import { toastNotification } from '../../redux/actions/uiAction'; import { toastNotification } from '../../redux/actions/uiAction';
import { updateCommentCache } from '../../redux/actions/cacheActions'; import { updateCommentCache, updateQuickCommentCache } from '../../redux/actions/cacheActions';
import { default as ROUTES } from '../../constants/routeNames'; 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';
@ -19,6 +19,7 @@ export interface QuickReplyModalContentProps {
selectedPost?: any; selectedPost?: any;
inputRef?: any; inputRef?: any;
sheetModalRef?: any; sheetModalRef?: any;
handleCloseRef?: any;
} }
export const QuickReplyModalContent = ({ export const QuickReplyModalContent = ({
@ -26,6 +27,7 @@ export const QuickReplyModalContent = ({
selectedPost, selectedPost,
inputRef, inputRef,
sheetModalRef, sheetModalRef,
handleCloseRef
}: QuickReplyModalContentProps) => { }: QuickReplyModalContentProps) => {
const intl = useIntl(); const intl = useIntl();
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -38,6 +40,10 @@ export const QuickReplyModalContent = ({
const headerText = const headerText =
selectedPost && (selectedPost.summary || postBodySummary(selectedPost, 150, Platform.OS)); selectedPost && (selectedPost.summary || postBodySummary(selectedPost, 150, Platform.OS));
useEffect(() => {
handleCloseRef.current = handleSheetClose;
}, [commentValue])
// reset the state when post changes // reset the state when post changes
useEffect(() => { useEffect(() => {
setCommentValue(''); setCommentValue('');
@ -45,6 +51,36 @@ export const QuickReplyModalContent = ({
// handlers // handlers
const handleSheetClose = () => {
console.log('sheet closed!');
if(!commentValue){
return;
}
console.log('commentValue : ', commentValue);
const parentAuthor = selectedPost.author;
const parentPermlink = selectedPost.permlink;
const date = new Date();
const updatedStamp = date.toISOString().substring(0, 19);
const quickCommentCache = {
parent_permlink: parentPermlink,
body: commentValue,
created: updatedStamp,
updated: updatedStamp,
expiresAt: date.getTime() + 6000000,
}
//add quick comment cache entry
dispatch(
updateQuickCommentCache(
`${parentAuthor}/${parentPermlink}`,
quickCommentCache
),
);
}
// handle close press // handle close press
const _handleClosePress = () => { const _handleClosePress = () => {
sheetModalRef.current?.setModalVisible(false); sheetModalRef.current?.setModalVisible(false);
@ -237,7 +273,9 @@ export const QuickReplyModalContent = ({
<View style={styles.inputContainer}> <View style={styles.inputContainer}>
<TextInput <TextInput
innerRef={inputRef} innerRef={inputRef}
onChangeText={setCommentValue} onChangeText={(value) => {
setCommentValue(value);
}}
value={commentValue} value={commentValue}
// autoFocus // autoFocus
placeholder={intl.formatMessage({ placeholder={intl.formatMessage({

View File

@ -14,6 +14,7 @@ const QuickReplyModal = ({ fetchPost }: QuickReplyModalProps, ref) => {
const [selectedPost, setSelectedPost] = useState(null); const [selectedPost, setSelectedPost] = useState(null);
const sheetModalRef = useRef<ActionSheet>(); const sheetModalRef = useRef<ActionSheet>();
const inputRef = useRef<TextInput>(null); const inputRef = useRef<TextInput>(null);
const handleCloseRef = useRef(null);
//CALLBACK_METHOD //CALLBACK_METHOD
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
@ -36,12 +37,14 @@ const QuickReplyModal = ({ fetchPost }: QuickReplyModalProps, ref) => {
containerStyle={styles.sheetContent} containerStyle={styles.sheetContent}
keyboardHandlerEnabled keyboardHandlerEnabled
indicatorColor={EStyleSheet.value('$primaryWhiteLightBackground')} indicatorColor={EStyleSheet.value('$primaryWhiteLightBackground')}
onClose={() => handleCloseRef.current()}
> >
<QuickReplyModalContent <QuickReplyModalContent
fetchPost={fetchPost} fetchPost={fetchPost}
selectedPost={selectedPost} selectedPost={selectedPost}
inputRef={inputRef} inputRef={inputRef}
sheetModalRef={sheetModalRef} sheetModalRef={sheetModalRef}
handleCloseRef={handleCloseRef}
/> />
</ActionSheet> </ActionSheet>
</Portal> </Portal>

View File

@ -5,9 +5,11 @@ import {
UPDATE_VOTE_CACHE, UPDATE_VOTE_CACHE,
PURGE_EXPIRED_CACHE, PURGE_EXPIRED_CACHE,
UPDATE_COMMENT_CACHE, UPDATE_COMMENT_CACHE,
DELETE_COMMENT_CACHE_ENTRY DELETE_COMMENT_CACHE_ENTRY,
UPDATE_QUICK_COMMENT_CACHE,
DELETE_QUICK_COMMENT_CACHE_ENTRY
} from '../constants/constants'; } from '../constants/constants';
import { Comment, Vote } from '../reducers/cacheReducer'; import { Comment, QuickComment, Vote } from '../reducers/cacheReducer';
@ -72,6 +74,19 @@ import { Comment, Vote } from '../reducers/cacheReducer';
type: DELETE_COMMENT_CACHE_ENTRY type: DELETE_COMMENT_CACHE_ENTRY
}) })
export const updateQuickCommentCache = (path:string, quickComment:QuickComment) => ({
payload:{
path,
quickComment
},
type: UPDATE_QUICK_COMMENT_CACHE
})
export const deleteQuickCommentCacheEntry = (path:string) => ({
payload:path,
type: DELETE_QUICK_COMMENT_CACHE_ENTRY
})
export const purgeExpiredCache = () => ({ export const purgeExpiredCache = () => ({
type: PURGE_EXPIRED_CACHE type: PURGE_EXPIRED_CACHE
}) })

View File

@ -111,6 +111,8 @@ export const PURGE_EXPIRED_CACHE = 'PURGE_EXPIRED_CACHE';
export const UPDATE_VOTE_CACHE = 'UPDATE_VOTE_CACHE'; export const UPDATE_VOTE_CACHE = 'UPDATE_VOTE_CACHE';
export const UPDATE_COMMENT_CACHE = 'UPDATE_COMMENT_CACHE'; export const UPDATE_COMMENT_CACHE = 'UPDATE_COMMENT_CACHE';
export const DELETE_COMMENT_CACHE_ENTRY = 'DELETE_COMMENT_CACHE_ENTRY'; export const DELETE_COMMENT_CACHE_ENTRY = 'DELETE_COMMENT_CACHE_ENTRY';
export const UPDATE_QUICK_COMMENT_CACHE = 'UPDATE_QUICK_COMMENT_CACHE';
export const DELETE_QUICK_COMMENT_CACHE_ENTRY = 'DELETE_QUICK_COMMENT_CACHE_ENTRY';
// TOOLTIPS // TOOLTIPS
export const REGISTER_TOOLTIP = 'REGISTER_TOOLTIP'; export const REGISTER_TOOLTIP = 'REGISTER_TOOLTIP';

View File

@ -1,4 +1,4 @@
import { PURGE_EXPIRED_CACHE, UPDATE_VOTE_CACHE, UPDATE_COMMENT_CACHE, DELETE_COMMENT_CACHE_ENTRY } from "../constants/constants"; import { PURGE_EXPIRED_CACHE, UPDATE_VOTE_CACHE, UPDATE_COMMENT_CACHE, DELETE_COMMENT_CACHE_ENTRY, UPDATE_QUICK_COMMENT_CACHE, DELETE_QUICK_COMMENT_CACHE_ENTRY } from "../constants/constants";
export interface Vote { export interface Vote {
amount:number; amount:number;
@ -26,19 +26,29 @@ export interface Comment {
expiresAt?:number, expiresAt?:number,
} }
export interface QuickComment {
parent_permlink:string,
body?:string,
created?:string,
updated?:string,
expiresAt:number;
}
interface State { interface State {
votes:Map<string, Vote> votes:Map<string, Vote>
comments:Map<string, Comment> //TODO: handle comment array per post, if parent is same comments:Map<string, Comment> //TODO: handle comment array per post, if parent is same
quickComments: Map<string, QuickComment>
lastUpdate:{ lastUpdate:{
postPath:string, postPath:string,
updatedAt:number, updatedAt:number,
type:'vote'|'comment', type:'vote'|'comment'|'quickComment',
} }
} }
const initialState:State = { const initialState:State = {
votes:new Map(), votes:new Map(),
comments:new Map(), comments:new Map(),
quickComments: new Map(),
lastUpdate:null, lastUpdate:null,
}; };
@ -79,6 +89,26 @@ const initialState:State = {
} }
return { ...state } return { ...state }
case UPDATE_QUICK_COMMENT_CACHE:
if(!state.quickComments){
state.quickComments = new Map<string, QuickComment>();
}
state.quickComments.set(payload.path, payload.quickComment);
return {
...state, //spread operator in requried here, otherwise persist do not register change
lastUpdate: {
postPath: payload.path,
updatedAt: new Date().getTime(),
type: 'quickComment',
},
};
case DELETE_QUICK_COMMENT_CACHE_ENTRY:
if (state.quickComments && state.quickComments.has(payload)) {
state.quickComments.delete(payload);
}
return { ...state }
case PURGE_EXPIRED_CACHE: case PURGE_EXPIRED_CACHE:
const currentTime = new Date().getTime(); const currentTime = new Date().getTime();

View File

@ -11,12 +11,14 @@ const transformCacheVoteMap = createTransform(
(inboundState:any) => ({ (inboundState:any) => ({
...inboundState, ...inboundState,
votes : Array.from(inboundState.votes), votes : Array.from(inboundState.votes),
comments : Array.from(inboundState.comments) comments : Array.from(inboundState.comments),
quickComments : Array.from(inboundState.quickComments),
}), }),
(outboundState) => ({ (outboundState) => ({
...outboundState, ...outboundState,
votes:new Map(outboundState.votes), votes:new Map(outboundState.votes),
comments:new Map(outboundState.comments) comments:new Map(outboundState.comments),
quickComments: new Map(outboundState.quickComments)
}), }),
{whitelist:['cache']} {whitelist:['cache']}
); );