implemented comment history api

This commit is contained in:
Sadaqat Ali 2022-04-26 16:54:26 +05:00
parent edd1eed898
commit f7af060ed6
6 changed files with 74 additions and 6 deletions

View File

@ -104,8 +104,9 @@ class PostDropdownContainer extends PureComponent {
// Component Functions // Component Functions
_handleOnDropdownSelect = async (index) => { _handleOnDropdownSelect = async (index) => {
const { content, dispatch, intl, navigation } = this.props; const { content, dispatch, intl, navigation, } = this.props;
const { options } = this.state; const { options } = this.state;
console.log('content : ', content);
switch (options[index]) { switch (options[index]) {
case 'copy': case 'copy':
@ -170,6 +171,10 @@ class PostDropdownContainer extends PureComponent {
case 'edit-history': case 'edit-history':
navigation.navigate({ navigation.navigate({
routeName: ROUTES.SCREENS.EDIT_HISTORY, routeName: ROUTES.SCREENS.EDIT_HISTORY,
params: {
author: content?.author || '',
permlink: content?.permlink || '',
},
}); });
break; break;
default: default:

View File

@ -26,6 +26,7 @@ api.interceptors.request.use((request) => {
|| request.url.startsWith('/private-api/received-vesting/') || request.url.startsWith('/private-api/received-vesting/')
|| request.url.startsWith('/private-api/referrals/') || request.url.startsWith('/private-api/referrals/')
|| request.url.startsWith('/private-api/market-data') || request.url.startsWith('/private-api/market-data')
|| request.url.startsWith('/private-api/comment-history')
){ ){
return request return request
} }

View File

@ -1,6 +1,6 @@
import { COIN_IDS } from '../../constants/defaultCoins'; import { COIN_IDS } from '../../constants/defaultCoins';
import { Referral } from '../../models'; import { Referral } from '../../models';
import { LatestMarketPrices, LatestQuotes, QuoteItem, ReferralStat } from './ecency.types'; import { CommentHistoryItem, LatestMarketPrices, LatestQuotes, QuoteItem, ReferralStat } from './ecency.types';
export const convertReferral = (rawData: any) => { export const convertReferral = (rawData: any) => {
return { return {
@ -43,3 +43,13 @@ export const convertLatestQuotes = (rawData: any, estmPrice:number, currencyRate
} as LatestQuotes; } as LatestQuotes;
}; };
export const convertCommentHistory = (rawData: any) => {
return {
body: rawData.body || '',
tags: rawData.tags || '',
timestamp: rawData.timestamp || '',
title: rawData.title || '',
v: rawData.v || 1,
} as CommentHistoryItem;
};

View File

@ -6,8 +6,8 @@ import bugsnagInstance from '../../config/bugsnag';
import { SERVER_LIST } from '../../constants/options/api'; import { SERVER_LIST } from '../../constants/options/api';
import { parsePost } from '../../utils/postParser'; import { parsePost } from '../../utils/postParser';
import { extractMetadata, makeJsonMetadata } from '../../utils/editor'; import { extractMetadata, makeJsonMetadata } from '../../utils/editor';
import { LatestMarketPrices, ReceivedVestingShare, Referral, ReferralStat } from './ecency.types'; import { CommentHistoryItem, LatestMarketPrices, ReceivedVestingShare, Referral, ReferralStat } from './ecency.types';
import { convertLatestQuotes, convertReferral, convertReferralStat } from './converters'; import { convertCommentHistory, convertLatestQuotes, convertReferral, convertReferralStat } from './converters';
@ -826,3 +826,27 @@ export const getReferralsStats = async (username: string):Promise<ReferralStat>
} }
} }
/**
* ************************************
* REFERRAL API IMPLEMENTATION
* ************************************
*/
export const getCommentHistory = async (author: string, permlink: string ):Promise<CommentHistoryItem[]> => {
try {
const data = {
author,
permlink
}
const res = await ecencyApi.post('/private-api/comment-history', data);
console.log('comment history', res.data);
if (!res.data) {
throw new Error('No history data!');
}
return res?.data?.list.map((item) => convertCommentHistory(item));
} catch (error) {
bugsnagInstance.notify(error);
throw error;
}
}

View File

@ -42,3 +42,11 @@ export interface UserPoint {
export interface LatestQuotes { export interface LatestQuotes {
[key:string]:QuoteItem [key:string]:QuoteItem
} }
export interface CommentHistoryItem {
body: string;
tags: [string];
title: string;
timestamp:string;
v: number;
}

View File

@ -1,7 +1,7 @@
import React, { Fragment } from 'react'; import React, { Fragment } from 'react';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { Text, View } from 'react-native'; import { Alert, Text, View } from 'react-native';
import { import {
BasicHeader, BasicHeader,
} from '../../components'; } from '../../components';
@ -9,9 +9,29 @@ import {
// styles // styles
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
import styles from './editHistoryScreenStyles'; import styles from './editHistoryScreenStyles';
import { getCommentHistory } from '../../providers/ecency/ecency';
import { CommentHistoryItem } from '../../providers/ecency/ecency.types';
const EditHistoryScreen = ({ navigation }) => { const EditHistoryScreen = ({ navigation }) => {
const {author, permlink} = navigation.state.params;
const intl = useIntl(); const intl = useIntl();
const [editHistory, setEditHistory] = useState<CommentHistoryItem[]>([])
useEffect(() => {
_getCommentHistory();
},[])
const _getCommentHistory = async () => {
const responseData = await getCommentHistory(author, permlink);
if(!responseData){
Alert.alert('No History found!')
return;
}
setEditHistory(responseData);
}
console.log('author, permlink : ', author, permlink);
console.log('editHistory : ', editHistory);
return ( return (
<Fragment> <Fragment>
<BasicHeader <BasicHeader