2022-11-16 05:16:56 -05:00
|
|
|
import Button from "@components/button"
|
|
|
|
import { Popover } from "@components/popover"
|
2022-11-12 04:28:06 -05:00
|
|
|
import ShiftBy from "@components/shift-by"
|
2022-03-25 16:01:46 -04:00
|
|
|
import { codeFileExtensions } from "@lib/constants"
|
2022-11-16 05:16:56 -05:00
|
|
|
import clsx from "clsx"
|
2022-11-12 04:28:06 -05:00
|
|
|
import type { File } from "lib/server/prisma"
|
2022-04-20 02:36:56 -04:00
|
|
|
import styles from "./dropdown.module.css"
|
2022-11-16 05:16:56 -05:00
|
|
|
import buttonStyles from "@components/button/button.module.css"
|
2022-11-29 03:43:04 -05:00
|
|
|
import { ChevronDown, Code, File as FileIcon } from "react-feather"
|
2022-03-25 16:01:46 -04:00
|
|
|
|
|
|
|
type Item = File & {
|
2022-04-09 20:48:19 -04:00
|
|
|
icon: JSX.Element
|
2022-03-25 16:01:46 -04:00
|
|
|
}
|
|
|
|
|
2022-11-16 05:16:56 -05:00
|
|
|
const FileDropdown = ({ files }: { files: File[] }) => {
|
|
|
|
const items = files.map((file) => {
|
|
|
|
const extension = file.title.split(".").pop()
|
|
|
|
if (codeFileExtensions.includes(extension || "")) {
|
|
|
|
return {
|
|
|
|
...file,
|
2022-11-29 03:43:04 -05:00
|
|
|
icon: <Code />
|
2022-11-16 05:16:56 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
...file,
|
|
|
|
icon: <FileIcon />
|
2022-04-09 20:48:19 -04:00
|
|
|
}
|
2022-11-16 05:16:56 -05:00
|
|
|
}
|
|
|
|
})
|
2022-03-25 16:01:46 -04:00
|
|
|
|
2022-04-12 02:07:06 -04:00
|
|
|
const content = (
|
2022-04-10 23:05:42 -04:00
|
|
|
<ul className={styles.content}>
|
|
|
|
{items.map((item) => (
|
2022-11-16 05:16:56 -05:00
|
|
|
<li key={item.id}>
|
2022-04-10 23:05:42 -04:00
|
|
|
<a href={`#${item.title}`}>
|
|
|
|
<ShiftBy y={5}>
|
|
|
|
<span className={styles.fileIcon}>{item.icon}</span>
|
|
|
|
</ShiftBy>
|
|
|
|
<span className={styles.fileTitle}>
|
|
|
|
{item.title ? item.title : "Untitled"}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
2022-04-12 02:07:06 -04:00
|
|
|
)
|
2022-03-25 16:01:46 -04:00
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
2022-11-16 05:16:56 -05:00
|
|
|
<Popover>
|
2022-11-18 02:39:52 -05:00
|
|
|
<Popover.Trigger className={buttonStyles.button}>
|
|
|
|
<div
|
|
|
|
className={clsx(buttonStyles.icon, styles.chevron)}
|
|
|
|
style={{ marginRight: 6 }}
|
|
|
|
>
|
2022-11-16 05:16:56 -05:00
|
|
|
<ChevronDown />
|
|
|
|
</div>
|
2022-11-18 01:36:53 -05:00
|
|
|
<span>
|
|
|
|
Jump to {files.length} {files.length === 1 ? "file" : "files"}
|
|
|
|
</span>
|
2022-11-16 05:16:56 -05:00
|
|
|
</Popover.Trigger>
|
2022-11-29 03:43:04 -05:00
|
|
|
<Popover.Content className={styles.contentWrapper}>{content}</Popover.Content>
|
2022-11-16 05:16:56 -05:00
|
|
|
</Popover>
|
2022-04-09 20:48:19 -04:00
|
|
|
)
|
2022-03-25 16:01:46 -04:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
export default FileDropdown
|