1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00

error handling

This commit is contained in:
Andrew Simachev 2023-08-24 10:09:13 +02:00
parent 3b98dd5d76
commit cd0cba3e00
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
5 changed files with 38 additions and 17 deletions

View file

@ -41,10 +41,10 @@
const client = chrome.runtime.connectNative('com.anytype.desktop');
client.onMessage.addListener((msg) => {
console.log('Received', msg);
console.log('[Native]', msg);
if (msg.error) {
console.error(msg.error);
callBack({ type: msg.type, error: msg.error });
return;
};
@ -56,14 +56,14 @@
break;
};
callBack({ type: 'NMHGetOpenPorts', port });
callBack({ type: msg.type, port });
break;
};
};
});
client.onDisconnect.addListener(() => {
console.log('Disconnected');
console.log('[Native] Disconnected');
});
client.postMessage({ type: 'NMHGetOpenPorts' });

View file

@ -117,11 +117,15 @@ class Iframe extends React.Component {
return false;
};
sendResponse({});
sendResponse({ type: msg.type, ref: 'iframe' });
return true;
});
Util.sendMessage({ type: 'initNative' }, (response) => {
if (response.error) {
return;
};
authStore.tokenSet('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZWVkIjoiWGhYdXlEUFYifQ.pnNEnTksl5pFacCTv5aFJd-Ur8X2cRfmIXcT30w02ro');
dispatcher.init(`http://127.0.0.1:${response.port}`);

View file

@ -123,16 +123,9 @@ class Popup extends React.Component {
return false;
};
sendResponse({});
sendResponse({ type: msg.type, ref: 'popup' });
return true;
});
Util.sendMessage({ type: 'initNative' }, (response) => {
authStore.tokenSet('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZWVkIjoiWGhYdXlEUFYifQ.pnNEnTksl5pFacCTv5aFJd-Ur8X2cRfmIXcT30w02ro');
dispatcher.init(`http://127.0.0.1:${response.port}`);
C.AppGetVersion();
});
};
};

View file

@ -1,15 +1,22 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import { Label, Button } from 'Component';
import { I, UtilCommon, UtilData } from 'Lib';
import { Label, Button, Error } from 'Component';
import { I, UtilCommon, UtilData, dispatcher } from 'Lib';
import { authStore } from 'Store';
import Url from 'json/url.json';
import Util from '../lib/util';
interface State {
error: string;
};
const Index = observer(class Index extends React.Component<I.PageComponent, State> {
state = {
error: '',
};
constructor (props: I.PageComponent) {
super(props);
@ -18,6 +25,8 @@ const Index = observer(class Index extends React.Component<I.PageComponent, Stat
};
render () {
const { error } = this.state;
return (
<div className="page pageIndex">
<Label text="To save in Anytype you need to Pair with the app" />
@ -26,13 +35,27 @@ const Index = observer(class Index extends React.Component<I.PageComponent, Stat
<Button color="pink" className="c32" text="Pair with app" onClick={this.onLogin} />
<Button color="blank" className="c32" text="Download app" onClick={this.onDownload} />
</div>
<Error text={error} />
</div>
);
};
onLogin () {
UtilData.createsSubscriptions(() => {
UtilCommon.route('/create', {});
Util.sendMessage({ type: 'initNative' }, (response) => {
console.log('Response', response);
if (response.error) {
this.setState({ error: response.error });
return;
};
authStore.tokenSet('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZWVkIjoiWGhYdXlEUFYifQ.pnNEnTksl5pFacCTv5aFJd-Ur8X2cRfmIXcT30w02ro');
dispatcher.init(`http://127.0.0.1:${response.port}`);
UtilData.createsSubscriptions(() => {
UtilCommon.route('/create', {});
});
});
};

View file

@ -15,6 +15,7 @@ html.anytypeWebclipper-popup { width: 268px; }
.textarea { padding: 10px; resize: none; height: 68px; display: block; }
.buttons { display: flex; flex-direction: column; justify-content: center; gap: 8px 0px; margin: 16px 0px 0px 0px; }
.loaderWrapper { position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; background: $colorBgLoader; z-index: 10; }
.error { @include text-small; margin: 1em 0px 0px 0px; }
.isFocused { border-color: $colorIce !important; box-shadow: 0px 0px 0px 1px $colorIce; }