Skip to content

Commit

Permalink
Merge pull request #2826 from ecency/nt/hiveuri-notifications
Browse files Browse the repository at this point in the history
handling hiveuri directly from comments and post body
  • Loading branch information
feruzm authored Feb 4, 2024
2 parents 8a33ab8 + b969f7a commit 9037115
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
17 changes: 13 additions & 4 deletions src/components/postElements/body/view/postBodyView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment, useState, useEffect, useRef } from 'react';
import { SafeAreaView, PermissionsAndroid, Platform, View, Text } from 'react-native';
import { SafeAreaView, PermissionsAndroid, Platform, View, Text, Alert } from 'react-native';
import CameraRoll from '@react-native-community/cameraroll';
import { useIntl } from 'react-intl';
import EStyleSheet from 'react-native-extended-stylesheet';
Expand All @@ -10,7 +10,11 @@ import ActionSheetView from 'react-native-actions-sheet';
// Services and Actions
import { useNavigation } from '@react-navigation/native';
import { writeToClipboard } from '../../../../utils/clipboard';
import { showProfileModal, toastNotification } from '../../../../redux/actions/uiAction';
import {
handleHiveUri,
showProfileModal,
toastNotification,
} from '../../../../redux/actions/uiAction';

// Constants
import { default as ROUTES } from '../../../../constants/routeNames';
Expand All @@ -22,6 +26,7 @@ import getWindowDimensions from '../../../../utils/getWindowDimensions';
import { useAppDispatch } from '../../../../hooks';
import { IconButton } from '../../../buttons';
import styles from './postBodyStyles';
import { isHiveUri } from '../../../../utils/hive-uri';

const WIDTH = getWindowDimensions().width;

Expand Down Expand Up @@ -249,8 +254,12 @@ const PostBody = ({ body, metadata, onLoadEnd, width }) => {
};

const _handleSetSelectedLink = (link) => {
setSelectedLink(link);
actionLink.current.show();
if (isHiveUri(link)) {
dispatch(handleHiveUri(link));
} else {
setSelectedLink(link);
actionLink.current.show();
}
};

const _handleSetSelectedImage = (imageLink, postImgUrls) => {
Expand Down
11 changes: 8 additions & 3 deletions src/components/postHtmlRenderer/postInteractionHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import RNFetchBlob from 'rn-fetch-blob';
import { useDispatch } from 'react-redux';
import { useNavigation } from '@react-navigation/native';
import ROUTES from '../../constants/routeNames';
import { toastNotification } from '../../redux/actions/uiAction';
import { handleHiveUri, toastNotification } from '../../redux/actions/uiAction';
import { writeToClipboard } from '../../utils/clipboard';

import { OptionsModal } from '../atoms';
Expand All @@ -20,6 +20,7 @@ import VideoPlayer from '../videoPlayer/videoPlayerView';
import { IconButton } from '../buttons';
import styles from './postHtmlRendererStyles';
import { PostTypes } from '../../constants/postTypes';
import { isHiveUri } from '../../utils/hive-uri';

interface PostHtmlInteractionHandlerProps {
postType?: PostTypes;
Expand Down Expand Up @@ -55,8 +56,12 @@ export const PostHtmlInteractionHandler = forwardRef(
}
},
handleLinkPress: (url: string) => {
setSelectedLink(url);
actionLink.current?.show();
if (isHiveUri(url)) {
dispatch(handleHiveUri(url));
} else {
setSelectedLink(url);
actionLink.current?.show();
}
},
handleYoutubePress: (videoId, startTime) => {
if (videoId && youtubePlayerRef.current) {
Expand Down
13 changes: 5 additions & 8 deletions src/components/qrModal/qrModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as hiveuri from 'hive-uri';
import styles from './qrModalStyles';
import { useAppDispatch, useAppSelector } from '../../hooks';
import {
handleHiveUri,
showActionModal,
showWebViewModal,
toastNotification,
Expand Down Expand Up @@ -36,20 +37,18 @@ export const QRModal = () => {
const isPinCodeOpen = useAppSelector((state) => state.application.isPinCodeOpen);
const isLoggedIn = useAppSelector((state) => state.application.isLoggedIn);


const [isScannerActive, setIsScannerActive] = useState(true);
const [isProcessing, setIsProcessing] = useState(false);
const sheetModalRef = useRef<ActionSheet>();
const scannerRef = useRef(null);

//TODO: make sure to properly clean uri processing code to process uri from deep links and notifications
// TODO: make sure to properly clean uri processing code to process uri from deep links and notifications
const hiveUriToHandle = useAppSelector((state) => state.ui.hiveUriToHandle);
useEffect(() => {
if(hiveUriToHandle){
if (hiveUriToHandle) {
_handleHiveUri(hiveUriToHandle);
}
}, [hiveUriToHandle])

}, [hiveUriToHandle]);

useEffect(() => {
if (isVisibleQRModal) {
Expand All @@ -58,11 +57,8 @@ export const QRModal = () => {
} else {
sheetModalRef?.current?.hide();
}

}, [isVisibleQRModal]);



const requestCameraPermission = async () => {
if (Platform.OS === 'ios') {
const permissionStatus = await check(PERMISSIONS.IOS.CAMERA);
Expand Down Expand Up @@ -218,6 +214,7 @@ export const QRModal = () => {
},
},
],
onClosed: () => dispatch(handleHiveUri('')),
}),
);
})
Expand Down
13 changes: 7 additions & 6 deletions src/screens/application/hook/useInitApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import messaging from '@react-native-firebase/messaging';
import BackgroundTimer from 'react-native-background-timer';
import FastImage from 'react-native-fast-image';
import { useAppDispatch, useAppSelector } from '../../../hooks';
import { handleHiveUri, setDeviceOrientation, setLockedOrientation } from '../../../redux/actions/uiAction';
import {
handleHiveUri,
setDeviceOrientation,
setLockedOrientation,
} from '../../../redux/actions/uiAction';
import { orientations } from '../../../redux/constants/orientationsConstants';
import isAndroidTablet from '../../../utils/isAndroidTablet';
import darkTheme from '../../../themes/darkTheme';
Expand All @@ -27,8 +31,6 @@ import { markNotifications } from '../../../providers/ecency/ecency';
import { updateUnreadActivityCount } from '../../../redux/actions/accountAction';
import RootNavigation from '../../../navigation/rootNavigation';
import ROUTES from '../../../constants/routeNames';
import { isPoundElement } from 'intl-messageformat-parser';
import * as hiveuri from 'hive-uri';

export const useInitApplication = () => {
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -235,8 +237,8 @@ export const useInitApplication = () => {
break;

case 'hiveuri':
if(push.hiveUri){
dispatch(handleHiveUri(push.hiveUri))
if (push.hiveUri) {
dispatch(handleHiveUri(push.hiveUri));
}
break;

Expand Down Expand Up @@ -267,7 +269,6 @@ export const useInitApplication = () => {
});
}
}

}
};
};

0 comments on commit 9037115

Please sign in to comment.