devextreme-cli 1.3.2 → 1.3.3
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/index.js +4 -2
- package/package.json +8 -3
- package/src/application.js +17 -17
- package/src/applications/application.angular.js +38 -21
- package/src/applications/application.react.js +81 -37
- package/src/applications/application.vue.js +70 -33
- package/src/commands.json +3 -0
- package/src/templates/react/application/src/{App.js → App.tsx} +0 -0
- package/src/templates/react/application/src/{Content.js → Content.tsx} +11 -9
- package/src/templates/react/application/src/UnauthenticatedContent.tsx +46 -0
- package/src/templates/react/application/src/api/{auth.js → auth.tsx} +4 -4
- package/src/templates/react/application/src/{app-info.js → app-info.tsx} +0 -0
- package/src/templates/react/application/src/{app-navigation.js → app-navigation.tsx} +0 -0
- package/src/templates/react/application/src/app-routes.tsx +24 -0
- package/src/templates/react/application/src/components/change-password-form/{change-password-form.js → ChangePasswordForm.tsx} +6 -6
- package/src/templates/react/application/src/components/create-account-form/{create-account-form.scss → CreateAccountForm.scss} +0 -0
- package/src/templates/react/application/src/components/create-account-form/{create-account-form.js → CreateAccountForm.tsx} +7 -7
- package/src/templates/react/application/src/components/footer/{footer.scss → Footer.scss} +0 -0
- package/src/templates/react/application/src/components/footer/{footer.js → Footer.tsx} +1 -1
- package/src/templates/react/application/src/components/header/{header.scss → Header.scss} +0 -0
- package/src/templates/react/application/src/components/header/{header.js → Header.tsx} +4 -3
- package/src/templates/react/application/src/components/index.tsx +7 -0
- package/src/templates/react/application/src/components/login-form/{login-form.scss → LoginForm.scss} +0 -0
- package/src/templates/react/application/src/components/login-form/{login-form.js → LoginForm.tsx} +6 -6
- package/src/templates/react/application/src/components/reset-password-form/{reset-password-form.scss → ResetPasswordForm.scss} +0 -0
- package/src/templates/react/application/src/components/reset-password-form/{reset-password-form.js → ResetPasswordForm.tsx} +7 -7
- package/src/templates/react/application/src/components/side-navigation-menu/{side-navigation-menu.scss → SideNavigationMenu.scss} +0 -0
- package/src/templates/react/application/src/components/side-navigation-menu/{side-navigation-menu.js → SideNavigationMenu.tsx} +8 -10
- package/src/templates/react/application/src/components/user-panel/{user-panel.scss → UserPanel.scss} +0 -0
- package/src/templates/react/application/src/components/user-panel/{user-panel.js → UserPanel.tsx} +8 -8
- package/src/templates/react/application/src/contexts/{auth.js → auth.tsx} +6 -5
- package/src/templates/react/application/src/contexts/navigation.tsx +35 -0
- package/src/templates/react/application/src/layouts/{index.js → index.tsx} +0 -0
- package/src/templates/react/application/src/layouts/side-nav-inner-toolbar/{side-nav-inner-toolbar.js → side-nav-inner-toolbar.tsx} +12 -9
- package/src/templates/react/application/src/layouts/side-nav-outer-toolbar/{side-nav-outer-toolbar.js → side-nav-outer-toolbar.tsx} +11 -10
- package/src/templates/react/application/src/layouts/single-card/{single-card.js → single-card.tsx} +2 -1
- package/src/templates/react/application/src/{polyfills.js → polyfills.tsx} +0 -0
- package/src/templates/react/application/src/types.tsx +53 -0
- package/src/templates/react/application/src/utils/{default-user.js → default-user.tsx} +0 -0
- package/src/templates/react/application/src/utils/{media-query.js → media-query.tsx} +4 -3
- package/src/templates/react/application/src/utils/{patches.js → patches.tsx} +1 -1
- package/src/templates/react/page/{page.js → page.tsx} +0 -0
- package/src/templates/react/sample-pages/home/{home.js → home.tsx} +0 -0
- package/src/templates/react/sample-pages/{index.js → index.tsx} +0 -0
- package/src/templates/react/sample-pages/profile/{profile.js → profile.tsx} +0 -0
- package/src/templates/react/sample-pages/tasks/{tasks.js → tasks.tsx} +1 -1
- package/src/templates/vue-v2/application/devextreme.json +2 -1
- package/src/templates/vue-v3/application/devextreme.json +2 -1
- package/src/utility/prompts/layout.js +9 -21
- package/src/utility/prompts/prompts.js +24 -8
- package/src/utility/prompts/typescript.js +18 -0
- package/src/utility/prompts/vue-version.js +9 -21
- package/src/utility/template-creator.js +11 -6
- package/src/utility/typescript-extension.js +24 -0
- package/src/templates/react/application/src/UnauthenticatedContent.js +0 -35
- package/src/templates/react/application/src/app-routes.js +0 -24
- package/src/templates/react/application/src/components/index.js +0 -7
- package/src/templates/react/application/src/contexts/navigation.js +0 -34
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import dxTreeView, { ItemClickEvent } from 'devextreme/ui/tree_view';
|
|
2
|
+
import { ClickEvent } from 'devextreme/ui/button';
|
|
3
|
+
import { EventInfo } from 'devextreme/events';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
export interface HeaderProps {
|
|
7
|
+
menuToggleEnabled: boolean;
|
|
8
|
+
title?: string;
|
|
9
|
+
toggleMenu: (e: ClickEvent) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SideNavigationMenuProps {
|
|
13
|
+
selectedItemChanged: (e: ItemClickEvent) => void;
|
|
14
|
+
openMenu: (e: React.PointerEvent) => void;
|
|
15
|
+
compactMode: boolean;
|
|
16
|
+
onMenuReady: (e: EventInfo<dxTreeView>) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface UserPanelProps {
|
|
20
|
+
menuMode: 'context' | 'list';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface User {
|
|
24
|
+
email: string;
|
|
25
|
+
avatarUrl: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type AuthContextType = {
|
|
29
|
+
user?: User;
|
|
30
|
+
signIn: (email: string, password: string) => Promise<{isOk: boolean, data?: User, message?: string}>;
|
|
31
|
+
signOut: () => void;
|
|
32
|
+
loading: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SideNavToolbarProps {
|
|
36
|
+
title: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SingleCardProps {
|
|
40
|
+
title?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type Handle = () => void;
|
|
45
|
+
|
|
46
|
+
interface NavigationData {
|
|
47
|
+
currentPath: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type NavigationContextType = {
|
|
51
|
+
setNavigationData?: ({ currentPath }: NavigationData) => void;
|
|
52
|
+
navigationData: NavigationData;
|
|
53
|
+
}
|
|
File without changes
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
<%=#isTypeScript%>import type { Handle } from '../types';<%=/isTypeScript%>
|
|
2
3
|
|
|
3
4
|
export const useScreenSize = () => {
|
|
4
5
|
const [screenSize, setScreenSize] = useState(getScreenSize());
|
|
@@ -35,7 +36,7 @@ export const useScreenSizeClass = () => {
|
|
|
35
36
|
return 'screen-x-small';
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
let handlers = [];
|
|
39
|
+
let handlers<%=#isTypeScript%>: Handle[]<%=/isTypeScript%> = [];
|
|
39
40
|
const xSmallMedia = window.matchMedia('(max-width: 599.99px)');
|
|
40
41
|
const smallMedia = window.matchMedia('(min-width: 600px) and (max-width: 959.99px)');
|
|
41
42
|
const mediumMedia = window.matchMedia('(min-width: 960px) and (max-width: 1279.99px)');
|
|
@@ -47,9 +48,9 @@ const largeMedia = window.matchMedia('(min-width: 1280px)');
|
|
|
47
48
|
});
|
|
48
49
|
});
|
|
49
50
|
|
|
50
|
-
const subscribe = handler => handlers.push(handler);
|
|
51
|
+
const subscribe = (handler<%=#isTypeScript%>: Handle<%=/isTypeScript%>) => handlers.push(handler);
|
|
51
52
|
|
|
52
|
-
const unsubscribe = handler => {
|
|
53
|
+
const unsubscribe = (handler<%=#isTypeScript%>: Handle<%=/isTypeScript%>) => {
|
|
53
54
|
handlers = handlers.filter(item => item !== handler);
|
|
54
55
|
};
|
|
55
56
|
|
|
@@ -12,5 +12,5 @@ export function useMenuPatch() {
|
|
|
12
12
|
setTimeout(() => setEnabled(false));
|
|
13
13
|
}, [enabled]);
|
|
14
14
|
|
|
15
|
-
return [enabled ? 'pre-init-blink-fix' : '', onMenuReady]
|
|
15
|
+
return [enabled ? 'pre-init-blink-fix' : '', onMenuReady]<%=#isTypeScript%> as [string, () => void]<%=/isTypeScript%>;
|
|
16
16
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -15,7 +15,7 @@ export default function Task() {
|
|
|
15
15
|
|
|
16
16
|
<DataGrid
|
|
17
17
|
className={'dx-card wide-card'}
|
|
18
|
-
dataSource={dataSource}
|
|
18
|
+
dataSource={dataSource<%=#isTypeScript%> as any<%=/isTypeScript%>}
|
|
19
19
|
showBorders={false}
|
|
20
20
|
focusedRowEnabled={true}
|
|
21
21
|
defaultFocusedRowIndex={0}
|
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const prompts = require('./prompts');
|
|
2
|
+
|
|
3
|
+
const choices = [
|
|
3
4
|
{ value: 'side-nav-outer-toolbar', title: 'Side navigation (outer toolbar)' },
|
|
4
5
|
{ value: 'side-nav-inner-toolbar', title: 'Side navigation (inner toolbar)' }
|
|
5
6
|
];
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return layoutName;
|
|
8
|
+
const question = {
|
|
9
|
+
message: 'Specify desired application layout:',
|
|
10
|
+
choices: choices
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
const getLayoutInfo = (
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
type: 'select',
|
|
18
|
-
name: 'layout',
|
|
19
|
-
message: 'Specify desired application layout:',
|
|
20
|
-
choices: layouts
|
|
21
|
-
}
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
return runPrompts(questions, getValidLayoutName(layoutName));
|
|
13
|
+
const getLayoutInfo = async(defaultValue) => {
|
|
14
|
+
return await prompts(question, choices, defaultValue);
|
|
25
15
|
};
|
|
26
16
|
|
|
27
|
-
module.exports =
|
|
28
|
-
getLayoutInfo
|
|
29
|
-
};
|
|
17
|
+
module.exports = getLayoutInfo;
|
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
const prompts = require('prompts');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const run = async(question, choices, defaultValue) => {
|
|
4
|
+
question = Object.assign({}, question, {
|
|
5
|
+
type: 'select',
|
|
6
|
+
name: 'answer',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const { answer } = await askQuestion(question, getDefaultValue(choices, defaultValue));
|
|
10
|
+
|
|
11
|
+
return answer;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const askQuestion = async(question, validateValue) => {
|
|
4
15
|
if(validateValue) {
|
|
5
|
-
|
|
6
|
-
|
|
16
|
+
return {
|
|
17
|
+
answer: validateValue
|
|
7
18
|
};
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
resolve(optionData);
|
|
10
|
-
});
|
|
11
19
|
}
|
|
12
20
|
|
|
13
|
-
return await prompts(
|
|
21
|
+
return await prompts(question);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getDefaultValue = (choices, answer) => {
|
|
25
|
+
if(!answer || !choices.some((choice) => answer === choice.value)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return answer;
|
|
14
30
|
};
|
|
15
31
|
|
|
16
|
-
module.exports =
|
|
32
|
+
module.exports = run;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const prompts = require('./prompts');
|
|
2
|
+
|
|
3
|
+
const choices = [
|
|
4
|
+
{ value: 'typescript', title: 'TypeScript' },
|
|
5
|
+
{ value: 'javascript', title: 'JavaScript' }
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
const question = {
|
|
9
|
+
message: 'Specify desired template type:',
|
|
10
|
+
choices: choices
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const getTemplateTypeInfo = async(defaultValue) => {
|
|
14
|
+
if(defaultValue === undefined) return 'javascript';
|
|
15
|
+
return await prompts(question, choices, defaultValue);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = getTemplateTypeInfo;
|
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const prompts = require('./prompts');
|
|
2
|
+
|
|
3
|
+
const choices = [
|
|
3
4
|
{ value: 'v2', title: 'Vue version (v2)' },
|
|
4
5
|
{ value: 'v3', title: 'Vue version (v3)' }
|
|
5
6
|
];
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return `v${versionValue}`;
|
|
8
|
+
const question = {
|
|
9
|
+
message: 'What version do you want?',
|
|
10
|
+
choices: choices
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
const getVersionInfo = (
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
type: 'select',
|
|
18
|
-
name: 'version',
|
|
19
|
-
message: 'What version do you want?',
|
|
20
|
-
choices: versions
|
|
21
|
-
}
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
return runPrompts(questions, getValidVersion(versionValue));
|
|
13
|
+
const getVersionInfo = async(defaultValue) => {
|
|
14
|
+
return await prompts(question, choices, `v${defaultValue}`);
|
|
25
15
|
};
|
|
26
16
|
|
|
27
|
-
module.exports =
|
|
28
|
-
getVersionInfo
|
|
29
|
-
};
|
|
17
|
+
module.exports = getVersionInfo;
|
|
@@ -12,9 +12,9 @@ const applyTemplateToFile = (filePath, templateOptions) => {
|
|
|
12
12
|
return content;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const addPageToApp = (pageName, pageDir, templatePagesPath) => {
|
|
15
|
+
const addPageToApp = (pageName, pageDir, templatePagesPath, getCorrectExtension) => {
|
|
16
16
|
fs.readdirSync(templatePagesPath).forEach((pageItem) => {
|
|
17
|
-
const pagePath = path.join(pageDir, `${pageName}${extname(pageItem)}`);
|
|
17
|
+
const pagePath = path.join(pageDir, `${pageName}${getCorrectExtension(extname(pageItem))}`);
|
|
18
18
|
if(fs.existsSync(pagePath)) {
|
|
19
19
|
console.error('The page already exists');
|
|
20
20
|
process.exit();
|
|
@@ -25,19 +25,19 @@ const addPageToApp = (pageName, pageDir, templatePagesPath) => {
|
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const moveTemplateFilesToProject = (templateFolder, appPath, templateOptions, pathToFileRelativelyRoot) => {
|
|
28
|
+
const moveTemplateFilesToProject = (templateFolder, appPath, templateOptions, getCorrectPath, pathToFileRelativelyRoot) => {
|
|
29
29
|
const relativePath = pathToFileRelativelyRoot || '';
|
|
30
30
|
const pathToFiles = path.join(templateFolder, relativePath);
|
|
31
31
|
|
|
32
32
|
fs.readdirSync(pathToFiles).forEach(file => {
|
|
33
|
-
const pathToAppFile = path.join(appPath, relativePath, file);
|
|
33
|
+
const pathToAppFile = getCorrectPath(extname(file), path.join(appPath, relativePath, file), templateOptions.isTypeScript);
|
|
34
34
|
const nextFilePath = path.join(pathToFiles, file);
|
|
35
35
|
|
|
36
36
|
if(fs.lstatSync(nextFilePath).isDirectory()) {
|
|
37
37
|
if(!fs.existsSync(pathToAppFile)) {
|
|
38
38
|
fs.mkdirSync(pathToAppFile);
|
|
39
39
|
}
|
|
40
|
-
moveTemplateFilesToProject(templateFolder, appPath, templateOptions, path.join(relativePath, file));
|
|
40
|
+
moveTemplateFilesToProject(templateFolder, appPath, templateOptions, getCorrectPath, path.join(relativePath, file));
|
|
41
41
|
} else {
|
|
42
42
|
const content = applyTemplateToFile(nextFilePath, templateOptions);
|
|
43
43
|
fs.writeFileSync(pathToAppFile, content);
|
|
@@ -45,7 +45,12 @@ const moveTemplateFilesToProject = (templateFolder, appPath, templateOptions, pa
|
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
const getTempaltePath = (app) => {
|
|
49
|
+
return path.join(__dirname, '..', 'templates', app);
|
|
50
|
+
};
|
|
51
|
+
|
|
48
52
|
module.exports = {
|
|
49
53
|
moveTemplateFilesToProject,
|
|
50
|
-
addPageToApp
|
|
54
|
+
addPageToApp,
|
|
55
|
+
getTempaltePath
|
|
51
56
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const devextremeConfigUtils = require('./devextreme-config');
|
|
3
|
+
|
|
4
|
+
const isTypeScript = (templateType) => templateType === 'typescript';
|
|
5
|
+
|
|
6
|
+
const setFileExtension = (filePath, isTypeScript) => {
|
|
7
|
+
const { dir, name } = path.parse(filePath);
|
|
8
|
+
const ext = '.' + (isTypeScript ? 'tsx' : 'js');
|
|
9
|
+
|
|
10
|
+
return path.join(dir, name + ext);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const getTemplateType = (engine) => {
|
|
14
|
+
const devextremeConfig = devextremeConfigUtils.read();
|
|
15
|
+
return devextremeConfig[engine]
|
|
16
|
+
? devextremeConfig[engine].template
|
|
17
|
+
: 'javascript';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
isTypeScript,
|
|
22
|
+
setFileExtension,
|
|
23
|
+
getTemplateType
|
|
24
|
+
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Switch, Route, Redirect } from 'react-router-dom';
|
|
3
|
-
import { SingleCard } from './layouts';
|
|
4
|
-
import { LoginForm, ResetPasswordForm, ChangePasswordForm, CreateAccountForm } from './components';
|
|
5
|
-
|
|
6
|
-
export default function UnauthenticatedContent() {
|
|
7
|
-
return (
|
|
8
|
-
<Switch>
|
|
9
|
-
<Route exact path='/login' >
|
|
10
|
-
<SingleCard title="Sign In">
|
|
11
|
-
<LoginForm />
|
|
12
|
-
</SingleCard>
|
|
13
|
-
</Route>
|
|
14
|
-
<Route exact path='/create-account' >
|
|
15
|
-
<SingleCard title="Sign Up">
|
|
16
|
-
<CreateAccountForm />
|
|
17
|
-
</SingleCard>
|
|
18
|
-
</Route>
|
|
19
|
-
<Route exact path='/reset-password' >
|
|
20
|
-
<SingleCard
|
|
21
|
-
title="Reset Password"
|
|
22
|
-
description="Please enter the email address that you used to register, and we will send you a link to reset your password via Email."
|
|
23
|
-
>
|
|
24
|
-
<ResetPasswordForm />
|
|
25
|
-
</SingleCard>
|
|
26
|
-
</Route>
|
|
27
|
-
<Route exact path='/change-password/:recoveryCode' >
|
|
28
|
-
<SingleCard title="Change Password">
|
|
29
|
-
<ChangePasswordForm />
|
|
30
|
-
</SingleCard>
|
|
31
|
-
</Route>
|
|
32
|
-
<Redirect to={'/login'} />
|
|
33
|
-
</Switch>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { withNavigationWatcher } from './contexts/navigation';<%=^empty%>
|
|
2
|
-
import { HomePage, TasksPage, ProfilePage } from './pages';<%=/empty%>
|
|
3
|
-
|
|
4
|
-
const routes = [<%=^empty%>
|
|
5
|
-
{
|
|
6
|
-
path: '/tasks',
|
|
7
|
-
component: TasksPage
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
path: '/profile',
|
|
11
|
-
component: ProfilePage
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
path: '/home',
|
|
15
|
-
component: HomePage
|
|
16
|
-
}
|
|
17
|
-
<%=/empty%>];
|
|
18
|
-
|
|
19
|
-
export default routes.map(route => {
|
|
20
|
-
return {
|
|
21
|
-
...route,
|
|
22
|
-
component: withNavigationWatcher(route.component)
|
|
23
|
-
};
|
|
24
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as Header } from './header/header';
|
|
2
|
-
export { default as Footer } from './footer/footer';
|
|
3
|
-
export { default as LoginForm } from './login-form/login-form';
|
|
4
|
-
export { default as ResetPasswordForm } from './reset-password-form/reset-password-form';
|
|
5
|
-
export { default as CreateAccountForm } from './create-account-form/create-account-form';
|
|
6
|
-
export { default as ChangePasswordForm } from './change-password-form/change-password-form';
|
|
7
|
-
export { default as SideNavigationMenu } from './side-navigation-menu/side-navigation-menu';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React, { useState, createContext, useContext, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
const NavigationContext = createContext({});
|
|
4
|
-
const useNavigation = () => useContext(NavigationContext);
|
|
5
|
-
|
|
6
|
-
function NavigationProvider(props) {
|
|
7
|
-
const [navigationData, setNavigationData] = useState({});
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<NavigationContext.Provider
|
|
11
|
-
value={{ navigationData, setNavigationData }}
|
|
12
|
-
{...props}
|
|
13
|
-
/>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function withNavigationWatcher(Component) {
|
|
18
|
-
return function (props) {
|
|
19
|
-
const { path } = props.match;
|
|
20
|
-
const { setNavigationData } = useNavigation();
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
setNavigationData({ currentPath: path });
|
|
24
|
-
}, [path, setNavigationData]);
|
|
25
|
-
|
|
26
|
-
return React.createElement(Component, props);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
NavigationProvider,
|
|
32
|
-
useNavigation,
|
|
33
|
-
withNavigationWatcher
|
|
34
|
-
}
|