mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-26 06:42:15 +03:00
added redux structure for managing point activities
This commit is contained in:
parent
fcb624c1a9
commit
558a787d26
@ -25,7 +25,7 @@ import { updateCurrentAccount } from '../../../redux/actions/accountAction';
|
||||
import showLoginAlert from '../../../utils/showLoginAlert';
|
||||
import { useUserActivityMutation } from '../../../providers/queries/pointQueries';
|
||||
import { generateRndStr } from '../../../utils/editor';
|
||||
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
import { PointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
@ -349,7 +349,7 @@ class PostDropdownContainer extends PureComponent {
|
||||
.then((response) => {
|
||||
//track user activity points ty=130
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.REBLOG,
|
||||
pointsTy:PointActivityIds.REBLOG,
|
||||
transactionId:response.id
|
||||
})
|
||||
|
||||
|
@ -25,7 +25,7 @@ import { useAppDispatch } from '../../../hooks';
|
||||
import { showReplyModal } from '../../../redux/actions/uiAction';
|
||||
import postTypes from '../../../constants/postTypes';
|
||||
import { useUserActivityMutation } from '../../../providers/queries/pointQueries';
|
||||
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
import { PointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
|
||||
const HEIGHT = getWindowDimensions().height;
|
||||
const WIDTH = getWindowDimensions().width;
|
||||
@ -70,7 +70,7 @@ const PostDisplayView = ({
|
||||
if (isLoggedIn && get(currentAccount, 'name') && !isNewPost) {
|
||||
//track user activity for view post
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.VIEW_POST
|
||||
pointsTy:PointActivityIds.VIEW_POST
|
||||
})
|
||||
}
|
||||
}, []);
|
||||
|
@ -21,7 +21,7 @@ import { Draft } from '../../redux/reducers/cacheReducer';
|
||||
import { RootState } from '../../redux/store/store';
|
||||
import { useImperativeHandle } from 'react';
|
||||
import { forwardRef } from 'react';
|
||||
import { EPointActivityIds } from '../../providers/ecency/ecency.types';
|
||||
import { PointActivityIds } from '../../providers/ecency/ecency.types';
|
||||
import { useUserActivityMutation } from '../../providers/queries/pointQueries';
|
||||
|
||||
export interface QuickReplyModalContentProps {
|
||||
@ -153,7 +153,7 @@ export const QuickReplyModalContent = forwardRef(({
|
||||
)
|
||||
.then((response) => {
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.COMMENT,
|
||||
pointsTy:PointActivityIds.COMMENT,
|
||||
transactionId:response.id
|
||||
})
|
||||
setIsSending(false);
|
||||
|
@ -24,7 +24,7 @@ import { useAppSelector } from '../../../hooks';
|
||||
import postTypes from '../../../constants/postTypes';
|
||||
import { useUserActivityMutation } from '../../../providers/queries';
|
||||
import { generateRndStr } from '../../../utils/editor';
|
||||
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
import { PointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
|
||||
interface UpvoteViewProps {
|
||||
isDeclinedPayout: boolean;
|
||||
@ -141,7 +141,7 @@ const UpvoteView = ({
|
||||
//record user points
|
||||
userActivityMutation.mutate({
|
||||
localId: generateRndStr(),
|
||||
pointsTy: EPointActivityIds.VOTE,
|
||||
pointsTy: PointActivityIds.VOTE,
|
||||
transactionId: response.id
|
||||
})
|
||||
|
||||
@ -216,7 +216,7 @@ const UpvoteView = ({
|
||||
//record usr points
|
||||
userActivityMutation.mutate({
|
||||
localId: generateRndStr(),
|
||||
pointsTy: EPointActivityIds.VOTE,
|
||||
pointsTy: PointActivityIds.VOTE,
|
||||
transactionId: response.id
|
||||
})
|
||||
setUpvote(!!sliderValue);
|
||||
|
@ -65,6 +65,13 @@ export interface CommentHistoryItem {
|
||||
v: number;
|
||||
}
|
||||
|
||||
export interface PointActivity {
|
||||
pointsTy:number;
|
||||
username?:string;
|
||||
transactionId?:string;
|
||||
blockNum?:number|string;
|
||||
}
|
||||
|
||||
export enum ScheduledPostStatus {
|
||||
PENDING = 1,
|
||||
POSTPONED = 2,
|
||||
@ -84,7 +91,8 @@ export enum NotificationFilters {
|
||||
FAVOURITES = "nfavorites"
|
||||
}
|
||||
|
||||
export enum EPointActivityIds {
|
||||
|
||||
export enum PointActivityIds {
|
||||
VIEW_POST = 10,
|
||||
LOGIN = 20,
|
||||
POST = 100,
|
||||
|
@ -792,8 +792,6 @@ export const vote = async (account, pin, author, permlink, weight) => {
|
||||
const resp = await _vote(account, pin, author, permlink, weight);
|
||||
console.log('Returning vote response', resp);
|
||||
|
||||
//TODO: remove userActivity
|
||||
// userActivity(120, resp.id);
|
||||
return resp;
|
||||
} catch (err) {
|
||||
console.warn('Failed to complete vote', err);
|
||||
@ -1411,12 +1409,6 @@ export const postContent = (
|
||||
voteWeight,
|
||||
)
|
||||
.then((resp) => {
|
||||
const t = title ? 100 : 110;
|
||||
const { id } = resp;
|
||||
if (!isEdit) {
|
||||
//TODO: remove userActivity
|
||||
// userActivity(t, id);
|
||||
}
|
||||
return resp;
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -1460,12 +1452,6 @@ export const postComment = (
|
||||
null,
|
||||
)
|
||||
.then((resp) => {
|
||||
const t = 110;
|
||||
const { id } = resp;
|
||||
if (!isEdit) {
|
||||
//TODO: remove userActivity
|
||||
// userActivity(t, id);
|
||||
}
|
||||
return resp;
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -1592,8 +1578,6 @@ const _postContent = async (
|
||||
// TODO: remove pinCode
|
||||
export const reblog = (account, pinCode, author, permlink) =>
|
||||
_reblog(account, pinCode, author, permlink).then((resp) => {
|
||||
//TODO: remove userActivity
|
||||
// userActivity(130, resp.id);
|
||||
return resp;
|
||||
});
|
||||
|
||||
|
@ -1,40 +1,49 @@
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { EPointActivityIds } from "../ecency/ecency.types";
|
||||
import { PointActivityIds } from "../ecency/ecency.types";
|
||||
import { userActivity } from "../ecency/ePoint"
|
||||
|
||||
|
||||
|
||||
interface UserActivityVars {
|
||||
pointsTy: EPointActivityIds;
|
||||
localId?: string; //use for redux storage
|
||||
interface UserActivityMutationVars {
|
||||
pointsTy: PointActivityIds;
|
||||
blockNum?: string;
|
||||
transactionId?: string;
|
||||
cacheId?:string
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const useUserActivityMutation = () => {
|
||||
|
||||
const _mutationFn = async ({ pointsTy, blockNum, transactionId }: UserActivityVars) => {
|
||||
const _mutationFn = async ({ pointsTy, blockNum, transactionId }: UserActivityMutationVars) => {
|
||||
await userActivity(pointsTy, transactionId, blockNum)
|
||||
return true;
|
||||
}
|
||||
|
||||
return useMutation<boolean, Error, UserActivityVars>(_mutationFn, {
|
||||
const mutation = useMutation<boolean, Error, UserActivityMutationVars>(_mutationFn, {
|
||||
retry: 2,
|
||||
onSuccess: (data, vars) => {
|
||||
console.log("successfully logged activity", data, vars)
|
||||
//remove entry from redux
|
||||
if(vars.localId){
|
||||
if(vars.cacheId){
|
||||
console.log("must remove from redux")
|
||||
}
|
||||
},
|
||||
onError: (error, vars) => {
|
||||
console.log("failed to log activity", error, vars)
|
||||
//add entry in redux
|
||||
if(!vars.localId){
|
||||
if(!vars.cacheId){
|
||||
console.log("must add to from redux")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const mutatePendingActivities = () => {
|
||||
//read pending activities from redux
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
...mutation,
|
||||
mutatePendingActivities,
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { renderPostBody } from '@ecency/render-helper';
|
||||
import { Platform } from 'react-native';
|
||||
import { makeJsonMetadataReply } from '../../utils/editor';
|
||||
import { PointActivity } from '../../providers/ecency/ecency.types';
|
||||
import { generateRndStr, makeJsonMetadataReply } from '../../utils/editor';
|
||||
import {
|
||||
UPDATE_VOTE_CACHE,
|
||||
PURGE_EXPIRED_CACHE,
|
||||
@ -10,13 +11,14 @@ import {
|
||||
DELETE_DRAFT_CACHE_ENTRY,
|
||||
UPDATE_SUBSCRIBED_COMMUNITY_CACHE,
|
||||
DELETE_SUBSCRIBED_COMMUNITY_CACHE,
|
||||
CLEAR_SUBSCRIBED_COMMUNITIES_CACHE
|
||||
CLEAR_SUBSCRIBED_COMMUNITIES_CACHE,
|
||||
DELETE_POINT_ACTIVITY_CACHE_ENTRY,
|
||||
UPDATE_POINT_ACTIVITY_CACHE
|
||||
} from '../constants/constants';
|
||||
import { Comment, CommentCacheStatus, Draft, SubscribedCommunity, Vote } from '../reducers/cacheReducer';
|
||||
|
||||
|
||||
|
||||
|
||||
export const updateVoteCache = (postPath: string, vote: Vote) => ({
|
||||
payload: {
|
||||
postPath,
|
||||
@ -123,6 +125,18 @@ export const clearSubscribedCommunitiesCache = () => ({
|
||||
type: CLEAR_SUBSCRIBED_COMMUNITIES_CACHE
|
||||
})
|
||||
|
||||
export const updatePointActivityCache = (pointActivity: PointActivity) => ({
|
||||
payload: {
|
||||
id:generateRndStr(),
|
||||
pointActivity
|
||||
},
|
||||
type: UPDATE_POINT_ACTIVITY_CACHE
|
||||
})
|
||||
|
||||
export const deletePointActivityCache = (id: string) => ({
|
||||
payload: id,
|
||||
type: DELETE_POINT_ACTIVITY_CACHE_ENTRY
|
||||
})
|
||||
|
||||
export const purgeExpiredCache = () => ({
|
||||
type: PURGE_EXPIRED_CACHE
|
||||
|
@ -124,6 +124,8 @@ export const DEFAULT_USER_DRAFT_ID = 'DEFAULT_USER_DRAFT_ID_';
|
||||
export const UPDATE_SUBSCRIBED_COMMUNITY_CACHE = 'UPDATE_SUBSCRIBED_COMMUNITY_CACHE';
|
||||
export const DELETE_SUBSCRIBED_COMMUNITY_CACHE = 'DELETE_SUBSCRIBED_COMMUNITY_CACHE';
|
||||
export const CLEAR_SUBSCRIBED_COMMUNITIES_CACHE = 'CLEAR_SUBSCRIBED_COMMUNITIES_CACHE';
|
||||
export const UPDATE_POINT_ACTIVITY_CACHE = 'UPDATE_POINT_ACTIVITY_CACHE';
|
||||
export const DELETE_POINT_ACTIVITY_CACHE_ENTRY = 'DELETE_POINT_ACTIVITY_CACHE_ENTRY';
|
||||
|
||||
// TOOLTIPS
|
||||
export const REGISTER_TOOLTIP = 'REGISTER_TOOLTIP';
|
||||
|
@ -1,4 +1,17 @@
|
||||
import { PURGE_EXPIRED_CACHE, UPDATE_VOTE_CACHE, UPDATE_COMMENT_CACHE, DELETE_COMMENT_CACHE_ENTRY, DELETE_DRAFT_CACHE_ENTRY, UPDATE_DRAFT_CACHE, UPDATE_SUBSCRIBED_COMMUNITY_CACHE, DELETE_SUBSCRIBED_COMMUNITY_CACHE, CLEAR_SUBSCRIBED_COMMUNITIES_CACHE, UPDATE_COMMENT_CACHE_ENTRY_STATUS, } from "../constants/constants";
|
||||
import { PointActivity } from "../../providers/ecency/ecency.types";
|
||||
import {
|
||||
PURGE_EXPIRED_CACHE,
|
||||
UPDATE_VOTE_CACHE,
|
||||
UPDATE_COMMENT_CACHE,
|
||||
DELETE_COMMENT_CACHE_ENTRY,
|
||||
DELETE_DRAFT_CACHE_ENTRY,
|
||||
UPDATE_DRAFT_CACHE,
|
||||
UPDATE_SUBSCRIBED_COMMUNITY_CACHE,
|
||||
DELETE_SUBSCRIBED_COMMUNITY_CACHE,
|
||||
CLEAR_SUBSCRIBED_COMMUNITIES_CACHE,
|
||||
UPDATE_POINT_ACTIVITY_CACHE,
|
||||
DELETE_POINT_ACTIVITY_CACHE_ENTRY
|
||||
} from "../constants/constants";
|
||||
|
||||
export enum CommentCacheStatus {
|
||||
PENDING = 'PENDING',
|
||||
@ -48,11 +61,14 @@ export interface SubscribedCommunity {
|
||||
data: Array<any>,
|
||||
expiresAt?: number;
|
||||
}
|
||||
|
||||
|
||||
interface State {
|
||||
votes: Map<string, Vote>
|
||||
comments: Map<string, Comment> //TODO: handle comment array per post, if parent is same
|
||||
drafts: Map<string, Draft>
|
||||
subscribedCommunities: Map<string, SubscribedCommunity>
|
||||
pointActivities: Map<string, PointActivity>
|
||||
lastUpdate: {
|
||||
postPath: string,
|
||||
updatedAt: number,
|
||||
@ -65,6 +81,7 @@ const initialState: State = {
|
||||
comments: new Map(),
|
||||
drafts: new Map(),
|
||||
subscribedCommunities: new Map(),
|
||||
pointActivities: new Map(),
|
||||
lastUpdate: null,
|
||||
};
|
||||
|
||||
@ -156,6 +173,21 @@ export default function (state = initialState, action) {
|
||||
|
||||
return { ...state }
|
||||
|
||||
case UPDATE_POINT_ACTIVITY_CACHE:
|
||||
if (!state.pointActivities) {
|
||||
state.pointActivities = new Map<string, PointActivity>();
|
||||
}
|
||||
state.pointActivities.set(payload.id, payload.pointActivity);
|
||||
return {
|
||||
...state, //spread operator in requried here, otherwise persist do not register change
|
||||
};
|
||||
|
||||
case DELETE_POINT_ACTIVITY_CACHE_ENTRY:
|
||||
if (state.pointActivities && state.pointActivities.has(payload)) {
|
||||
state.pointActivities.delete(payload);
|
||||
}
|
||||
return { ...state }
|
||||
|
||||
case PURGE_EXPIRED_CACHE:
|
||||
const currentTime = new Date().getTime();
|
||||
|
||||
|
@ -15,6 +15,7 @@ const transformCacheVoteMap = createTransform(
|
||||
comments: Array.from(inboundState.comments),
|
||||
drafts: Array.from(inboundState.drafts),
|
||||
subscribedCommunities: Array.from(inboundState.subscribedCommunities),
|
||||
pointActivities: Array.from(inboundState.pointActivities),
|
||||
}),
|
||||
(outboundState) => ({
|
||||
...outboundState,
|
||||
@ -22,6 +23,7 @@ const transformCacheVoteMap = createTransform(
|
||||
comments: new Map(outboundState.comments),
|
||||
drafts: new Map(outboundState.drafts),
|
||||
subscribedCommunities: new Map(outboundState.subscribedCommunities),
|
||||
pointActivities: new Map(outboundState.pointActivities)
|
||||
}),
|
||||
{ whitelist: ['cache'] },
|
||||
);
|
||||
|
@ -47,7 +47,7 @@ import {
|
||||
import QUERIES from '../../../providers/queries/queryKeys';
|
||||
import bugsnapInstance from '../../../config/bugsnag';
|
||||
import { useUserActivityMutation } from '../../../providers/queries/pointQueries';
|
||||
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
import { PointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
@ -621,7 +621,7 @@ class EditorContainer extends Component<EditorContainerProps, any> {
|
||||
console.log(response);
|
||||
// track user activity for points
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.POST,
|
||||
pointsTy:PointActivityIds.POST,
|
||||
transactionId:response.id
|
||||
})
|
||||
|
||||
@ -631,7 +631,7 @@ class EditorContainer extends Component<EditorContainerProps, any> {
|
||||
.then((resp) => {
|
||||
//track user activity for points on reblog
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.REBLOG,
|
||||
pointsTy:PointActivityIds.REBLOG,
|
||||
transactionId:resp.id
|
||||
})
|
||||
console.log('Successfully reblogged post', resp);
|
||||
@ -710,7 +710,7 @@ class EditorContainer extends Component<EditorContainerProps, any> {
|
||||
.then((response) => {
|
||||
//record user activity for points
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.COMMENT,
|
||||
pointsTy:PointActivityIds.COMMENT,
|
||||
transactionId:response.id
|
||||
})
|
||||
|
||||
|
@ -34,7 +34,7 @@ import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAc
|
||||
import { showActionModal } from '../../../redux/actions/uiAction';
|
||||
import { UserAvatar } from '../../../components';
|
||||
import { useUserActivityMutation } from '../../../providers/queries/pointQueries';
|
||||
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
import { PointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
@ -168,7 +168,7 @@ class LoginContainer extends PureComponent {
|
||||
dispatch(setFeedPosts([]));
|
||||
|
||||
//track user activity for login
|
||||
userActivityMutation.mutate({ pointsTy:EPointActivityIds.LOGIN })
|
||||
userActivityMutation.mutate({ pointsTy:PointActivityIds.LOGIN })
|
||||
setExistUser(true);
|
||||
this._setPushToken(result.name);
|
||||
const encryptedPin = encryptKey(Config.DEFAULT_PIN, Config.PIN_KEY);
|
||||
|
Loading…
Reference in New Issue
Block a user