-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathindex.tsx
More file actions
73 lines (66 loc) · 2.83 KB
/
Copy pathindex.tsx
File metadata and controls
73 lines (66 loc) · 2.83 KB
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
import classNames from "classnames";
import { GetStaticProps } from "next";
import { useEffect, useState } from "react";
import { getColumnManifests } from "../columns";
import { Manifest } from "../glide";
import { removeUndefineds } from "../util";
import PreviewPage from "./preview/[slug]";
interface Props {
manifests: Record<string, Manifest>;
}
export const getStaticProps: GetStaticProps<Props> = async () => {
const manifests = await getColumnManifests();
return {
props: {
manifests: removeUndefineds(manifests),
},
};
};
const Index = ({ manifests }: Props) => {
const columns = Object.keys(manifests).sort((a, b) => manifests[a].name.localeCompare(manifests[b].name));
const [selectedColumn, setSelectedColumn] = useState<string>();
useEffect(() => {
let { column } = localStorage;
if (manifests[column] === undefined) {
column = columns[0];
}
setSelectedColumn(column);
});
return (
<div className="flex flex-col h-screen text-gray-700 dark:text-gray-50">
<div className="h-16 bg-[#12CCE5] shadow hidden">Header</div>
<div className="flex flex-grow w-full">
<div className="h-screen overflow-scroll border-r w-72 dark:bg-gray-900 dark:border-transparent">
{columns.map(column => {
const manifest = manifests[column];
return (
<div
className={classNames(
"p-4 flex items-center space-x-4 overflow-hidden cursor-pointer border-b dark:border-gray-600",
{
" dark:bg-gray-900 cursor-pointer hover:bg-white dark:hover:bg-gray-800":
column !== selectedColumn,
"bg-blue-500 text-white": column === selectedColumn,
}
)}
key={column}
onClick={() => {
localStorage.column = column;
setSelectedColumn(column);
}}
>
<div className="flex-grow">
<div className="text-base">{manifest.name}</div>
</div>
</div>
);
})}
</div>
<div className="flex-grow bg-gray-100 dark:bg-black">
{selectedColumn && <PreviewPage slug={selectedColumn} />}
</div>
</div>
</div>
);
};
export default Index;