mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 08:55:14 +03:00
migrated all instance of userActivity call to react-query
This commit is contained in:
parent
0bb051d675
commit
fcb624c1a9
@ -23,6 +23,9 @@ import PostDropdownView from '../view/postDropdownView';
|
||||
import { OptionsModal } from '../../atoms';
|
||||
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';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
@ -79,11 +82,11 @@ class PostDropdownContainer extends PureComponent {
|
||||
const _canUpdateCommunityPin =
|
||||
subscribedCommunities.data && !!content && content.community
|
||||
? subscribedCommunities.data.reduce((role, subscription) => {
|
||||
if (content.community === subscription[0]) {
|
||||
return ['owner', 'admin', 'mod'].includes(subscription[2]);
|
||||
}
|
||||
return role;
|
||||
}, false)
|
||||
if (content.community === subscription[0]) {
|
||||
return ['owner', 'admin', 'mod'].includes(subscription[2]);
|
||||
}
|
||||
return role;
|
||||
}, false)
|
||||
: false;
|
||||
const _isPinnedInCommunity = !!content && content.stats?.is_pinned;
|
||||
|
||||
@ -287,7 +290,7 @@ class PostDropdownContainer extends PureComponent {
|
||||
buttons: [
|
||||
{
|
||||
text: intl.formatMessage({ id: 'alert.cancel' }),
|
||||
onPress: () => {},
|
||||
onPress: () => { },
|
||||
},
|
||||
{
|
||||
text: intl.formatMessage({ id: 'alert.confirm' }),
|
||||
@ -326,7 +329,16 @@ class PostDropdownContainer extends PureComponent {
|
||||
};
|
||||
|
||||
_reblog = () => {
|
||||
const { content, currentAccount, dispatch, intl, isLoggedIn, pinCode, navigation } = this
|
||||
const {
|
||||
content,
|
||||
currentAccount,
|
||||
dispatch,
|
||||
intl,
|
||||
isLoggedIn,
|
||||
pinCode,
|
||||
navigation,
|
||||
userActivityMutation
|
||||
} = this
|
||||
.props as any;
|
||||
if (!isLoggedIn) {
|
||||
showLoginAlert({ navigation, intl });
|
||||
@ -334,8 +346,13 @@ class PostDropdownContainer extends PureComponent {
|
||||
}
|
||||
if (isLoggedIn) {
|
||||
reblog(currentAccount, pinCode, content.author, get(content, 'permlink', ''))
|
||||
.then(() => {
|
||||
//TODO: track user activity points ty=130
|
||||
.then((response) => {
|
||||
//track user activity points ty=130
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.REBLOG,
|
||||
transactionId:response.id
|
||||
})
|
||||
|
||||
dispatch(
|
||||
toastNotification(
|
||||
intl.formatMessage({
|
||||
@ -367,7 +384,7 @@ class PostDropdownContainer extends PureComponent {
|
||||
};
|
||||
|
||||
_updatePinnedPost = async ({ unpinPost }: { unpinPost: boolean } = { unpinPost: false }) => {
|
||||
const { content, currentAccount, pinCode, dispatch, intl, isLoggedIn } = this.props;
|
||||
const { content, currentAccount, pinCode, dispatch, intl } = this.props;
|
||||
|
||||
const params = {
|
||||
...currentAccount.about.profile,
|
||||
@ -499,4 +516,10 @@ const mapStateToProps = (state) => ({
|
||||
subscribedCommunities: state.communities.subscribedCommunities,
|
||||
});
|
||||
|
||||
export default withNavigation(connect(mapStateToProps)(injectIntl(PostDropdownContainer)));
|
||||
const mapQueriesToProps = () => ({
|
||||
userActivityMutation: useUserActivityMutation()
|
||||
})
|
||||
|
||||
export default withNavigation(connect(mapStateToProps)(injectIntl((props) => (
|
||||
<PostDropdownContainer {...props} {...mapQueriesToProps()} />)))
|
||||
);
|
||||
|
@ -5,7 +5,6 @@ import get from 'lodash/get';
|
||||
|
||||
// Providers
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { userActivity } from '../../../providers/ecency/ePoint';
|
||||
|
||||
// Utils
|
||||
import { getTimeFromNow } from '../../../utils/time';
|
||||
@ -25,6 +24,8 @@ import getWindowDimensions from '../../../utils/getWindowDimensions';
|
||||
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';
|
||||
|
||||
const HEIGHT = getWindowDimensions().height;
|
||||
const WIDTH = getWindowDimensions().width;
|
||||
@ -49,6 +50,7 @@ const PostDisplayView = ({
|
||||
}) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const insets = useSafeAreaInsets();
|
||||
const userActivityMutation = useUserActivityMutation();
|
||||
|
||||
const commentsRef = useRef<CommentsDisplay>();
|
||||
const scrollRef = useRef<ScrollView>();
|
||||
@ -66,8 +68,10 @@ const PostDisplayView = ({
|
||||
// Component Life Cycles
|
||||
useEffect(() => {
|
||||
if (isLoggedIn && get(currentAccount, 'name') && !isNewPost) {
|
||||
//TODO: track user activity with react-query
|
||||
userActivity(10);
|
||||
//track user activity for view post
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.VIEW_POST
|
||||
})
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { View, Text, Alert, TouchableOpacity, Keyboard, Platform } from 'react-n
|
||||
import { useIntl } from 'react-intl';
|
||||
import { IconButton, MainButton, TextButton, TextInput, UserAvatar } from '..';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { delay, generateReplyPermlink } from '../../utils/editor';
|
||||
import { delay, generateReplyPermlink, generateRndStr } from '../../utils/editor';
|
||||
import { postComment } from '../../providers/hive/dhive';
|
||||
import { toastNotification } from '../../redux/actions/uiAction';
|
||||
import {
|
||||
@ -14,13 +14,15 @@ import {
|
||||
updateDraftCache,
|
||||
} from '../../redux/actions/cacheActions';
|
||||
import { default as ROUTES } from '../../constants/routeNames';
|
||||
import { get, debounce } from 'lodash';
|
||||
import { get } from 'lodash';
|
||||
import { navigate } from '../../navigation/service';
|
||||
import { postBodySummary } from '@ecency/render-helper';
|
||||
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 { useUserActivityMutation } from '../../providers/queries/pointQueries';
|
||||
|
||||
export interface QuickReplyModalContentProps {
|
||||
selectedPost?: any;
|
||||
@ -34,6 +36,7 @@ export const QuickReplyModalContent = forwardRef(({
|
||||
}: QuickReplyModalContentProps, ref) => {
|
||||
const intl = useIntl();
|
||||
const dispatch = useDispatch();
|
||||
const userActivityMutation = useUserActivityMutation();
|
||||
|
||||
const inputRef = useRef(null);
|
||||
|
||||
@ -148,8 +151,11 @@ export const QuickReplyModalContent = forwardRef(({
|
||||
commentValue,
|
||||
parentTags,
|
||||
)
|
||||
.then(() => {
|
||||
|
||||
.then((response) => {
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.COMMENT,
|
||||
transactionId:response.id
|
||||
})
|
||||
setIsSending(false);
|
||||
setCommentValue('');
|
||||
|
||||
|
@ -85,5 +85,10 @@ export enum NotificationFilters {
|
||||
}
|
||||
|
||||
export enum EPointActivityIds {
|
||||
VOTE = 120
|
||||
VIEW_POST = 10,
|
||||
LOGIN = 20,
|
||||
POST = 100,
|
||||
COMMENT = 110,
|
||||
VOTE = 120,
|
||||
REBLOG = 130,
|
||||
}
|
||||
|
@ -1415,7 +1415,7 @@ export const postContent = (
|
||||
const { id } = resp;
|
||||
if (!isEdit) {
|
||||
//TODO: remove userActivity
|
||||
userActivity(t, id);
|
||||
// userActivity(t, id);
|
||||
}
|
||||
return resp;
|
||||
})
|
||||
@ -1464,7 +1464,7 @@ export const postComment = (
|
||||
const { id } = resp;
|
||||
if (!isEdit) {
|
||||
//TODO: remove userActivity
|
||||
userActivity(t, id);
|
||||
// userActivity(t, id);
|
||||
}
|
||||
return resp;
|
||||
})
|
||||
@ -1593,7 +1593,7 @@ const _postContent = async (
|
||||
export const reblog = (account, pinCode, author, permlink) =>
|
||||
_reblog(account, pinCode, author, permlink).then((resp) => {
|
||||
//TODO: remove userActivity
|
||||
userActivity(130, resp.id);
|
||||
// userActivity(130, resp.id);
|
||||
return resp;
|
||||
});
|
||||
|
||||
|
@ -5,8 +5,8 @@ import { userActivity } from "../ecency/ePoint"
|
||||
|
||||
|
||||
interface UserActivityVars {
|
||||
localId: string;
|
||||
pointsTy: EPointActivityIds;
|
||||
localId?: string; //use for redux storage
|
||||
blockNum?: string;
|
||||
transactionId?: string;
|
||||
}
|
||||
@ -25,10 +25,16 @@ export const useUserActivityMutation = () => {
|
||||
onSuccess: (data, vars) => {
|
||||
console.log("successfully logged activity", data, vars)
|
||||
//remove entry from redux
|
||||
if(vars.localId){
|
||||
console.log("must remove from redux")
|
||||
}
|
||||
},
|
||||
onError: (error, vars) => {
|
||||
console.log("failed to log activity", error, vars)
|
||||
//add entry in redux
|
||||
if(!vars.localId){
|
||||
console.log("must add to from redux")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
@ -8,7 +8,7 @@ import { isArray } from 'lodash';
|
||||
|
||||
// Services and Actions
|
||||
import { Buffer } from 'buffer';
|
||||
import { QueryClient, useQueryClient } from '@tanstack/react-query';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { addDraft, updateDraft, getDrafts, addSchedule } from '../../../providers/ecency/ecency';
|
||||
import { toastNotification, setRcOffer } from '../../../redux/actions/uiAction';
|
||||
import {
|
||||
@ -46,6 +46,8 @@ import {
|
||||
} from '../../../redux/actions/cacheActions';
|
||||
import QUERIES from '../../../providers/queries/queryKeys';
|
||||
import bugsnapInstance from '../../../config/bugsnag';
|
||||
import { useUserActivityMutation } from '../../../providers/queries/pointQueries';
|
||||
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
@ -53,7 +55,8 @@ import bugsnapInstance from '../../../config/bugsnag';
|
||||
*
|
||||
*/
|
||||
|
||||
class EditorContainer extends Component<any, any> {
|
||||
|
||||
class EditorContainer extends Component<EditorContainerProps, any> {
|
||||
_isMounted = false;
|
||||
_updatedDraftFields = null;
|
||||
_appState = AppState.currentState;
|
||||
@ -546,6 +549,7 @@ class EditorContainer extends Component<any, any> {
|
||||
intl,
|
||||
navigation,
|
||||
pinCode,
|
||||
userActivityMutation
|
||||
// isDefaultFooter,
|
||||
} = this.props;
|
||||
const { rewardType, isPostSending, thumbUrl, draftId, shouldReblog } = this.state;
|
||||
@ -615,13 +619,21 @@ class EditorContainer extends Component<any, any> {
|
||||
)
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
//TODO: track user activity ty=110 for comment, ty=100 for blog
|
||||
// track user activity for points
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.POST,
|
||||
transactionId:response.id
|
||||
})
|
||||
|
||||
//reblog if flag is active
|
||||
if (shouldReblog) {
|
||||
reblog(currentAccount, pinCode, author, permlink)
|
||||
.then((resp) => {
|
||||
//TODO: track user activity ty=130
|
||||
//track user activity for points on reblog
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.REBLOG,
|
||||
transactionId:resp.id
|
||||
})
|
||||
console.log('Successfully reblogged post', resp);
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -667,7 +679,7 @@ class EditorContainer extends Component<any, any> {
|
||||
};
|
||||
|
||||
_submitReply = async (fields) => {
|
||||
const { currentAccount, pinCode, dispatch } = this.props;
|
||||
const { currentAccount, pinCode, dispatch, userActivityMutation } = this.props;
|
||||
const { isPostSending } = this.state;
|
||||
|
||||
if (isPostSending) {
|
||||
@ -695,8 +707,13 @@ class EditorContainer extends Component<any, any> {
|
||||
fields.body,
|
||||
parentTags,
|
||||
)
|
||||
.then(() => {
|
||||
//TODO: track user activity ty = 110
|
||||
.then((response) => {
|
||||
//record user activity for points
|
||||
userActivityMutation.mutate({
|
||||
pointsTy:EPointActivityIds.COMMENT,
|
||||
transactionId:response.id
|
||||
})
|
||||
|
||||
AsyncStorage.setItem('temp-reply', '');
|
||||
this._handleSubmitSuccess();
|
||||
|
||||
@ -1132,10 +1149,11 @@ const mapStateToProps = (state) => ({
|
||||
drafts: state.cache.drafts,
|
||||
});
|
||||
|
||||
const mapQueriesToProps = () => ({
|
||||
queryClient:useQueryClient(),
|
||||
userActivityMutation:useUserActivityMutation()
|
||||
})
|
||||
|
||||
export default connect(mapStateToProps)(
|
||||
injectIntl(
|
||||
//NOTE: remove extra integration step once compoent converted to functional component
|
||||
//TOOD: inject add and update draft mutation hooks as well
|
||||
(props) => <EditorContainer {...props} queryClient={useQueryClient()} />,
|
||||
),
|
||||
injectIntl((props) => <EditorContainer {...props} {...mapQueriesToProps()} />),
|
||||
);
|
||||
|
@ -8,7 +8,7 @@ import messaging from '@react-native-firebase/messaging';
|
||||
// Services and Actions
|
||||
import { login, loginWithSC2 } from '../../../providers/hive/auth';
|
||||
import { lookupAccounts } from '../../../providers/hive/dhive';
|
||||
import { userActivity } from '../../../providers/ecency/ePoint';
|
||||
|
||||
import {
|
||||
failedAccount,
|
||||
addOtherAccount,
|
||||
@ -33,6 +33,8 @@ import persistAccountGenerator from '../../../utils/persistAccountGenerator';
|
||||
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
|
||||
import { showActionModal } from '../../../redux/actions/uiAction';
|
||||
import { UserAvatar } from '../../../components';
|
||||
import { useUserActivityMutation } from '../../../providers/queries/pointQueries';
|
||||
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
@ -149,7 +151,7 @@ class LoginContainer extends PureComponent {
|
||||
};
|
||||
|
||||
_handleOnPressLogin = (username, password) => {
|
||||
const { dispatch, intl, isPinCodeOpen, navigation } = this.props;
|
||||
const { dispatch, intl, isPinCodeOpen, navigation, userActivityMutation } = this.props;
|
||||
|
||||
this.setState({ isLoading: true });
|
||||
|
||||
@ -165,8 +167,8 @@ class LoginContainer extends PureComponent {
|
||||
dispatch(setInitPosts([]));
|
||||
dispatch(setFeedPosts([]));
|
||||
|
||||
//TODO: track user activity with react query
|
||||
userActivity(20);
|
||||
//track user activity for login
|
||||
userActivityMutation.mutate({ pointsTy:EPointActivityIds.LOGIN })
|
||||
setExistUser(true);
|
||||
this._setPushToken(result.name);
|
||||
const encryptedPin = encryptKey(Config.DEFAULT_PIN, Config.PIN_KEY);
|
||||
@ -191,8 +193,8 @@ class LoginContainer extends PureComponent {
|
||||
const errorDescription = err?.response?.data?.error_description
|
||||
? err?.response?.data?.error_description
|
||||
: intl.formatMessage({
|
||||
id: err.message,
|
||||
});
|
||||
id: err.message,
|
||||
});
|
||||
Alert.alert(
|
||||
intl.formatMessage({
|
||||
id: 'login.login_failed',
|
||||
@ -288,4 +290,10 @@ const mapStateToProps = (state) => ({
|
||||
isPinCodeOpen: state.application.isPinCodeOpen,
|
||||
});
|
||||
|
||||
export default injectIntl(connect(mapStateToProps)(LoginContainer));
|
||||
const mapQueriesToProps = () => ({
|
||||
userActivityMutation: useUserActivityMutation()
|
||||
})
|
||||
|
||||
export default connect(mapStateToProps)(injectIntl((props) => (
|
||||
<LoginContainer {...props} {...mapQueriesToProps()} />
|
||||
)));
|
||||
|
Loading…
Reference in New Issue
Block a user