-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
views.tsx
127 lines (117 loc) · 3.79 KB
/
views.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
import React, { Suspense, useCallback, useMemo, useReducer } from "react";
import { useLocation } from "wouter";
import classNames from "classnames";
import Context, { initialState, reducer } from "./stores";
import Routes from "./urls";
import {
Navbar,
NavbarGroup,
Alignment,
NavbarHeading,
NavbarDivider,
Classes,
Tabs,
Tab,
TabId,
InputGroup,
Spinner,
Icon,
ButtonGroup,
Popover,
Button,
Menu,
MenuItem,
MenuDivider,
Position,
} from "@blueprintjs/core";
import styles from "./styles.scss";
import { ApolloProvider } from "@apollo/react-hooks";
import ApolloClient from "apollo-client";
import { InMemoryCache } from "apollo-cache-inmemory";
import { HttpLink } from "apollo-link-http";
// === PAGES === //
/* --- Main Page --- */
export function PagesShell() {
const [state, dispatch] = useReducer(reducer, initialState);
const client = useMemo(() => {
return new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: "https://api.github.com/graphql",
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
},
}),
});
}, []);
return (
<Context.Provider value={{ state, dispatch }}>
<ApolloProvider client={client}>
<header>
<NavigationBar />
</header>
<main className={styles.main}>
<Suspense fallback={<Loading />}>
<Routes />
</Suspense>
</main>
</ApolloProvider>
</Context.Provider>
);
}
// === COMPONENTS === //
/* --- Loading --- */
export function Loading() {
return (
<div className={styles.loading}>
Loading
<span className={styles.loadingSpan}>...</span>
</div>
);
}
/* --- Navigation Bar --- */
export function NavigationBar() {
const [location, setLocation] = useLocation();
const goto = useCallback(
(newTabId: TabId) => {
setLocation(String(newTabId));
},
[setLocation],
);
const searchSpinner = <Spinner size={Icon.SIZE_STANDARD} />;
const navBarMenu = (
<Menu className={Classes.ELEVATION_1}>
<MenuItem icon="new-text-box" text="New text box" />
<MenuItem icon="new-object" text="New object" />
<MenuItem icon="new-link" text="New link" />
<MenuDivider />
<MenuItem icon="cog" labelElement={<Icon icon="share" />} text="Settings..." />
</Menu>
);
return (
<Navbar className={Classes.DARK}>
<NavbarGroup align={Alignment.LEFT}>
<NavbarHeading>
<strong>Boilerplate</strong>{" "}
<span className={classNames("bp3-monospace-text", "bp3-text-small", "bp3-text-disabled")}>
{location}
</span>
</NavbarHeading>
<NavbarDivider />
<Tabs animate={true} id="navBar" large={true} onChange={goto} selectedTabId={location}>
<Tab id="/" title="Home" />
<Tab id="/app/context" title="Context" />
</Tabs>
</NavbarGroup>
<NavbarGroup align={Alignment.RIGHT}>
<InputGroup type="search" leftIcon="search" placeholder="Search..." rightElement={searchSpinner} />
<NavbarDivider />
<ButtonGroup minimal={true}>
<Popover content={navBarMenu} position={Position.BOTTOM_RIGHT}>
<Button icon="settings" />
</Popover>
</ButtonGroup>
</NavbarGroup>
</Navbar>
);
}