From e60813de0338f528f6816dacca8e6ae77ab5b6a5 Mon Sep 17 00:00:00 2001 From: Rafael Date: Tue, 3 May 2022 08:57:39 -0300 Subject: [PATCH] Bring back repost page from previous changes for direct link --- ui/component/router/view.jsx | 2 + ui/constants/pageTitles.js | 1 + ui/constants/pages.js | 1 + ui/page/repost/index.js | 14 +++++++ ui/page/repost/view.jsx | 76 ++++++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 ui/page/repost/index.js create mode 100644 ui/page/repost/view.jsx diff --git a/ui/component/router/view.jsx b/ui/component/router/view.jsx index 0c8f0c139..5731c7f2f 100644 --- a/ui/component/router/view.jsx +++ b/ui/component/router/view.jsx @@ -83,6 +83,7 @@ const PasswordSetPage = lazyImport(() => import('page/passwordSet' /* webpackChu const PublishPage = lazyImport(() => import('page/publish' /* webpackChunkName: "publish" */)); const ReportContentPage = lazyImport(() => import('page/reportContent' /* webpackChunkName: "reportContent" */)); const ReportPage = lazyImport(() => import('page/report' /* webpackChunkName: "report" */)); +const RepostNew = lazyImport(() => import('page/repost' /* webpackChunkName: "repost" */)); const RewardsPage = lazyImport(() => import('page/rewards' /* webpackChunkName: "rewards" */)); const RewardsVerifyPage = lazyImport(() => import('page/rewardsVerify' /* webpackChunkName: "rewardsVerify" */)); const SearchPage = lazyImport(() => import('page/search' /* webpackChunkName: "search" */)); @@ -351,6 +352,7 @@ function AppRouter(props: Props) { /> + diff --git a/ui/constants/pageTitles.js b/ui/constants/pageTitles.js index 4c1fb523b..6e917920a 100644 --- a/ui/constants/pageTitles.js +++ b/ui/constants/pageTitles.js @@ -31,6 +31,7 @@ export const PAGE_TITLE = { [PAGES.RECEIVE]: 'Your address', [PAGES.REPORT]: 'Report an issue or request a feature', [PAGES.REPORT_CONTENT]: 'Report content', + [PAGES.REPOST_NEW]: 'Repost', [PAGES.REWARDS]: 'Rewards', [PAGES.REWARDS_VERIFY]: 'Verify to earn Credits', [PAGES.SEARCH]: 'Search', diff --git a/ui/constants/pages.js b/ui/constants/pages.js index 861eef166..bd42ad7bb 100644 --- a/ui/constants/pages.js +++ b/ui/constants/pages.js @@ -45,6 +45,7 @@ exports.REPORT = 'report'; exports.REPORT_CONTENT = 'report_content'; exports.REWARDS = 'rewards'; exports.REWARDS_VERIFY = 'rewards/verify'; +exports.REPOST_NEW = 'repost'; exports.SEND = 'send'; exports.SETTINGS = 'settings'; exports.SETTINGS_STRIPE_CARD = 'settings/card'; diff --git a/ui/page/repost/index.js b/ui/page/repost/index.js new file mode 100644 index 000000000..aa2aba3af --- /dev/null +++ b/ui/page/repost/index.js @@ -0,0 +1,14 @@ +import { connect } from 'react-redux'; +import { doResolveUri } from 'redux/actions/claims'; +import { selectBalance } from 'redux/selectors/wallet'; +import RepostPage from './view'; + +const select = (state, props) => ({ + balance: selectBalance(state), +}); + +const perform = { + resolveUri: doResolveUri, +}; + +export default connect(select, perform)(RepostPage); diff --git a/ui/page/repost/view.jsx b/ui/page/repost/view.jsx new file mode 100644 index 000000000..acb1ecb6c --- /dev/null +++ b/ui/page/repost/view.jsx @@ -0,0 +1,76 @@ +// @flow +import React from 'react'; +import Page from 'component/page'; +import { useHistory } from 'react-router'; +import RepostCreate from 'component/repostCreate'; +import YrblWalletEmpty from 'component/yrblWalletEmpty'; +import useThrottle from 'effects/use-throttle'; + +const REPOST_PARAMS = { + FROM: 'from', + TO: 'to', + REDIRECT: 'redirect', +}; + +type Props = { + // --redux-- + balance: number, + resolveUri: (string) => void, +}; + +function RepostPage(props: Props) { + const { balance, resolveUri } = props; + + const { + location: { search }, + } = useHistory(); + + const [contentUri, setContentUri] = React.useState(''); + const [repostUri, setRepostUri] = React.useState(''); + + const urlParams = new URLSearchParams(search); + const repostFrom = urlParams.get(REPOST_PARAMS.FROM); + const redirectUri = urlParams.get(REPOST_PARAMS.REDIRECT); + const repostTo = urlParams.get(REPOST_PARAMS.TO); + + const decodedFrom = repostFrom && decodeURIComponent(repostFrom); + const throttledContentValue = useThrottle(contentUri, 500); + const throttledRepostValue = useThrottle(repostUri, 500); + + React.useEffect(() => { + if (throttledContentValue) { + resolveUri(throttledContentValue); + } + }, [throttledContentValue, resolveUri]); + + React.useEffect(() => { + if (throttledRepostValue) { + resolveUri(throttledRepostValue); + } + }, [throttledRepostValue, resolveUri]); + + React.useEffect(() => { + if (repostTo) { + resolveUri(repostTo); + } + }, [repostTo, resolveUri]); + + return ( + + {balance === 0 && } +
+ +
+
+ ); +} + +export default RepostPage;