@qlover/create-app 0.7.5 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +257 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/next-app/.env.template +22 -0
- package/dist/templates/next-app/.prettierignore +58 -0
- package/dist/templates/next-app/README.md +36 -0
- package/dist/templates/next-app/build/generateLocales.ts +25 -0
- package/dist/templates/next-app/config/IOCIdentifier.ts +45 -0
- package/dist/templates/next-app/config/Identifier/common.error.ts +34 -0
- package/dist/templates/next-app/config/Identifier/common.ts +62 -0
- package/dist/templates/next-app/config/Identifier/index.ts +10 -0
- package/dist/templates/next-app/config/Identifier/page.about.ts +181 -0
- package/dist/templates/next-app/config/Identifier/page.executor.ts +272 -0
- package/dist/templates/next-app/config/Identifier/page.home.ts +63 -0
- package/dist/templates/next-app/config/Identifier/page.identifiter.ts +39 -0
- package/dist/templates/next-app/config/Identifier/page.jsonStorage.ts +72 -0
- package/dist/templates/next-app/config/Identifier/page.login.ts +165 -0
- package/dist/templates/next-app/config/Identifier/page.register.ts +147 -0
- package/dist/templates/next-app/config/Identifier/page.request.ts +182 -0
- package/dist/templates/next-app/config/common.ts +34 -0
- package/dist/templates/next-app/config/i18n/PageI18nInterface.ts +51 -0
- package/dist/templates/next-app/config/i18n/i18nConfig.ts +12 -0
- package/dist/templates/next-app/config/i18n/index.ts +3 -0
- package/dist/templates/next-app/config/i18n/loginI18n.ts +42 -0
- package/dist/templates/next-app/config/theme.ts +23 -0
- package/dist/templates/next-app/docs/env.md +94 -0
- package/dist/templates/next-app/eslint.config.mjs +181 -0
- package/dist/templates/next-app/next.config.ts +21 -0
- package/dist/templates/next-app/package.json +58 -0
- package/dist/templates/next-app/plugins/eslint-plugin-testid.mjs +94 -0
- package/dist/templates/next-app/plugins/generateLocalesPlugin.ts +33 -0
- package/dist/templates/next-app/postcss.config.mjs +5 -0
- package/dist/templates/next-app/public/file.svg +1 -0
- package/dist/templates/next-app/public/globe.svg +1 -0
- package/dist/templates/next-app/public/locales/en/common.json +183 -0
- package/dist/templates/next-app/public/locales/zh/common.json +183 -0
- package/dist/templates/next-app/public/next.svg +1 -0
- package/dist/templates/next-app/public/vercel.svg +1 -0
- package/dist/templates/next-app/public/window.svg +1 -0
- package/dist/templates/next-app/src/app/[locale]/favicon.ico +0 -0
- package/dist/templates/next-app/src/app/[locale]/layout.tsx +44 -0
- package/dist/templates/next-app/src/app/[locale]/login/FeatureItem.tsx +13 -0
- package/dist/templates/next-app/src/app/[locale]/login/LoginForm.tsx +115 -0
- package/dist/templates/next-app/src/app/[locale]/login/page.tsx +73 -0
- package/dist/templates/next-app/src/app/[locale]/not-found.tsx +24 -0
- package/dist/templates/next-app/src/app/[locale]/page.tsx +106 -0
- package/dist/templates/next-app/src/base/cases/AppConfig.ts +15 -0
- package/dist/templates/next-app/src/base/cases/InversifyContainer.ts +33 -0
- package/dist/templates/next-app/src/base/port/I18nServiceInterface.ts +25 -0
- package/dist/templates/next-app/src/base/port/UserServiceInterface.ts +11 -0
- package/dist/templates/next-app/src/base/services/I18nService.ts +115 -0
- package/dist/templates/next-app/src/base/services/UserService.ts +23 -0
- package/dist/templates/next-app/src/core/IOC.ts +58 -0
- package/dist/templates/next-app/src/core/IocRegisterImpl.ts +100 -0
- package/dist/templates/next-app/src/core/bootstraps/BootstrapClient.ts +98 -0
- package/dist/templates/next-app/src/core/bootstraps/BootstrapsRegistry.ts +47 -0
- package/dist/templates/next-app/src/core/bootstraps/IocIdentifierTest.ts +26 -0
- package/dist/templates/next-app/src/core/bootstraps/PrintBootstrap.ts +18 -0
- package/dist/templates/next-app/src/core/globals.ts +21 -0
- package/dist/templates/next-app/src/i18n/request.ts +22 -0
- package/dist/templates/next-app/src/i18n/routing.ts +30 -0
- package/dist/templates/next-app/src/middleware.ts +22 -0
- package/dist/templates/next-app/src/server/getServerI18n.ts +26 -0
- package/dist/templates/next-app/src/styles/css/antd-themes/_default.css +239 -0
- package/dist/templates/next-app/src/styles/css/antd-themes/dark.css +178 -0
- package/dist/templates/next-app/src/styles/css/antd-themes/index.css +3 -0
- package/dist/templates/next-app/src/styles/css/antd-themes/no-context.css +34 -0
- package/dist/templates/next-app/src/styles/css/antd-themes/pink.css +204 -0
- package/dist/templates/next-app/src/styles/css/index.css +6 -0
- package/dist/templates/next-app/src/styles/css/page.css +19 -0
- package/dist/templates/next-app/src/styles/css/tailwind.css +5 -0
- package/dist/templates/next-app/src/styles/css/themes/_default.css +29 -0
- package/dist/templates/next-app/src/styles/css/themes/dark.css +29 -0
- package/dist/templates/next-app/src/styles/css/themes/index.css +3 -0
- package/dist/templates/next-app/src/styles/css/themes/pink.css +29 -0
- package/dist/templates/next-app/src/styles/css/zIndex.css +9 -0
- package/dist/templates/next-app/src/uikit/components/BaseHeader.tsx +42 -0
- package/dist/templates/next-app/src/uikit/components/BootstrapsProvider.tsx +25 -0
- package/dist/templates/next-app/src/uikit/components/ComboProvider.tsx +45 -0
- package/dist/templates/next-app/src/uikit/components/LanguageSwitcher.tsx +52 -0
- package/dist/templates/next-app/src/uikit/components/LocaleLink.tsx +51 -0
- package/dist/templates/next-app/src/uikit/components/NextIntlProvider.tsx +21 -0
- package/dist/templates/next-app/src/uikit/components/ThemeSwitcher.tsx +86 -0
- package/dist/templates/next-app/src/uikit/context/IOCContext.ts +6 -0
- package/dist/templates/next-app/src/uikit/hook/useI18nInterface.ts +28 -0
- package/dist/templates/next-app/src/uikit/hook/useIOC.ts +37 -0
- package/dist/templates/next-app/src/uikit/hook/useMountedClient.ts +11 -0
- package/dist/templates/next-app/src/uikit/hook/useStore.ts +15 -0
- package/dist/templates/next-app/tailwind.config.ts +8 -0
- package/dist/templates/next-app/tsconfig.json +36 -0
- package/dist/templates/react-app/.env.template +0 -2
- package/dist/templates/react-app/__tests__/src/base/services/I18nService.test.ts +1 -1
- package/dist/templates/react-app/__tests__/src/core/IOC.test.ts +6 -31
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapsApp.test.ts +1 -1
- package/dist/templates/react-app/config/IOCIdentifier.ts +77 -5
- package/dist/templates/react-app/config/app.router.ts +2 -2
- package/dist/templates/react-app/package.json +4 -7
- package/dist/templates/react-app/public/locales/en/common.json +1 -1
- package/dist/templates/react-app/public/locales/zh/common.json +1 -1
- package/dist/templates/react-app/src/App.tsx +9 -4
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +4 -0
- package/dist/templates/react-app/src/base/cases/DialogHandler.ts +16 -13
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +4 -3
- package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +2 -2
- package/dist/templates/react-app/src/base/cases/RequestLanguages.ts +39 -0
- package/dist/templates/react-app/src/base/cases/RequestState.ts +20 -0
- package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +2 -2
- package/dist/templates/react-app/src/base/cases/RouterLoader.ts +8 -2
- package/dist/templates/react-app/src/base/port/AsyncStateInterface.ts +7 -0
- package/dist/templates/react-app/src/base/port/ExecutorPageBridgeInterface.ts +24 -0
- package/dist/templates/react-app/src/base/port/I18nServiceInterface.ts +10 -0
- package/dist/templates/react-app/src/base/port/JSONStoragePageBridgeInterface.ts +20 -0
- package/dist/templates/react-app/src/base/port/ProcesserExecutorInterface.ts +20 -0
- package/dist/templates/react-app/src/base/port/RequestPageBridgeInterface.ts +23 -0
- package/dist/templates/react-app/src/base/port/RequestStatusInterface.ts +5 -0
- package/dist/templates/react-app/src/base/port/RouteServiceInterface.ts +27 -0
- package/dist/templates/react-app/src/base/port/UserServiceInterface.ts +12 -0
- package/dist/templates/react-app/src/base/services/I18nService.ts +10 -6
- package/dist/templates/react-app/src/base/services/ProcesserExecutor.ts +23 -5
- package/dist/templates/react-app/src/base/services/RouteService.ts +25 -54
- package/dist/templates/react-app/src/base/services/UserService.ts +10 -20
- package/dist/templates/react-app/src/core/IOC.ts +1 -26
- package/dist/templates/react-app/src/core/IocRegisterImpl.ts +125 -0
- package/dist/templates/react-app/src/core/bootstraps/BootstrapApp.ts +4 -6
- package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +8 -6
- package/dist/templates/react-app/src/core/bootstraps/IocIdentifierTest.ts +26 -0
- package/dist/templates/react-app/src/pages/auth/Layout.tsx +2 -2
- package/dist/templates/react-app/src/pages/auth/LoginPage.tsx +5 -6
- package/dist/templates/react-app/src/pages/auth/RegisterPage.tsx +8 -7
- package/dist/templates/react-app/src/pages/base/ExecutorPage.tsx +8 -19
- package/dist/templates/react-app/src/pages/base/{ErrorIdentifierPage.tsx → IdentifierPage.tsx} +1 -1
- package/dist/templates/react-app/src/pages/base/JSONStoragePage.tsx +11 -15
- package/dist/templates/react-app/src/pages/base/Layout.tsx +1 -1
- package/dist/templates/react-app/src/pages/base/RedirectPathname.tsx +2 -2
- package/dist/templates/react-app/src/pages/base/RequestPage.tsx +34 -46
- package/dist/templates/react-app/src/styles/css/antd-themes/_default.css +2 -2
- package/dist/templates/react-app/src/styles/css/antd-themes/dark.css +2 -2
- package/dist/templates/react-app/src/styles/css/antd-themes/pink.css +2 -2
- package/dist/templates/react-app/src/styles/css/index.css +1 -0
- package/dist/templates/react-app/src/styles/css/page.css +8 -0
- package/dist/templates/react-app/src/styles/css/zIndex.css +9 -0
- package/dist/templates/react-app/src/uikit/{controllers/ExecutorController.ts → bridges/ExecutorPageBridge.ts} +13 -36
- package/dist/templates/react-app/src/uikit/bridges/JSONStoragePageBridge.ts +41 -0
- package/dist/templates/react-app/src/uikit/bridges/NavigateBridge.ts +16 -0
- package/dist/templates/react-app/src/uikit/bridges/RequestPageBridge.ts +136 -0
- package/dist/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +3 -2
- package/dist/templates/react-app/src/uikit/components/LogoutButton.tsx +2 -2
- package/dist/templates/react-app/src/uikit/{providers → components}/ProcessExecutorProvider.tsx +4 -4
- package/dist/templates/react-app/src/uikit/components/RouterRenderComponent.tsx +1 -1
- package/dist/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +3 -5
- package/dist/templates/react-app/src/uikit/{providers → components}/UserAuthProvider.tsx +3 -3
- package/dist/templates/react-app/src/uikit/hooks/useI18nGuard.ts +5 -2
- package/dist/templates/react-app/src/uikit/hooks/{userRouterService.ts → useNavigateBridge.ts} +3 -3
- package/dist/templates/react-app/src/uikit/hooks/useStore.ts +5 -2
- package/dist/templates/react-app/tsconfig.json +1 -4
- package/package.json +1 -1
- package/dist/templates/react-app/src/base/port/InteractionHubInterface.ts +0 -94
- package/dist/templates/react-app/src/base/port/UIDependenciesInterface.ts +0 -37
- package/dist/templates/react-app/src/core/registers/IocRegisterImpl.ts +0 -25
- package/dist/templates/react-app/src/core/registers/RegisterCommon.ts +0 -74
- package/dist/templates/react-app/src/core/registers/RegisterControllers.ts +0 -26
- package/dist/templates/react-app/src/core/registers/RegisterGlobals.ts +0 -30
- package/dist/templates/react-app/src/uikit/controllers/JSONStorageController.ts +0 -49
- package/dist/templates/react-app/src/uikit/controllers/RequestController.ts +0 -158
- /package/dist/templates/react-app/src/uikit/{providers → components}/BaseRouteProvider.tsx +0 -0
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FetchAbortPlugin,
|
|
3
|
-
type SyncStorageInterface
|
|
4
|
-
} from '@qlover/fe-corekit';
|
|
5
|
-
import { Logger } from '@qlover/logger';
|
|
6
|
-
import {
|
|
7
|
-
RequestCommonPlugin,
|
|
8
|
-
ApiMockPlugin,
|
|
9
|
-
ApiCatchPlugin,
|
|
10
|
-
ThemeService,
|
|
11
|
-
TokenStorage
|
|
12
|
-
} from '@qlover/corekit-bridge';
|
|
13
|
-
import mockDataJson from '@config/feapi.mock.json';
|
|
14
|
-
import { RequestStatusCatcher } from '@/base/cases/RequestStatusCatcher';
|
|
15
|
-
import { themeConfig } from '@config/theme';
|
|
16
|
-
import { localStorage, logger } from '../globals';
|
|
17
|
-
import { I18nService } from '@/base/services/I18nService';
|
|
18
|
-
import { RouteService } from '@/base/services/RouteService';
|
|
19
|
-
import { baseRoutes, baseNoLocaleRoutes } from '@config/app.router';
|
|
20
|
-
import { useLocaleRoutes } from '@config/common';
|
|
21
|
-
import { UserService } from '@/base/services/UserService';
|
|
22
|
-
import { IOCRegister } from '../IOC';
|
|
23
|
-
import { IOCIdentifier } from '@config/IOCIdentifier';
|
|
24
|
-
|
|
25
|
-
export const RegisterCommon: IOCRegister = {
|
|
26
|
-
register(container, _, options): void {
|
|
27
|
-
const AppConfig = container.get(IOCIdentifier.AppConfig);
|
|
28
|
-
|
|
29
|
-
const feApiToken = new TokenStorage(AppConfig.userTokenStorageKey, {
|
|
30
|
-
storage: container.get(IOCIdentifier.LocalStorageEncrypt)
|
|
31
|
-
});
|
|
32
|
-
const feApiAbort = new FetchAbortPlugin();
|
|
33
|
-
const feApiRequestCommonPlugin = new RequestCommonPlugin({
|
|
34
|
-
tokenPrefix: AppConfig.openAiTokenPrefix,
|
|
35
|
-
requiredToken: true,
|
|
36
|
-
token: () => container.get(UserService).getToken()
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
container.bind(FetchAbortPlugin, feApiAbort);
|
|
40
|
-
|
|
41
|
-
container.bind(IOCIdentifier.FeApiToken, feApiToken);
|
|
42
|
-
container.bind(IOCIdentifier.FeApiCommonPlugin, feApiRequestCommonPlugin);
|
|
43
|
-
container.bind(
|
|
44
|
-
IOCIdentifier.ApiMockPlugin,
|
|
45
|
-
new ApiMockPlugin(mockDataJson, container.get(Logger))
|
|
46
|
-
);
|
|
47
|
-
container.bind(
|
|
48
|
-
IOCIdentifier.ApiCatchPlugin,
|
|
49
|
-
new ApiCatchPlugin(
|
|
50
|
-
container.get(Logger),
|
|
51
|
-
container.get(RequestStatusCatcher)
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
container.bind(
|
|
56
|
-
ThemeService,
|
|
57
|
-
new ThemeService({
|
|
58
|
-
...themeConfig,
|
|
59
|
-
storage: localStorage as SyncStorageInterface<string, string>
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
container.bind(
|
|
64
|
-
RouteService,
|
|
65
|
-
new RouteService({
|
|
66
|
-
routes: useLocaleRoutes ? baseRoutes : baseNoLocaleRoutes,
|
|
67
|
-
logger,
|
|
68
|
-
hasLocalRoutes: useLocaleRoutes
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
container.bind(I18nService, new I18nService(options!.pathname));
|
|
73
|
-
}
|
|
74
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { localStorage } from '../globals';
|
|
2
|
-
import { JSONStorageController } from '@/uikit/controllers/JSONStorageController';
|
|
3
|
-
import { ProcesserExecutor } from '@/base/services/ProcesserExecutor';
|
|
4
|
-
import { UserService } from '@/base/services/UserService';
|
|
5
|
-
import { I18nKeyErrorPlugin } from '@/base/cases/I18nKeyErrorPlugin';
|
|
6
|
-
import { IOCContainer, IOCRegister } from '../IOC';
|
|
7
|
-
import { IOCManagerInterface } from '@qlover/corekit-bridge';
|
|
8
|
-
|
|
9
|
-
export class RegisterControllers implements IOCRegister {
|
|
10
|
-
/**
|
|
11
|
-
* @override
|
|
12
|
-
*/
|
|
13
|
-
register(
|
|
14
|
-
container: IOCContainer,
|
|
15
|
-
_: IOCManagerInterface<IOCContainer>
|
|
16
|
-
): void {
|
|
17
|
-
const jsonStorageController = new JSONStorageController(localStorage);
|
|
18
|
-
|
|
19
|
-
container.bind(JSONStorageController, jsonStorageController);
|
|
20
|
-
|
|
21
|
-
container
|
|
22
|
-
.get(ProcesserExecutor)
|
|
23
|
-
.use(container.get(I18nKeyErrorPlugin))
|
|
24
|
-
.use(container.get(UserService));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { JSONSerializer } from '@qlover/fe-corekit';
|
|
2
|
-
import {
|
|
3
|
-
cookieStorage,
|
|
4
|
-
dialogHandler,
|
|
5
|
-
JSON,
|
|
6
|
-
localStorage,
|
|
7
|
-
localStorageEncrypt,
|
|
8
|
-
logger
|
|
9
|
-
} from '../globals';
|
|
10
|
-
import { IOCRegister } from '@/core/IOC';
|
|
11
|
-
import { Logger } from '@qlover/logger';
|
|
12
|
-
import { IOCIdentifier } from '@config/IOCIdentifier';
|
|
13
|
-
|
|
14
|
-
export const RegisterGlobals: IOCRegister = {
|
|
15
|
-
register(container, _, options): void {
|
|
16
|
-
// inject AppConfig to IOC
|
|
17
|
-
container.bind(IOCIdentifier.AppConfig, options!.appConfig);
|
|
18
|
-
container.bind(IOCIdentifier.DialogHandler, dialogHandler);
|
|
19
|
-
|
|
20
|
-
container.bind(JSONSerializer, JSON);
|
|
21
|
-
container.bind(IOCIdentifier.JSON, JSON);
|
|
22
|
-
|
|
23
|
-
container.bind(Logger, logger);
|
|
24
|
-
container.bind(IOCIdentifier.Logger, logger);
|
|
25
|
-
|
|
26
|
-
container.bind(IOCIdentifier.LocalStorage, localStorage);
|
|
27
|
-
container.bind(IOCIdentifier.LocalStorageEncrypt, localStorageEncrypt);
|
|
28
|
-
container.bind(IOCIdentifier.CookieStorage, cookieStorage);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
StoreInterface,
|
|
3
|
-
type StoreStateInterface
|
|
4
|
-
} from '@qlover/corekit-bridge';
|
|
5
|
-
import { SyncStorageInterface } from '@qlover/fe-corekit';
|
|
6
|
-
import random from 'lodash/random';
|
|
7
|
-
|
|
8
|
-
interface JSONStoragePageState extends StoreStateInterface {
|
|
9
|
-
testKey1?: number;
|
|
10
|
-
testKey2?: number;
|
|
11
|
-
expireTime: number;
|
|
12
|
-
requestTimeout: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class JSONStorageController extends StoreInterface<JSONStoragePageState> {
|
|
16
|
-
selector = {
|
|
17
|
-
requestTimeout: (state: JSONStoragePageState) => state.requestTimeout
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
constructor(private storage: SyncStorageInterface<string, unknown>) {
|
|
21
|
-
super(() => ({
|
|
22
|
-
testKey1: storage.getItem('testKey1') ?? 0,
|
|
23
|
-
testKey2: storage.getItem('testKey2') ?? 0,
|
|
24
|
-
expireTime: 5000,
|
|
25
|
-
requestTimeout: storage.getItem('requestTimeout') ?? 5000
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
changeRandomTestKey1 = (): void => {
|
|
30
|
-
const value = random(100, 9000);
|
|
31
|
-
this.storage.setItem('testKey1', value);
|
|
32
|
-
this.emit({ ...this.state, testKey1: value });
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
onChangeRandomTestKey2 = (): void => {
|
|
36
|
-
const value = random(100, 9000);
|
|
37
|
-
this.storage.setItem('testKey2', value, Date.now() + this.state.expireTime);
|
|
38
|
-
this.emit({ ...this.state, testKey2: value });
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
changeExpireTime = (expireTime: number): void => {
|
|
42
|
-
this.emit({ ...this.state, expireTime });
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
changeRequestTimeout = (requestTimeout: number): void => {
|
|
46
|
-
this.storage.setItem('requestTimeout', requestTimeout);
|
|
47
|
-
this.emit({ ...this.state, requestTimeout });
|
|
48
|
-
};
|
|
49
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { inject, injectable } from 'inversify';
|
|
2
|
-
import { FeApi } from '@/base/apis/feApi/FeApi';
|
|
3
|
-
import { logger } from '@/core/globals';
|
|
4
|
-
import { UserApi } from '@/base/apis/userApi/UserApi';
|
|
5
|
-
import { aiHello } from '@/base/apis/AiApi';
|
|
6
|
-
import { StoreInterface } from '@qlover/corekit-bridge';
|
|
7
|
-
|
|
8
|
-
function createDefaultState() {
|
|
9
|
-
return {
|
|
10
|
-
helloState: {
|
|
11
|
-
loading: false,
|
|
12
|
-
result: null as unknown,
|
|
13
|
-
error: null as unknown
|
|
14
|
-
},
|
|
15
|
-
ipInfoState: {
|
|
16
|
-
loading: false,
|
|
17
|
-
result: null as unknown,
|
|
18
|
-
error: null as unknown
|
|
19
|
-
},
|
|
20
|
-
randomUserState: {
|
|
21
|
-
loading: false,
|
|
22
|
-
result: null as unknown,
|
|
23
|
-
error: null as unknown
|
|
24
|
-
},
|
|
25
|
-
abortState: {
|
|
26
|
-
loading: false,
|
|
27
|
-
result: null as unknown,
|
|
28
|
-
error: null as unknown
|
|
29
|
-
},
|
|
30
|
-
apiCatchResultState: {
|
|
31
|
-
loading: false,
|
|
32
|
-
result: null as unknown,
|
|
33
|
-
error: null as unknown
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type RequestControllerState = ReturnType<typeof createDefaultState>;
|
|
39
|
-
|
|
40
|
-
@injectable()
|
|
41
|
-
export class RequestController extends StoreInterface<RequestControllerState> {
|
|
42
|
-
constructor(
|
|
43
|
-
@inject(FeApi) private readonly feApi: FeApi,
|
|
44
|
-
@inject(UserApi) private readonly userApi: UserApi
|
|
45
|
-
) {
|
|
46
|
-
super(createDefaultState);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setState(state: Partial<RequestControllerState>): void {
|
|
50
|
-
this.emit({ ...this.state, ...state });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
onHello = async () => {
|
|
54
|
-
if (this.state.helloState.loading) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.setState({ helloState: { loading: true, result: '', error: null } });
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const result = await aiHello({
|
|
62
|
-
messages: [{ role: 'user', content: 'Hello, world!' }]
|
|
63
|
-
});
|
|
64
|
-
this.setState({ helloState: { loading: false, result, error: null } });
|
|
65
|
-
} catch (error) {
|
|
66
|
-
logger.error(error);
|
|
67
|
-
this.setState({ helloState: { loading: false, result: null, error } });
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
onIpInfo = async () => {
|
|
72
|
-
if (this.state.ipInfoState.loading) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.setState({
|
|
77
|
-
ipInfoState: { loading: true, result: null, error: null }
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const result = await this.feApi.getIpInfo();
|
|
82
|
-
this.setState({ ipInfoState: { loading: false, result, error: null } });
|
|
83
|
-
} catch (error) {
|
|
84
|
-
logger.error(error);
|
|
85
|
-
this.setState({ ipInfoState: { loading: false, result: null, error } });
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
onRandomUser = async () => {
|
|
90
|
-
if (this.state.randomUserState.loading) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.setState({
|
|
95
|
-
randomUserState: { loading: true, result: null, error: null }
|
|
96
|
-
});
|
|
97
|
-
try {
|
|
98
|
-
const result = await this.userApi.getRandomUser();
|
|
99
|
-
this.setState({
|
|
100
|
-
randomUserState: { loading: false, result, error: null }
|
|
101
|
-
});
|
|
102
|
-
} catch (error) {
|
|
103
|
-
logger.error(error);
|
|
104
|
-
this.setState({
|
|
105
|
-
randomUserState: { loading: false, result: null, error }
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
onTriggerApiCatchResult = async () => {
|
|
111
|
-
if (this.state.apiCatchResultState.loading) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.setState({
|
|
116
|
-
apiCatchResultState: { loading: true, result: null, error: null }
|
|
117
|
-
});
|
|
118
|
-
try {
|
|
119
|
-
const result = await this.userApi.testApiCatchResult();
|
|
120
|
-
this.setState({
|
|
121
|
-
apiCatchResultState: {
|
|
122
|
-
loading: false,
|
|
123
|
-
result,
|
|
124
|
-
error: result.apiCatchResult
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
} catch (error) {
|
|
128
|
-
this.setState({
|
|
129
|
-
apiCatchResultState: { loading: false, result: null, error }
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
onTriggerAbortRequest = async () => {
|
|
135
|
-
if (this.state.abortState.loading) {
|
|
136
|
-
this.stopAbortRequest();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
this.setState({ abortState: { loading: true, result: null, error: null } });
|
|
141
|
-
try {
|
|
142
|
-
await this.userApi.request({
|
|
143
|
-
method: 'GET',
|
|
144
|
-
url: 'https://api.example.com/users',
|
|
145
|
-
disabledMock: true,
|
|
146
|
-
requestId: 'onTriggerAbortRequest'
|
|
147
|
-
});
|
|
148
|
-
} catch (error) {
|
|
149
|
-
this.setState({ abortState: { loading: false, result: null, error } });
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
stopAbortRequest = async () => {
|
|
154
|
-
this.userApi.stop({
|
|
155
|
-
requestId: 'onTriggerAbortRequest'
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
}
|
|
File without changes
|