mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-03 11:34:30 +03:00
added support for deleting cached comment and cleaning cache on delete
This commit is contained in:
parent
34c93303f3
commit
31a020b149
@ -19,6 +19,7 @@ import ROUTES from '../../../constants/routeNames';
|
||||
// Component
|
||||
import CommentsView from '../view/commentsView';
|
||||
import { useAppSelector } from '../../../hooks';
|
||||
import { deleteCommentCacheEntry } from '../../../redux/actions/cacheActions';
|
||||
|
||||
const CommentsContainer = ({
|
||||
author,
|
||||
@ -261,12 +262,25 @@ const CommentsContainer = ({
|
||||
let filteredComments;
|
||||
|
||||
deleteComment(currentAccount, pinCode, _permlink).then(() => {
|
||||
if (lcomments.length > 0) {
|
||||
filteredComments = lcomments.filter((item) => item.permlink !== _permlink);
|
||||
} else {
|
||||
filteredComments = comments.filter((item) => item.permlink !== _permlink);
|
||||
let cachePath = null;
|
||||
const _applyFilter = (item) => {
|
||||
if (item.permlink === _permlink) {
|
||||
cachePath = `${item.parent_author}/${item.parent_permlink}`;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if (lcomments.length > 0) {
|
||||
filteredComments = lcomments.filter(_applyFilter);
|
||||
setLComments(filteredComments);
|
||||
} else {
|
||||
filteredComments = replies.filter(_applyFilter);
|
||||
setReplies(filteredComments);
|
||||
}
|
||||
|
||||
// remove cached entry based on parent
|
||||
dispatch(deleteCommentCacheEntry(cachePath));
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,8 @@ import { makeJsonMetadataReply } from '../../utils/editor';
|
||||
import {
|
||||
UPDATE_VOTE_CACHE,
|
||||
PURGE_EXPIRED_CACHE,
|
||||
UPDATE_COMMENT_CACHE
|
||||
UPDATE_COMMENT_CACHE,
|
||||
DELETE_COMMENT_CACHE_ENTRY
|
||||
} from '../constants/constants';
|
||||
import { Comment, Vote } from '../reducers/cacheReducer';
|
||||
|
||||
@ -65,6 +66,11 @@ import { Comment, Vote } from '../reducers/cacheReducer';
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteCommentCacheEntry = (commentPath:string) => ({
|
||||
payload:commentPath,
|
||||
type: DELETE_COMMENT_CACHE_ENTRY
|
||||
})
|
||||
|
||||
export const purgeExpiredCache = () => ({
|
||||
type: PURGE_EXPIRED_CACHE
|
||||
})
|
||||
|
@ -108,3 +108,4 @@ export const TEMP_BENEFICIARIES_ID = 'temp-beneficiaries';
|
||||
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';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { PURGE_EXPIRED_CACHE, UPDATE_VOTE_CACHE, UPDATE_COMMENT_CACHE } from "../constants/constants";
|
||||
import { PURGE_EXPIRED_CACHE, UPDATE_VOTE_CACHE, UPDATE_COMMENT_CACHE, DELETE_COMMENT_CACHE_ENTRY } from "../constants/constants";
|
||||
|
||||
export interface Vote {
|
||||
amount:number;
|
||||
@ -71,6 +71,13 @@ const initialState:State = {
|
||||
type:'comment'
|
||||
}
|
||||
};
|
||||
|
||||
case DELETE_COMMENT_CACHE_ENTRY:
|
||||
if(state.comments && state.comments.has(payload)){
|
||||
state.comments.delete(payload);
|
||||
}
|
||||
return { ...state }
|
||||
|
||||
case PURGE_EXPIRED_CACHE:
|
||||
const currentTime = new Date().getTime();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user