doNavigate refactor
This commit is contained in:
parent
4a0f8505f8
commit
13d46eeb19
5 changed files with 301 additions and 557 deletions
742
build/index.js
742
build/index.js
File diff suppressed because it is too large
Load diff
12
src/index.js
12
src/index.js
|
@ -1,7 +1,11 @@
|
|||
// constants
|
||||
import * as ACTIONS from 'constants/action_types';
|
||||
|
||||
// common
|
||||
import Lbry from 'lbry';
|
||||
import Lbryapi from 'lbryapi';
|
||||
|
||||
export { ACTIONS };
|
||||
export { Lbry, Lbryapi };
|
||||
export {
|
||||
regexInvalidURI,
|
||||
|
@ -27,14 +31,6 @@ export {
|
|||
doFileList,
|
||||
doFetchFileInfosAndPublishedClaims,
|
||||
} from 'redux/actions/file_info';
|
||||
export {
|
||||
doNavigate,
|
||||
doAuthNavigate,
|
||||
doHistoryTraverse,
|
||||
doHistoryBack,
|
||||
doHistoryForward,
|
||||
doRecordScroll,
|
||||
} from 'redux/actions/navigation';
|
||||
export { doSearch } from 'redux/actions/search';
|
||||
export {
|
||||
doUpdateBalance,
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
import * as ACTIONS from 'constants/action_types';
|
||||
import { selectHistoryIndex, selectHistoryStack } from 'redux/selectors/navigation';
|
||||
import { toQueryString } from 'util/query_params';
|
||||
|
||||
export function doNavigate(path, params = {}, options = {}) {
|
||||
return dispatch => {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
|
||||
let url = path;
|
||||
if (params && Object.values(params).length) {
|
||||
url += `?${toQueryString(params)}`;
|
||||
}
|
||||
|
||||
const { scrollY } = options;
|
||||
|
||||
dispatch({
|
||||
type: ACTIONS.HISTORY_NAVIGATE,
|
||||
data: { url, index: options.index, scrollY },
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function doAuthNavigate(pathAfterAuth = null, params = {}) {
|
||||
return dispatch => {
|
||||
if (pathAfterAuth) {
|
||||
dispatch({
|
||||
type: ACTIONS.CHANGE_AFTER_AUTH_PATH,
|
||||
data: {
|
||||
path: `${pathAfterAuth}?${toQueryString(params)}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
dispatch(doNavigate('/auth'));
|
||||
};
|
||||
}
|
||||
|
||||
export function doHistoryTraverse(dispatch, state, modifier) {
|
||||
const stack = selectHistoryStack(state);
|
||||
const index = selectHistoryIndex(state) + modifier;
|
||||
|
||||
if (index >= 0 && index < stack.length) {
|
||||
const historyItem = stack[index];
|
||||
dispatch(doNavigate(historyItem.path, {}, { scrollY: historyItem.scrollY, index }));
|
||||
}
|
||||
}
|
||||
|
||||
export function doHistoryBack() {
|
||||
return (dispatch, getState) => doHistoryTraverse(dispatch, getState(), -1);
|
||||
}
|
||||
|
||||
export function doHistoryForward() {
|
||||
return (dispatch, getState) => doHistoryTraverse(dispatch, getState(), 1);
|
||||
}
|
||||
|
||||
export function doRecordScroll(scroll) {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: ACTIONS.WINDOW_SCROLLED,
|
||||
data: { scrollY: scroll },
|
||||
});
|
||||
};
|
||||
}
|
|
@ -1,12 +1,11 @@
|
|||
import * as ACTIONS from 'constants/action_types';
|
||||
import { buildURI } from 'lbryURI';
|
||||
import { doResolveUri } from 'redux/actions/claims';
|
||||
import { doNavigate } from 'redux/actions/navigation';
|
||||
import { selectCurrentPage } from 'redux/selectors/navigation';
|
||||
import batchActions from 'util/batchActions';
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export function doSearch(rawQuery) {
|
||||
export function doSearch(rawQuery, currentPageNotSearchHandler) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const page = selectCurrentPage(state);
|
||||
|
@ -26,7 +25,9 @@ export function doSearch(rawQuery) {
|
|||
});
|
||||
|
||||
if (page !== 'search') {
|
||||
dispatch(doNavigate('search', { query }));
|
||||
if (currentPageNotSearchHandler) {
|
||||
currentPageNotSearchHandler();
|
||||
}
|
||||
} else {
|
||||
fetch(`https://lighthouse.lbry.io/search?s=${query}`)
|
||||
.then(
|
||||
|
|
|
@ -2,7 +2,6 @@ import * as ACTIONS from 'constants/action_types';
|
|||
import * as MODALS from 'constants/modal_types';
|
||||
import Lbry from 'lbry';
|
||||
import { doOpenModal, doShowSnackBar } from 'redux/actions/app';
|
||||
import { doNavigate } from 'redux/actions/navigation';
|
||||
import {
|
||||
selectBalance,
|
||||
selectDraftTransaction,
|
||||
|
@ -155,7 +154,7 @@ export function doSetDraftTransactionAddress(address) {
|
|||
};
|
||||
}
|
||||
|
||||
export function doSendSupport(amount, claimId, uri) {
|
||||
export function doSendSupport(amount, claimId, uri, successCallback, errorCallback) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const balance = selectBalance(state);
|
||||
|
@ -169,36 +168,6 @@ export function doSendSupport(amount, claimId, uri) {
|
|||
type: ACTIONS.SUPPORT_TRANSACTION_STARTED,
|
||||
});
|
||||
|
||||
const successCallback = results => {
|
||||
if (results.txid) {
|
||||
dispatch({
|
||||
type: ACTIONS.SUPPORT_TRANSACTION_COMPLETED,
|
||||
});
|
||||
dispatch(
|
||||
doShowSnackBar({
|
||||
message: __(`You sent ${amount} LBC as support, Mahalo!`),
|
||||
linkText: __('History'),
|
||||
linkTarget: __('/wallet'),
|
||||
})
|
||||
);
|
||||
dispatch(doNavigate('/show', { uri }));
|
||||
} else {
|
||||
dispatch({
|
||||
type: ACTIONS.SUPPORT_TRANSACTION_FAILED,
|
||||
data: { error: results.code },
|
||||
});
|
||||
dispatch(doOpenModal(MODALS.TRANSACTION_FAILED));
|
||||
}
|
||||
};
|
||||
|
||||
const errorCallback = error => {
|
||||
dispatch({
|
||||
type: ACTIONS.SUPPORT_TRANSACTION_FAILED,
|
||||
data: { error: error.code },
|
||||
});
|
||||
dispatch(doOpenModal(MODALS.TRANSACTION_FAILED));
|
||||
};
|
||||
|
||||
Lbry.wallet_send({
|
||||
claim_id: claimId,
|
||||
amount,
|
||||
|
|
Loading…
Add table
Reference in a new issue