Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a reblog functionality into reblogScreen #2720

Merged
merged 18 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/globalStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ export default EStyleSheet.create({
tabBarBottom: {
paddingBottom: 60,
},
mainbutton: {
width: '46%',
position: 'relative',
left: 180,
bottom: 20,
},
});
59 changes: 0 additions & 59 deletions src/screens/reblogs/screen/reblogScreen.js

This file was deleted.

158 changes: 158 additions & 0 deletions src/screens/reblogs/screen/reblogScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import React, { useState } from 'react';
import { FlatList, SafeAreaView, RefreshControl, ScrollView } from 'react-native';
import { useIntl } from 'react-intl';
import get from 'lodash/get';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
import reactotron from 'reactotron-react-native';
import { useAppDispatch, useAppSelector } from '../../../hooks';
import showLoginAlert from '../../../utils/showLoginAlert';
import { reblog } from '../../../providers/hive/dhive';
import { useUserActivityMutation } from '../../../providers/queries/pointQueries';
import { getPostReblogs } from '../../../providers/ecency/ecency';
// Components
import { BasicHeader, MainButton, UserListItem } from '../../../components';

// Container
import AccountListContainer from '../../../containers/accountListContainer';

// Utils
import globalStyles from '../../../globalStyles';
import { getTimeFromNow } from '../../../utils/time';
import { setRcOffer, toastNotification } from '../../../redux/actions/uiAction';
import { PointActivityIds } from '../../../providers/ecency/ecency.types';

const renderUserListItem = (item, index, handleOnUserPress) => {
return (
<UserListItem
index={index}
username={item.account}
description={getTimeFromNow(item.timestamp)}
handleOnPress={() => handleOnUserPress(item.account)}
// eslint-disable-next-line max-len
isClickable rightText={undefined} descriptionStyle={undefined} subRightText={undefined} isRightColor={undefined} isHasRightItem={undefined} isBlackRightColor={undefined} itemIndex={undefined} handleOnLongPress={undefined} text={undefined} middleText={undefined} rightTextStyle={undefined} onPressRightText={undefined} isLoggedIn={undefined} searchValue={undefined} rightTooltipText={undefined} leftItemRenderer={undefined} rightItemRenderer={undefined} />
);
};

const ReblogScreen = ({ route }) => {
const [refreshing, setRefreshing] = React.useState(false);
const content = route.params?.content;
const pReblogs = route.params?.reblogs;

const [reblogs, setReblogs] = useState(pReblogs);
const intl = useIntl();
const headerTitle = intl.formatMessage({
id: 'reblog.title',
});
const dispatch = useAppDispatch();
const userActivityMutation = useUserActivityMutation();
const isLoggedIn = useAppSelector((state) => state.application.isLoggedIn);
const currentAccount = useAppSelector((state) => state.account.currentAccount);
const pinCode = useAppSelector((state) => state.application.pin);
const dummy = {
account: 'Ali',
timestamp: '2023-07-16T23:30:39+00:00',
}


const onRefresh = React.useCallback(() => {
setRefreshing(true);
getPostReblogs(content).then((result) => {
result = [...reblogs, dummy];
setReblogs(result);
reactotron.log("Result", result);
});


}, []);

const _reblog = () => {
if (!isLoggedIn) {
showLoginAlert({ intl });
return;
}

if (isLoggedIn) {
reblog(currentAccount, pinCode, content.author, content.permlink)
.then((response) => {
// track user activity points ty=130
userActivityMutation.mutate({
pointsTy: PointActivityIds.REBLOG,
transactionId: response.id,

});

dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.success_rebloged',
}),
),
);
})
.catch((error) => {
if (String(get(error, 'jse_shortmsg', '')).indexOf('has already reblogged') > -1) {
dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.already_rebloged',
}),
),
);
} else {
if (error && error.jse_shortmsg.split(': ')[1].includes('wait to transact')) {
// when RC is not enough, offer boosting account
dispatch(setRcOffer(true));
} else {
// when other errors
dispatch(toastNotification(intl.formatMessage({ id: 'alert.fail' })));
}
}
});
}
};

return (
<AccountListContainer data={reblogs}>
{({ data, filterResult, handleSearch, handleOnUserPress }) => (

<SafeAreaView style={[globalStyles.container, { paddingBottom: 40 }]}>
<ScrollView
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
>
{/* Your content goes here */}
<BasicHeader
title={`${headerTitle} (${data && data.length})`}
backIconName="close"
isHasSearch
handleOnSearch={(text) => handleSearch(text, 'account')}
/>

<FlatList
data={filterResult || data}
keyExtractor={(item) => item.account}
removeClippedSubviews={false}
renderItem={({ item, index }) =>
renderUserListItem(item, index, handleOnUserPress)
}
/>


</ScrollView>
<MainButton
style={globalStyles.mainbutton}
onPress={_reblog}
iconName="square-edit-outline"
iconType="MaterialCommunityIcons"
iconColor="white"
text="Reblog Post"
/>
</SafeAreaView>

)}
</AccountListContainer>
);
};

export default gestureHandlerRootHOC(ReblogScreen);