Merge branch 'development' into nt/wave-post-data

# Conflicts:
#	src/components/quickReplyModal/usePostSubmitter.ts
#	src/utils/editor.ts
This commit is contained in:
Nouman Tahir 2023-09-25 18:47:32 +05:00
commit 18da9d2234
4 changed files with 43 additions and 17 deletions

View File

@ -1,7 +1,7 @@
import { useDispatch } from "react-redux";
import { useAppSelector } from "../../hooks";
import { postComment } from "../../providers/hive/dhive";
import { extractMetadata, generateUniquePermlink, makeJsonMetadata } from "../../utils/editor";
import { extractMetadata, generateReplyPermlink, makeJsonMetadata } from "../../utils/editor";
import { Alert } from "react-native";
import { updateCommentCache } from "../../redux/actions/cacheActions";
import { toastNotification } from "../../redux/actions/uiAction";
@ -10,7 +10,6 @@ import { useState } from "react";
import { useUserActivityMutation, wavesQueries } from "../../providers/queries";
import { PointActivityIds } from "../../providers/ecency/ecency.types";
import { usePublishWaveMutation } from "../../providers/queries/postQueries/wavesQueries";
import { PostTypes } from "../../constants/postTypes";
export const usePostSubmitter = () => {
@ -39,10 +38,7 @@ export const usePostSubmitter = () => {
if (currentAccount) {
setIsSending(true);
const _prefix = postType === PostTypes.WAVE
? postType
: `re-${parentPost.author.replace(/\./g, '')}`
const permlink = generateUniquePermlink(_prefix);
const permlink = generateReplyPermlink(parentPost.author);
const author = currentAccount.name;
const parentAuthor = parentPost.author;
const parentPermlink = parentPost.permlink;
@ -53,8 +49,7 @@ export const usePostSubmitter = () => {
//adding jsonmeta with image ratios here....
const meta = await extractMetadata({
body:commentBody,
fetchRatios:true,
postType
fetchRatios:true
})
const jsonMetadata = makeJsonMetadata(meta, parentTags || ['ecency'])
@ -148,7 +143,7 @@ export const usePostSubmitter = () => {
const _wavesHost = 'ecency.waves' //TODO: make waves host selection dynamic
const latestWavesPost = await wavesQueries.fetchLatestWavesContainer(_wavesHost);
const _cacheCommentData = await _submitReply(body, latestWavesPost, PostTypes.WAVE)
const _cacheCommentData = await _submitReply(body, latestWavesPost)
if(_cacheCommentData){
pusblishWaveMutation.mutate(_cacheCommentData)

View File

@ -1,4 +1,5 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Alert } from 'react-native'
import { useDispatch, useSelector } from 'react-redux';
// Actions
@ -7,9 +8,16 @@ import { setInitPosts, setFeedPosts } from '../../../redux/actions/postsAction';
// Component
import SideMenuView from '../view/sideMenuView';
import { useDrawerStatus } from '@react-navigation/drawer';
import { updateCurrentAccount } from '../../../redux/actions/accountAction';
import { getUser } from '../../../providers/hive/dhive';
import bugsnapInstance from '../../../config/bugsnag';
const SideMenuContainer = ({ navigation }) => {
const dispatch = useDispatch();
const drawerStatus = useDrawerStatus();
const isLoggedIn = useSelector((state) => state.application.isLoggedIn);
const currentAccount = useSelector((state) => state.account.currentAccount);
@ -17,6 +25,34 @@ const SideMenuContainer = ({ navigation }) => {
(state) => state.ui.isVisibleAccountsBottomSheet,
);
useEffect(()=>{
if(drawerStatus === 'open'){
//update profile on drawer open
_updateUserData();
}
}, [drawerStatus])
//fetches and update user data
const _updateUserData = async () => {
try{
if(currentAccount?.username){
let accountData = await getUser(currentAccount.username);
if(accountData){
dispatch(updateCurrentAccount({...currentAccount, ...accountData}))
}
}
} catch(err){
console.warn("failed to update user data")
bugsnapInstance.notify(err);
}
}
const _navigateToRoute = (route = null) => {
if (route) {
navigation.navigate(route);

View File

@ -26,12 +26,12 @@ import { default as ROUTES } from '../../../constants/routeNames';
// Utilities
import {
generatePermlink,
generateReplyPermlink,
makeJsonMetadata,
makeOptions,
extractMetadata,
makeJsonMetadataForUpdate,
createPatch,
generateUniquePermlink,
} from '../../../utils/editor';
// import { generateSignature } from '../../../utils/image';
@ -707,9 +707,7 @@ class EditorContainer extends Component<EditorContainerProps, any> {
});
const { post } = this.state;
const _prefix = `re-${post.author.replace(/\./g, '')}`
const permlink = generateUniquePermlink(_prefix);
const permlink = generateReplyPermlink(post.author);
const parentAuthor = post.author;
const parentPermlink = post.permlink;

View File

@ -3,7 +3,6 @@ import { Image } from 'react-native';
import { diff_match_patch as diffMatchPatch } from 'diff-match-patch';
import VersionNumber from 'react-native-version-number';
import MimeTypes from 'mime-types';
import { PostTypes } from '../constants/postTypes';
export const getWordsCount = (text) =>
text && typeof text === 'string' ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0;
@ -215,12 +214,10 @@ export const extractMetadata = async ({
body,
thumbUrl,
fetchRatios,
postType
}: {
body: string;
thumbUrl?: string;
fetchRatios?: boolean;
postType?: PostTypes;
}) => {
// NOTE: keepting regex to extract usernames as reference for later usage if any
// const userReg = /(^|\s)(@[a-z][-.a-z\d]+[a-z\d])/gim;