forked from mydraft-cc/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
170 lines (144 loc) · 6.51 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* mydraft.cc
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved.
*/
import { LeftOutlined, RightOutlined } from '@ant-design/icons';
import { usePrinter } from '@app/core';
import { ArrangeMenu, ClipboardMenu, CustomProperties, EditorView, HistoryMenu, Icons, LayoutProperties, LoadingMenu, LockMenu, MoreProperties, Pages, PrintView, Recent, SettingsMenu, Shapes, UIMenu, VisualProperties } from '@app/wireframes/components';
import { loadDiagramAsync, newDiagram, selectTab, showInfoToast, toggleLeftSidebar, toggleRightSidebar, useStore } from '@app/wireframes/model';
import { Button, Collapse, Layout, Tabs } from 'antd';
import classNames from 'classnames';
import * as React from 'react';
import { useDispatch } from 'react-redux';
import { useRouteMatch } from 'react-router';
import { texts } from './texts';
import { PresentationView } from './wireframes/components/PresentationView';
const logo = require('./images/logo.svg').default;
export const App = () => {
const dispatch = useDispatch();
const route = useRouteMatch();
const routeToken = route.params['token'] || null;
const routeTokenSnapshot = React.useRef(routeToken);
const selectedTab = useStore(s => s.ui.selectedTab);
const showLeftSidebar = useStore(s => s.ui.showLeftSidebar);
const showRightSidebar = useStore(s => s.ui.showRightSidebar);
const [presenting, setPresenting] = React.useState(false);
const [
print,
printReady,
isPrinting,
ref,
] = usePrinter();
React.useEffect(() => {
const token = routeTokenSnapshot.current;
if (token && token.length > 0) {
dispatch(loadDiagramAsync({ tokenToRead: token, navigate: false }));
} else {
dispatch(newDiagram({ navigate: false }));
}
}, [dispatch]);
React.useEffect(() => {
if (isPrinting) {
dispatch(showInfoToast('Printing started...'));
}
}, [dispatch, isPrinting]);
const doSelectTab = React.useCallback((key: string) => {
dispatch(selectTab(key));
}, [dispatch]);
const doToggleLeftSidebar = React.useCallback(() => {
dispatch(toggleLeftSidebar());
}, [dispatch]);
const doToggleRightSidebar = React.useCallback(() => {
dispatch(toggleRightSidebar());
}, [dispatch]);
const doEdit = React.useCallback(() => {
setPresenting(false);
}, []);
const doPresent = React.useCallback(() => {
setPresenting(true);
}, []);
return (
<>
<Layout className='screen-mode'>
<Layout.Header>
<img className='logo' src={logo} alt='mydraft.cc' />
<HistoryMenu />
<span className='menu-separator' />
<LockMenu />
<span className='menu-separator' />
<ArrangeMenu />
<span className='menu-separator' />
<ClipboardMenu />
<span className='menu-separator' />
<UIMenu onPlay={doPresent} />
<span className='menu-separator' />
<SettingsMenu onPrint={print} />
<span style={{ float: 'right' }}>
<LoadingMenu />
</span>
</Layout.Header>
<Layout className='content'>
<Layout.Sider width={320} className='sidebar-left'
collapsed={!showLeftSidebar}
collapsedWidth={0}>
<Tabs type='card' onTabClick={doSelectTab} activeKey={selectedTab}>
<Tabs.TabPane key='shapes' tab={texts.common.shapes}>
<Shapes />
</Tabs.TabPane>
<Tabs.TabPane key='icons' tab={texts.common.icons}>
<Icons />
</Tabs.TabPane>
<Tabs.TabPane key='pages' tab={texts.common.pages}>
<Pages />
</Tabs.TabPane>
<Tabs.TabPane key='recent' tab={texts.common.recent}>
<Recent />
</Tabs.TabPane>
</Tabs>
</Layout.Sider>
<Layout.Content className='editor-content'>
<EditorView spacing={40} />
</Layout.Content>
<Layout.Sider width={330} className='sidebar-right'
collapsed={!showRightSidebar}
collapsedWidth={0}>
<Collapse bordered={false} defaultActiveKey={['layout', 'visual', 'custom']}>
<Collapse.Panel key='layout' header={texts.common.layout}>
<LayoutProperties />
</Collapse.Panel>
<Collapse.Panel key='visual' header={texts.common.visual}>
<VisualProperties />
</Collapse.Panel>
<Collapse.Panel key='more' header={texts.common.more}>
<MoreProperties />
</Collapse.Panel>
<Collapse.Panel key='custom' header={texts.common.custom}>
<CustomProperties />
</Collapse.Panel>
</Collapse>
</Layout.Sider>
<Button icon={showLeftSidebar ? <LeftOutlined /> : <RightOutlined />}
className={classNames('toggle-button-left', { visible: showLeftSidebar })}
size='small'
shape='circle'
onClick={doToggleLeftSidebar} />
<Button icon={showRightSidebar ? <RightOutlined /> : <LeftOutlined />}
className={classNames('toggle-button-right', { visible: showRightSidebar })}
size='small'
shape='circle'
onClick={doToggleRightSidebar} />
</Layout>
</Layout>
{presenting &&
<PresentationView onClose={doEdit} />
}
{isPrinting &&
<div className='print-mode' ref={ref}>
<PrintView onRender={printReady} />
</div>
}
</>
);
};