-
Notifications
You must be signed in to change notification settings - Fork 12
/
App.tsx
118 lines (96 loc) · 2.9 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
import React, { useCallback, useRef, useState } from 'react';
import { Footer } from '../components/Footer';
import { HelpDialog } from '../components/HelpDialog';
import { IconButton } from '../components/IconButton';
import { Logo } from '../components/Logo';
import { Main } from '../components/Main';
import { Notification } from '../components/Notification';
import { Sidebar } from '../components/Sidebar';
import { Viewer } from '../components/Viewer';
import { HelpIcon } from '../components/icons/HelpIcon';
import { useKey } from '../hooks/useKey';
import { useEntities } from '../states/entity';
import { useSidebarMutators } from '../states/sidebar';
import { Color } from '../styles/variables.css';
import { findFirstFocusable } from '../utils/selector';
import * as styles from './App.css';
export type Props = {};
export const App = () => {
const { toggle: toggleSidebar } = useSidebarMutators();
const { newItems, failedItems, deletedItems, passedItems } = useEntities();
const [helpDialogOpen, setHelpDialogOpen] = useState(false);
const filterRef = useRef<HTMLInputElement>(null);
const listRef = useRef<HTMLDivElement>(null);
const handleHelpClick = useCallback((e: React.MouseEvent) => {
e.preventDefault();
setHelpDialogOpen(true);
}, []);
const handleHelpClose = useCallback(() => {
setHelpDialogOpen(false);
}, []);
useKey(null, ['/', 's'], (e) => {
e.preventDefault();
if (filterRef.current != null) {
filterRef.current.focus();
}
});
useKey(null, ['g s'], () => {
const { current: list } = listRef;
if (list == null) {
return;
}
const first = findFirstFocusable(list);
if (first == null) {
return;
}
first.focus();
});
useKey(null, ['g c'], () => {
if (failedItems.length > 0) {
window.location.hash = 'changed';
}
});
useKey(null, ['g n'], () => {
if (newItems.length > 0) {
window.location.hash = 'new';
}
});
useKey(null, ['g d'], () => {
if (deletedItems.length > 0) {
window.location.hash = 'deleted';
}
});
useKey(null, ['g p'], () => {
if (passedItems.length > 0) {
window.location.hash = 'passed';
}
});
useKey(null, ['f'], () => {
toggleSidebar();
});
useKey(null, ['Shift+?'], () => {
setHelpDialogOpen(true);
});
return (
<>
<span className={styles.brand}>
<Logo size={40} />
</span>
<main className={styles.layout}>
<Sidebar inputRef={filterRef} listRef={listRef} />
<div className={styles.content}>
<Main />
<Footer />
</div>
</main>
<span className={styles.help}>
<IconButton variant="dark" onClick={handleHelpClick}>
<HelpIcon fill={Color.WHITE} />
</IconButton>
</span>
<HelpDialog open={helpDialogOpen} onRequestClose={handleHelpClose} />
<Viewer />
<Notification />
</>
);
};