mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-24 05:42:33 +03:00
added quick comment cache when sheet is closed
This commit is contained in:
parent
1b1b6d0175
commit
93dd7e6508
@ -833,4 +833,4 @@ SPEC CHECKSUMS:
|
||||
|
||||
PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311
|
||||
|
||||
COCOAPODS: 1.11.3
|
||||
COCOAPODS: 1.11.2
|
||||
|
@ -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 = ({
|
||||
<View style={styles.inputContainer}>
|
||||
<TextInput
|
||||
innerRef={inputRef}
|
||||
onChangeText={setCommentValue}
|
||||
onChangeText={(value) => {
|
||||
setCommentValue(value);
|
||||
}}
|
||||
value={commentValue}
|
||||
// autoFocus
|
||||
placeholder={intl.formatMessage({
|
||||
|
@ -14,6 +14,7 @@ const QuickReplyModal = ({ fetchPost }: QuickReplyModalProps, ref) => {
|
||||
const [selectedPost, setSelectedPost] = useState(null);
|
||||
const sheetModalRef = useRef<ActionSheet>();
|
||||
const inputRef = useRef<TextInput>(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()}
|
||||
>
|
||||
<QuickReplyModalContent
|
||||
fetchPost={fetchPost}
|
||||
selectedPost={selectedPost}
|
||||
inputRef={inputRef}
|
||||
sheetModalRef={sheetModalRef}
|
||||
handleCloseRef={handleCloseRef}
|
||||
/>
|
||||
</ActionSheet>
|
||||
</Portal>
|
||||
|
@ -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
|
||||
})
|
||||
|
@ -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';
|
||||
|
@ -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<string, Vote>
|
||||
comments:Map<string, Comment> //TODO: handle comment array per post, if parent is same
|
||||
quickComments: Map<string, QuickComment>
|
||||
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<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:
|
||||
const currentTime = new Date().getTime();
|
||||
|
||||
|
@ -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']}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user