Skip to content

Commit

Permalink
Merge pull request #2888 from ecency/sa/crash-fixes
Browse files Browse the repository at this point in the history
Crash Bug Fixes
  • Loading branch information
feruzm authored Jul 6, 2024
2 parents b4ed086 + 31d2c2c commit 0cc4a04
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/components/comments/container/commentsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CommentsView from '../view/commentsView';
import { updateCommentCache } from '../../../redux/actions/cacheActions';
import { CacheStatus } from '../../../redux/reducers/cacheReducer';
import { postQueries } from '../../../providers/queries';
import { PostTypes } from '../../../constants/postTypes';

const CommentsContainer = ({
author,
Expand Down Expand Up @@ -53,6 +54,7 @@ const CommentsContainer = ({
handleOnReplyPress,
handleOnCommentsLoaded,
postType,
handleWaveDelete,
}) => {
const navigation = useNavigation();
const postsCachePrimer = postQueries.usePostsCachePrimer();
Expand Down Expand Up @@ -204,7 +206,14 @@ const CommentsContainer = ({

const _handleDeleteComment = (_permlink) => {
let filteredComments;

if (postType === PostTypes.WAVE && handleWaveDelete) {
handleWaveDelete({
currentAccount,
pinCode,
_permlink,
});
return;
}
deleteComment(currentAccount, pinCode, _permlink).then(() => {
let deletedItem = null;

Expand Down
15 changes: 8 additions & 7 deletions src/components/qrModal/qrModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,14 @@ export const QRModal = () => {
indicatorStyle={styles.indicator}
>
<View style={styles.mainContainer}>
<Camera
style={EStyleSheet.absoluteFill}
device={device}
isActive={isScannerActive}
codeScanner={codeScanner}
/>

{!!device && (
<Camera
style={EStyleSheet.absoluteFill}
device={device}
isActive={isScannerActive}
codeScanner={codeScanner}
/>
)}
{isProcessing && (
<View style={styles.activityIndicatorContainer}>
<ActivityIndicator color="white" style={styles.activityIndicator} />
Expand Down
1 change: 1 addition & 0 deletions src/components/votersDisplay/view/votersDisplayView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const VotersDisplayView = ({ votes, createdAt = '2010-01-01T00:00:00' }) => {

const _renderItem = ({ item, index }) => {
const value = item.reward && `$ ${item.reward}`;

// eslint-disable-next-line
const percent = !isNaN(item.percent100) && `${item.percent100}%`;

Expand Down
36 changes: 35 additions & 1 deletion src/providers/queries/postQueries/wavesQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
import { useEffect, useMemo, useRef, useState } from 'react';

import { unionBy, isArray } from 'lodash';
import { getDiscussionCollection, getAccountPosts } from '../../hive/dhive';
import { useDispatch } from 'react-redux';
import { useIntl } from 'react-intl';
import { getDiscussionCollection, getAccountPosts, deleteComment } from '../../hive/dhive';

import QUERIES from '../queryKeys';
import { delay } from '../../../utils/editor';
Expand All @@ -18,9 +20,12 @@ import {
mapDiscussionToThreads,
} from '../../../utils/postParser';
import { useAppSelector } from '../../../hooks';
import { toastNotification } from '../../../redux/actions/uiAction';

export const useWavesQuery = (host: string) => {
const queryClient = useQueryClient();
const dispatch = useDispatch();
const intl = useIntl();

const cache = useAppSelector((state) => state.cache);
const mutes = useAppSelector((state) => state.account.currentAccount.mutes);
Expand Down Expand Up @@ -266,13 +271,42 @@ export const useWavesQuery = (host: string) => {
return _newWaves;
};

// wave delete mutation to delete wave and update query
const deleteWave = async ({ currentAccount, pinCode, _permlink }: any) => {
const response = await deleteComment(currentAccount, pinCode, _permlink);

if (!response?.id) {
throw new Error('Failed to delete the wave');
}
return _permlink;
};

const deleteMutation = useMutation(deleteWave, {
onSuccess: (_permlink) => {
const waveQueries = queryClient.getQueriesData([QUERIES.WAVES.GET, host]);
// filter out the deleted wave from queries data
waveQueries.forEach(([queryKey, oldData]) => {
if (oldData) {
const newData = oldData?.filter((wave: { permlink: any }) => wave.permlink !== _permlink);
queryClient.setQueryData(queryKey, newData);
}
});
dispatch(toastNotification(intl.formatMessage({ id: 'alert.success' })));
},
onError: (error) => {
console.log('Failed to delete wave:', error);
dispatch(toastNotification(intl.formatMessage({ id: 'alert.error' })));
},
});

return {
data: _filteredData,
isRefreshing,
isLoading: isLoading || _lastItem?.isLoading || _lastItem?.isFetching,
fetchNextPage: _fetchNextPage,
latestWavesFetch: _lastestWavesFetch,
refresh: _refresh,
deleteWave: deleteMutation.mutate,
};
};

Expand Down
9 changes: 9 additions & 0 deletions src/screens/waves/screen/wavesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ const WavesScreen = ({ route }) => {
}
};

const _handleWaveDelete = ({ currentAccount, pinCode, _permlink }: any) => {
wavesQuery.deleteWave({
currentAccount,
pinCode,
_permlink,
});
};

// scrolls to top, blocks scroll popup for 2 seconds to reappear after scroll
const _scrollTop = () => {
if (postsListRef.current) {
Expand Down Expand Up @@ -138,6 +146,7 @@ const WavesScreen = ({ route }) => {
postType={PostTypes.WAVE}
comments={_data}
handleOnOptionsPress={_handleOnOptionsPress}
handleWaveDelete={_handleWaveDelete}
flatListProps={{
ref: postsListRef,
onEndReached: _fetchData,
Expand Down
9 changes: 8 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"extends": "@react-native/typescript-config/tsconfig.json"
"extends": "@react-native/typescript-config/tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"paths": {
"*": ["*"]
},
"moduleResolution": "node"
}
}

0 comments on commit 0cc4a04

Please sign in to comment.