diff --git a/ios/Podfile.lock b/ios/Podfile.lock index e27b5a1df..b15638732 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -833,4 +833,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311 -COCOAPODS: 1.11.3 +COCOAPODS: 1.11.2 diff --git a/src/components/quickReplyModal/quickReplyModalContent.tsx b/src/components/quickReplyModal/quickReplyModalContent.tsx index 9700fd05f..665c94fea 100644 --- a/src/components/quickReplyModal/quickReplyModalContent.tsx +++ b/src/components/quickReplyModal/quickReplyModalContent.tsx @@ -8,7 +8,7 @@ import { useSelector, useDispatch } from 'react-redux'; import { delay, generateReplyPermlink } from '../../utils/editor'; import { postComment } from '../../providers/hive/dhive'; 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 get from 'lodash/get'; import { navigate } from '../../navigation/service'; @@ -19,6 +19,7 @@ export interface QuickReplyModalContentProps { selectedPost?: any; inputRef?: any; sheetModalRef?: any; + handleCloseRef?: any; } export const QuickReplyModalContent = ({ @@ -26,6 +27,7 @@ export const QuickReplyModalContent = ({ selectedPost, inputRef, sheetModalRef, + handleCloseRef }: QuickReplyModalContentProps) => { const intl = useIntl(); const dispatch = useDispatch(); @@ -38,12 +40,46 @@ export const QuickReplyModalContent = ({ const headerText = selectedPost && (selectedPost.summary || postBodySummary(selectedPost, 150, Platform.OS)); + useEffect(() => { + handleCloseRef.current = handleSheetClose; + }, [commentValue]) + // reset the state when post changes useEffect(() => { setCommentValue(''); }, [selectedPost]); // 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 const _handleClosePress = () => { @@ -237,7 +273,9 @@ export const QuickReplyModalContent = ({ { + setCommentValue(value); + }} value={commentValue} // autoFocus placeholder={intl.formatMessage({ diff --git a/src/components/quickReplyModal/quickReplyModalView.tsx b/src/components/quickReplyModal/quickReplyModalView.tsx index 47a675648..67ff0df05 100644 --- a/src/components/quickReplyModal/quickReplyModalView.tsx +++ b/src/components/quickReplyModal/quickReplyModalView.tsx @@ -14,6 +14,7 @@ const QuickReplyModal = ({ fetchPost }: QuickReplyModalProps, ref) => { const [selectedPost, setSelectedPost] = useState(null); const sheetModalRef = useRef(); const inputRef = useRef(null); + const handleCloseRef = useRef(null); //CALLBACK_METHOD useImperativeHandle(ref, () => ({ @@ -36,12 +37,14 @@ const QuickReplyModal = ({ fetchPost }: QuickReplyModalProps, ref) => { containerStyle={styles.sheetContent} keyboardHandlerEnabled indicatorColor={EStyleSheet.value('$primaryWhiteLightBackground')} + onClose={() => handleCloseRef.current()} > diff --git a/src/redux/actions/cacheActions.ts b/src/redux/actions/cacheActions.ts index e15773d81..7e148be1b 100644 --- a/src/redux/actions/cacheActions.ts +++ b/src/redux/actions/cacheActions.ts @@ -5,9 +5,11 @@ import { UPDATE_VOTE_CACHE, PURGE_EXPIRED_CACHE, UPDATE_COMMENT_CACHE, - DELETE_COMMENT_CACHE_ENTRY + DELETE_COMMENT_CACHE_ENTRY, + UPDATE_QUICK_COMMENT_CACHE, + DELETE_QUICK_COMMENT_CACHE_ENTRY } 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 }) + 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 = () => ({ type: PURGE_EXPIRED_CACHE }) diff --git a/src/redux/constants/constants.js b/src/redux/constants/constants.js index 54a07ebaa..74c8689a7 100644 --- a/src/redux/constants/constants.js +++ b/src/redux/constants/constants.js @@ -111,6 +111,8 @@ export const PURGE_EXPIRED_CACHE = 'PURGE_EXPIRED_CACHE'; export const UPDATE_VOTE_CACHE = 'UPDATE_VOTE_CACHE'; export const UPDATE_COMMENT_CACHE = 'UPDATE_COMMENT_CACHE'; 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 export const REGISTER_TOOLTIP = 'REGISTER_TOOLTIP'; diff --git a/src/redux/reducers/cacheReducer.ts b/src/redux/reducers/cacheReducer.ts index d5109779c..7ade92f09 100644 --- a/src/redux/reducers/cacheReducer.ts +++ b/src/redux/reducers/cacheReducer.ts @@ -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 { amount:number; @@ -26,19 +26,29 @@ export interface Comment { expiresAt?:number, } +export interface QuickComment { + parent_permlink:string, + body?:string, + created?:string, + updated?:string, + expiresAt:number; +} + interface State { votes:Map comments:Map //TODO: handle comment array per post, if parent is same + quickComments: Map lastUpdate:{ postPath:string, updatedAt:number, - type:'vote'|'comment', + type:'vote'|'comment'|'quickComment', } } const initialState:State = { votes:new Map(), comments:new Map(), + quickComments: new Map(), lastUpdate:null, }; @@ -79,6 +89,26 @@ const initialState:State = { } return { ...state } + case UPDATE_QUICK_COMMENT_CACHE: + if(!state.quickComments){ + state.quickComments = new Map(); + } + 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: const currentTime = new Date().getTime(); diff --git a/src/redux/store/store.ts b/src/redux/store/store.ts index b9086a0cd..603470ab5 100644 --- a/src/redux/store/store.ts +++ b/src/redux/store/store.ts @@ -11,12 +11,14 @@ const transformCacheVoteMap = createTransform( (inboundState:any) => ({ ...inboundState, votes : Array.from(inboundState.votes), - comments : Array.from(inboundState.comments) + comments : Array.from(inboundState.comments), + quickComments : Array.from(inboundState.quickComments), }), (outboundState) => ({ ...outboundState, votes:new Map(outboundState.votes), - comments:new Map(outboundState.comments) + comments:new Map(outboundState.comments), + quickComments: new Map(outboundState.quickComments) }), {whitelist:['cache']} );