Skip to content

Commit

Permalink
chore: fix nativate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xwchris committed Oct 27, 2022
1 parent aa84efe commit a6fe43a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
24 changes: 12 additions & 12 deletions packages/mona-clients/mona-client-web/src/apis/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const webChooseImage: OriginApis['chooseImage'] = (options = {}) => {
input.dispatchEvent(event);

input.onchange = () => {
options?.success?.(input.files as unknown as ChooseImageSuccessCallbackArgs);
options?.success?.((input.files as unknown) as ChooseImageSuccessCallbackArgs);
};
} catch (e) {
options.fail?.({ errMsg: 'chooseImage:fail' });
Expand Down Expand Up @@ -337,7 +337,7 @@ export const webGetLocation: OriginApis['getLocation'] = options => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
position => {
options?.success?.(position.coords as unknown as GetLocationSuccessCallbackArgs);
options?.success?.((position.coords as unknown) as GetLocationSuccessCallbackArgs);
},
err => {
options?.fail?.({
Expand All @@ -357,7 +357,7 @@ export const webGetNetworkType: OriginApis['getNetworkType'] = (options = {}) =>
if (navigator.connection) {
// @ts-ignore ignore
errMsg = navigator.connection.effectiveType;
options.success?.({ networkType: errMsg as unknown as NetworkType });
options.success?.({ networkType: (errMsg as unknown) as NetworkType });
} else {
errMsg = 'getNetworkType call faild';
options.fail?.({ errMsg });
Expand Down Expand Up @@ -399,12 +399,10 @@ export const webNavigateTo: OriginApis['navigateTo'] = options => {
let errMsg: string;
try {
errMsg = 'navigateTo:ok';
const monaHistory = window.__mona_history || history;
if (options.url.startsWith('..')) {
monaHistory.push(formatPath(options.url, monaHistory.location.pathname));
} else {
monaHistory.push(formatPath(options.url, monaHistory.location.pathname));
}
const monaHistory = window.__mona_history;
const currentPath = monaHistory.location.pathname;
const targetPath = formatPath(options.url, currentPath);
monaHistory.push(targetPath);
options.success?.({ errMsg });
} catch (err) {
errMsg = `navigateTo:fail${err}`;
Expand All @@ -417,8 +415,10 @@ export const webRedirectTo: OriginApis['redirectTo'] = options => {
let errMsg: string;
try {
errMsg = 'redirectTo:ok';
const monaHistory = window.__mona_history || history;
monaHistory.replace(formatPath(options.url, monaHistory.location.pathname));
const monaHistory = window.__mona_history;
const currentPath = monaHistory.location.pathname;
const targetPath = formatPath(options.url, currentPath);
monaHistory.replace(targetPath);
options.success?.({ errMsg });
} catch (err) {
errMsg = `redirectTo:fail${err}`;
Expand All @@ -435,7 +435,7 @@ export const webSwitchTab: OriginApis['switchTab'] = ({ url, success, fail, comp
export const webNavigateBack: OriginApis['navigateBack'] = (options = {}) => {
let errMsg: string;
try {
const monaHistory = window.__mona_history || history;
const monaHistory = window.__mona_history;
errMsg = 'navigateBack:ok';
const delta = options.delta || 1;
monaHistory.go(-delta);
Expand Down
5 changes: 1 addition & 4 deletions packages/mona-clients/mona-client-web/src/createWebApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ export const HistorySetWrapper: React.FC = ({ children }) => {
const history = useHistory();

// set global history to implement navigateTo and redirectTo api
useEffect(() => {
// @ts-ignore
window.__mona_history = history;
}, [history]);
window.__mona_history = history;

return <>{children}</>;
};
Expand Down

0 comments on commit a6fe43a

Please sign in to comment.