1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-07 21:47:02 +09:00

JS-6113: add integration

This commit is contained in:
Andrew Simachev 2025-01-07 16:29:57 +01:00
parent abd0d51773
commit 1b415ced7b
No known key found for this signature in database
GPG key ID: 1DFE44B21443F0EF
11 changed files with 122 additions and 24 deletions

View file

@ -62,6 +62,13 @@ class Util {
};
C.AccountSelect(message.accountId, '', 0, '', (message: any) => {
if (message.error.code) {
if (onError) {
onError(message.error);
};
return;
};
S.Auth.accountSet(message.account);
S.Common.configSet(message.account.config, false);
S.Common.showVaultSet(false);

View file

@ -13,6 +13,7 @@ export default {
LIMIT_OF_ROWS_OR_RELATIONS_EXCEEDED: 7,
FILE_LOAD_ERROR: 8,
INSUFFICIENT_PERMISSIONS: 9,
ACCOUNT_STORE_NOT_MIGRATED: 113,
Import: {
INTERNAL_ERROR: 3,

View file

@ -276,3 +276,7 @@ html.bodyAuthDeleted {
.button { width: 320px; }
.remove { color: var(--color-red) !important; }
}
.pageAuthMigrate {
.frame { width: 480px; }
}

View file

@ -9,9 +9,9 @@ const FooterMainObject = observer(forwardRef<{}, I.FooterComponent>((props, ref)
const { onHelp } = props;
const { show } = S.Progress;
const theme = S.Common.getThemeClass();
const current = S.Progress.getCurrent();
const total = S.Progress.getTotal();
const percent = Math.round((current / total) * 100);
const skipType = [ I.ProgressType.Migrate ];
const list = S.Progress.getList(it => !skipType.includes(it.type));
const percent = S.Progress.getPercent(list);
const color = J.Theme[theme].progress;
const onTooltipShow = (e: any, text: string, caption?: string) => {
@ -23,7 +23,7 @@ const FooterMainObject = observer(forwardRef<{}, I.FooterComponent>((props, ref)
return (
<div className="buttons">
{total ? (
{percent ? (
<div
id="button-progress"
className="iconWrap"

View file

@ -99,6 +99,11 @@ const PageAuthLogin = observer(forwardRef<{}, I.PageComponent>((props, ref: any)
return;
};
if (code == J.Error.Code.ACCOUNT_STORE_NOT_MIGRATED) {
U.Router.go('/auth/migrate', {});
return;
};
setError(text);
phraseRef.current?.setError(true);
submitRef.current?.setLoading(false);

View file

@ -0,0 +1,68 @@
import React, { forwardRef, useEffect, useState } from 'react';
import { observer } from 'mobx-react';
import { Frame, Error, ProgressBar } from 'Component';
import { I, C, S, U, Animation, Storage } from 'Lib';
const PageAuthMigrate = observer(forwardRef<{}, I.PageComponent>((props, ref) => {
const { dataPath } = S.Common;
const accountId = Storage.get('accountId');
const spaceId = Storage.get('spaceId');
const [ error, setError ] = useState('');
const { networkConfig } = S.Auth;
const { mode, path } = networkConfig;
const types = [ I.ProgressType.Migrate ];
const list = S.Progress.getList(it => types.includes(it.type));
const progress = list.length ? list[0] : null;
const segments = [];
if (progress) {
segments.push({ name: 'migrate', caption: 'Migrate', percent: progress.current / progress.total, isActive: true });
};
useEffect(() => {
S.Auth.clearAll();
Animation.to(() => {
C.AccountMigrate(accountId, dataPath, (message: any) => {
if (message.error.code) {
setError(message.error.description);
return;
};
C.AccountSelect(accountId, dataPath, mode, path, (message: any) => {
const { account } = message;
if (!account) {
return;
};
S.Auth.accountSet(account);
S.Common.configSet(account.config, false);
const routeParam = { replace: true };
if (spaceId) {
U.Router.switchSpace(spaceId, '', false, routeParam);
} else {
U.Data.onAuthWithoutSpace(routeParam);
};
U.Data.onInfo(account.info);
U.Data.onAuthOnce(false);
});
});
});
}, []);
return (
<Frame>
<Error text={error} />
<ProgressBar segments={segments} />
</Frame>
);
}));
export default PageAuthMigrate;

View file

@ -85,6 +85,11 @@ const PageAuthSetup = observer(forwardRef<{}, I.PageComponent>((props, ref) => {
return false;
};
if (error.code == J.Error.Code.ACCOUNT_STORE_NOT_MIGRATED) {
U.Router.go('/auth/migrate', {});
return;
};
setError(error);
return U.Common.checkErrorCommon(error.code);
};

View file

@ -11,6 +11,7 @@ import PageAuthPinCheck from './auth/pinCheck';
import PageAuthSetup from './auth/setup';
import PageAuthOnboard from './auth/onboard';
import PageAuthDeleted from './auth/deleted';
import PageAuthMigrate from './auth/migrate';
import PageMainBlank from './main/blank';
import PageMainEmpty from './main/empty';
@ -41,6 +42,7 @@ const Components = {
'auth/setup': PageAuthSetup,
'auth/onboard': PageAuthOnboard,
'auth/deleted': PageAuthDeleted,
'auth/migrate': PageAuthMigrate,
'main/blank': PageMainBlank,
'main/empty': PageMainEmpty,

View file

@ -7,8 +7,9 @@ import { I, S, U, C, J, Storage, keyboard, translate } from 'Lib';
const Progress: FC = observer(() => {
const { show } = S.Progress;
const list = S.Progress.getList();
const percent = S.Progress.getPercent();
const skipType = [ I.ProgressType.Migrate ];
const list = S.Progress.getList(it => !skipType.includes(it.type));
const percent = S.Progress.getPercent(list);
const nodeRef = useRef(null);
const innerRef = useRef(null);
const dx = useRef(0);

View file

@ -195,6 +195,15 @@ export const AccountSelect = (id: string, path: string, mode: I.NetworkMode, net
dispatcher.request(AccountSelect.name, request, callBack);
};
export const AccountMigrate = (id: string, path: string, callBack?: (message: any) => void) => {
const request = new Rpc.Account.Migrate.Request();
request.setId(id);
request.setRootpath(path);
dispatcher.request(AccountMigrate.name, request, callBack);
};
export const AccountStop = (removeData: boolean, callBack?: (message: any) => void) => {
const request = new Rpc.Account.Stop.Request();

View file

@ -49,32 +49,28 @@ class ProgressStore {
this.showValue = Boolean(v);
};
getList () {
getList (filter?: (it: I.Progress) => boolean) {
const { space } = S.Common;
const skip = [ I.ProgressState.Done, I.ProgressState.Canceled ];
const skipState = [ I.ProgressState.Done, I.ProgressState.Canceled ];
return this.list.filter(it => (!it.spaceId || (it.spaceId == space)) && !skip.includes(it.state));
return this.list.filter(it => {
let ret = true;
if (filter) {
ret = filter(it);
};
return ret && (!it.spaceId || (it.spaceId == space)) && !skipState.includes(it.state);
});
};
getItem (id: string): I.Progress {
return this.getList().find(it => it.id == id);
};
getField (field: string): number {
return this.getList().reduce((acc, it) => acc + (Number(it[field]) || 0), 0);
};
getCurrent (): number {
return this.getField('current');
};
getTotal (): number {
return this.getField('total');
};
getPercent (): number {
const current = this.getCurrent();
const total = this.getTotal();
getPercent (list: I.Progress[]): number {
const current = list.reduce((acc, it) => acc + (Number(it.current) || 0), 0);
const total = list.reduce((acc, it) => acc + (Number(it.total) || 0), 0);
return total > 0 ? Math.min(100, Math.ceil(current / total * 100)) : 0;
};