-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.tsx
102 lines (94 loc) · 3.66 KB
/
index.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
import React, { ReactElement, ReactNode, useState } from 'react';
import { FontAwesomeIcon as Icon } from '@fortawesome/react-fontawesome';
import { faChevronRight, faChevronLeft } from '@fortawesome/free-solid-svg-icons';
import { useMappedWindowSize } from '../../hooks/window-size-hook';
import FocusView from './FocusView';
import FutureView, { futureViewConfigProvider, FutureViewConfig } from './FutureView';
import ProgressTracker from './ProgressTracker';
import styles from './index.module.css';
import SamwiseIcon from '../UI/SamwiseIcon';
const FocusPanel = (): ReactElement => <div className={styles.FocusPanel}><FocusView /></div>;
export default function TaskView(): ReactElement {
const [doesShowFocusViewInWideScreen, setDoesShowFocusViewInWideScreen] = useState(true);
const [doesShowFutureViewInSmallScreen, setDoesShowFutureViewInSmallScreen] = useState(false);
const [config, setConfig] = useState<FutureViewConfig>(futureViewConfigProvider.initialValue);
const screenIsSmall = useMappedWindowSize((size) => size.width <= 840);
const toggleFocusViewInWideScreen = (): void => setDoesShowFocusViewInWideScreen((prev) => !prev);
const switchView = (): void => setDoesShowFutureViewInSmallScreen((prev) => !prev);
const FuturePanel = ({ children }: { readonly children?: ReactNode }): ReactElement => {
const onChange = (c: FutureViewConfig): void => { setConfig(c); };
return (
<div className={styles.FuturePanel}>
<div className={styles.FuturePanelContainer}>
{children}
<FutureView config={config} onConfigChange={onChange} />
</div>
</div>
);
};
FuturePanel.defaultProps = { children: null };
const inNDaysView = futureViewConfigProvider.isInNDaysView(config);
const showFocusView = inNDaysView || doesShowFocusViewInWideScreen;
if (screenIsSmall) {
const taskView = doesShowFutureViewInSmallScreen
? (
<div className={styles.TaskView}>
<FuturePanel />
<SamwiseIcon
iconName="pin-dark-filled"
className={styles.ViewSwitcher}
onClick={switchView}
/>
</div>
) : (
<div className={styles.TaskView}>
<FocusPanel />
<SamwiseIcon
iconName="calendar-dark"
className={styles.ViewSwitcher}
onClick={switchView}
/>
</div>
);
return (
<>
{taskView}
<ProgressTracker inMobileView />
</>
);
}
const WideScreenFocusViewToggle = (): ReactElement => {
const wrapperStyle = doesShowFocusViewInWideScreen ? { left: '-4em' } : { left: '0' };
const buttonStyle = doesShowFocusViewInWideScreen ? { left: '2em' } : {};
const iconName = doesShowFocusViewInWideScreen ? faChevronLeft : faChevronRight;
const iconClass = doesShowFocusViewInWideScreen
? styles.FocusViewToggleIconFocusViewShow
: styles.FocusViewToggleIconFocusViewHide;
return (
<div className={styles.FocusViewToggleWrapper} style={wrapperStyle}>
<div
role="button"
tabIndex={-1}
className={styles.FocusViewToggle}
style={buttonStyle}
onClick={toggleFocusViewInWideScreen}
onKeyDown={toggleFocusViewInWideScreen}
>
<Icon icon={iconName} className={iconClass} />
</div>
</div>
);
};
return (
<>
<div className={styles.TaskView}>
<ProgressTracker inMobileView={false} />
{showFocusView && <FocusPanel />}
{showFocusView && <div style={{ width: '2em' }} />}
<FuturePanel>
{!inNDaysView && <WideScreenFocusViewToggle />}
</FuturePanel>
</div>
</>
);
}