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 { useDispatch } from "react-redux";
import { useAppSelector } from "../../hooks"; import { useAppSelector } from "../../hooks";
import { postComment } from "../../providers/hive/dhive"; 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 { Alert } from "react-native";
import { updateCommentCache } from "../../redux/actions/cacheActions"; import { updateCommentCache } from "../../redux/actions/cacheActions";
import { toastNotification } from "../../redux/actions/uiAction"; import { toastNotification } from "../../redux/actions/uiAction";
@ -10,7 +10,6 @@ import { useState } from "react";
import { useUserActivityMutation, wavesQueries } from "../../providers/queries"; import { useUserActivityMutation, wavesQueries } from "../../providers/queries";
import { PointActivityIds } from "../../providers/ecency/ecency.types"; import { PointActivityIds } from "../../providers/ecency/ecency.types";
import { usePublishWaveMutation } from "../../providers/queries/postQueries/wavesQueries"; import { usePublishWaveMutation } from "../../providers/queries/postQueries/wavesQueries";
import { PostTypes } from "../../constants/postTypes";
export const usePostSubmitter = () => { export const usePostSubmitter = () => {
@ -39,10 +38,7 @@ export const usePostSubmitter = () => {
if (currentAccount) { if (currentAccount) {
setIsSending(true); setIsSending(true);
const _prefix = postType === PostTypes.WAVE const permlink = generateReplyPermlink(parentPost.author);
? postType
: `re-${parentPost.author.replace(/\./g, '')}`
const permlink = generateUniquePermlink(_prefix);
const author = currentAccount.name; const author = currentAccount.name;
const parentAuthor = parentPost.author; const parentAuthor = parentPost.author;
const parentPermlink = parentPost.permlink; const parentPermlink = parentPost.permlink;
@ -53,8 +49,7 @@ export const usePostSubmitter = () => {
//adding jsonmeta with image ratios here.... //adding jsonmeta with image ratios here....
const meta = await extractMetadata({ const meta = await extractMetadata({
body:commentBody, body:commentBody,
fetchRatios:true, fetchRatios:true
postType
}) })
const jsonMetadata = makeJsonMetadata(meta, parentTags || ['ecency']) const jsonMetadata = makeJsonMetadata(meta, parentTags || ['ecency'])
@ -148,7 +143,7 @@ export const usePostSubmitter = () => {
const _wavesHost = 'ecency.waves' //TODO: make waves host selection dynamic const _wavesHost = 'ecency.waves' //TODO: make waves host selection dynamic
const latestWavesPost = await wavesQueries.fetchLatestWavesContainer(_wavesHost); const latestWavesPost = await wavesQueries.fetchLatestWavesContainer(_wavesHost);
const _cacheCommentData = await _submitReply(body, latestWavesPost, PostTypes.WAVE) const _cacheCommentData = await _submitReply(body, latestWavesPost)
if(_cacheCommentData){ if(_cacheCommentData){
pusblishWaveMutation.mutate(_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'; import { useDispatch, useSelector } from 'react-redux';
// Actions // Actions
@ -7,9 +8,16 @@ import { setInitPosts, setFeedPosts } from '../../../redux/actions/postsAction';
// Component // Component
import SideMenuView from '../view/sideMenuView'; 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 SideMenuContainer = ({ navigation }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const drawerStatus = useDrawerStatus();
const isLoggedIn = useSelector((state) => state.application.isLoggedIn); const isLoggedIn = useSelector((state) => state.application.isLoggedIn);
const currentAccount = useSelector((state) => state.account.currentAccount); const currentAccount = useSelector((state) => state.account.currentAccount);
@ -17,6 +25,34 @@ const SideMenuContainer = ({ navigation }) => {
(state) => state.ui.isVisibleAccountsBottomSheet, (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) => { const _navigateToRoute = (route = null) => {
if (route) { if (route) {
navigation.navigate(route); navigation.navigate(route);

View File

@ -26,12 +26,12 @@ import { default as ROUTES } from '../../../constants/routeNames';
// Utilities // Utilities
import { import {
generatePermlink, generatePermlink,
generateReplyPermlink,
makeJsonMetadata, makeJsonMetadata,
makeOptions, makeOptions,
extractMetadata, extractMetadata,
makeJsonMetadataForUpdate, makeJsonMetadataForUpdate,
createPatch, createPatch,
generateUniquePermlink,
} from '../../../utils/editor'; } from '../../../utils/editor';
// import { generateSignature } from '../../../utils/image'; // import { generateSignature } from '../../../utils/image';
@ -707,9 +707,7 @@ class EditorContainer extends Component<EditorContainerProps, any> {
}); });
const { post } = this.state; const { post } = this.state;
const permlink = generateReplyPermlink(post.author);
const _prefix = `re-${post.author.replace(/\./g, '')}`
const permlink = generateUniquePermlink(_prefix);
const parentAuthor = post.author; const parentAuthor = post.author;
const parentPermlink = post.permlink; 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 { diff_match_patch as diffMatchPatch } from 'diff-match-patch';
import VersionNumber from 'react-native-version-number'; import VersionNumber from 'react-native-version-number';
import MimeTypes from 'mime-types'; import MimeTypes from 'mime-types';
import { PostTypes } from '../constants/postTypes';
export const getWordsCount = (text) => export const getWordsCount = (text) =>
text && typeof text === 'string' ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0; text && typeof text === 'string' ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0;
@ -215,12 +214,10 @@ export const extractMetadata = async ({
body, body,
thumbUrl, thumbUrl,
fetchRatios, fetchRatios,
postType
}: { }: {
body: string; body: string;
thumbUrl?: string; thumbUrl?: string;
fetchRatios?: boolean; fetchRatios?: boolean;
postType?: PostTypes;
}) => { }) => {
// NOTE: keepting regex to extract usernames as reference for later usage if any // 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; // const userReg = /(^|\s)(@[a-z][-.a-z\d]+[a-z\d])/gim;