diff --git a/src/components/comments/container/commentsContainer.tsx b/src/components/comments/container/commentsContainer.tsx index 8be3ee2095..0a41511cb6 100644 --- a/src/components/comments/container/commentsContainer.tsx +++ b/src/components/comments/container/commentsContainer.tsx @@ -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, @@ -53,6 +54,7 @@ const CommentsContainer = ({ handleOnReplyPress, handleOnCommentsLoaded, postType, + handleWaveDelete, }) => { const navigation = useNavigation(); const postsCachePrimer = postQueries.usePostsCachePrimer(); @@ -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; diff --git a/src/components/qrModal/qrModalView.tsx b/src/components/qrModal/qrModalView.tsx index dfea563e9e..2aebcb933d 100644 --- a/src/components/qrModal/qrModalView.tsx +++ b/src/components/qrModal/qrModalView.tsx @@ -300,13 +300,14 @@ export const QRModal = () => { indicatorStyle={styles.indicator} > - - + {!!device && ( + + )} {isProcessing && ( diff --git a/src/components/votersDisplay/view/votersDisplayView.js b/src/components/votersDisplay/view/votersDisplayView.js index 9ceb67eddb..9ae6cf759a 100644 --- a/src/components/votersDisplay/view/votersDisplayView.js +++ b/src/components/votersDisplay/view/votersDisplayView.js @@ -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}%`; diff --git a/src/providers/queries/postQueries/wavesQueries.ts b/src/providers/queries/postQueries/wavesQueries.ts index df9dd62e3e..dceb94f6e3 100644 --- a/src/providers/queries/postQueries/wavesQueries.ts +++ b/src/providers/queries/postQueries/wavesQueries.ts @@ -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'; @@ -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); @@ -266,6 +271,34 @@ 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, @@ -273,6 +306,7 @@ export const useWavesQuery = (host: string) => { fetchNextPage: _fetchNextPage, latestWavesFetch: _lastestWavesFetch, refresh: _refresh, + deleteWave: deleteMutation.mutate, }; }; diff --git a/src/screens/waves/screen/wavesScreen.tsx b/src/screens/waves/screen/wavesScreen.tsx index 43aca03363..e947c40a77 100644 --- a/src/screens/waves/screen/wavesScreen.tsx +++ b/src/screens/waves/screen/wavesScreen.tsx @@ -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) { @@ -138,6 +146,7 @@ const WavesScreen = ({ route }) => { postType={PostTypes.WAVE} comments={_data} handleOnOptionsPress={_handleOnOptionsPress} + handleWaveDelete={_handleWaveDelete} flatListProps={{ ref: postsListRef, onEndReached: _fetchData, diff --git a/tsconfig.json b/tsconfig.json index 20e6bcbb4c..14aa44a510 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,10 @@ { - "extends": "@react-native/typescript-config/tsconfig.json" + "extends": "@react-native/typescript-config/tsconfig.json", + "compilerOptions": { + "baseUrl": "src", + "paths": { + "*": ["*"] + }, + "moduleResolution": "node" + } } \ No newline at end of file