2022-11-16 05:16:56 -05:00
|
|
|
import { memo } from "react"
|
2022-04-09 20:48:19 -04:00
|
|
|
import styles from "./document.module.css"
|
2022-11-14 02:02:31 -05:00
|
|
|
import Skeleton from "@components/skeleton"
|
2022-11-10 02:11:36 -05:00
|
|
|
import Link from "next/link"
|
2022-03-21 23:43:50 -04:00
|
|
|
|
2022-11-12 21:39:03 -05:00
|
|
|
import Tooltip from "@components/tooltip"
|
2022-11-16 03:49:12 -05:00
|
|
|
import Button from "@components/button"
|
|
|
|
import ButtonGroup from "@components/button-group"
|
|
|
|
import DocumentTabs from "app/(posts)/components/tabs"
|
2022-11-16 05:16:56 -05:00
|
|
|
import Input from "@components/input"
|
2022-11-29 03:43:04 -05:00
|
|
|
import { Download, ExternalLink } from "react-feather"
|
2022-03-21 23:43:50 -04:00
|
|
|
|
2022-03-11 21:48:40 -05:00
|
|
|
// import Link from "next/link"
|
2022-03-06 19:46:59 -05:00
|
|
|
type Props = {
|
2022-04-09 20:48:19 -04:00
|
|
|
title: string
|
|
|
|
initialTab?: "edit" | "preview"
|
|
|
|
skeleton?: boolean
|
|
|
|
id: string
|
|
|
|
content: string
|
2022-11-12 19:06:23 -05:00
|
|
|
preview: string
|
2022-03-06 19:46:59 -05:00
|
|
|
}
|
|
|
|
|
2022-12-04 17:26:05 -05:00
|
|
|
const DownloadButtons = ({ rawLink }: { rawLink?: string }) => {
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
|
|
|
<div className={styles.actionWrapper}>
|
|
|
|
<ButtonGroup className={styles.actions}>
|
2022-11-12 21:39:03 -05:00
|
|
|
<Tooltip content="Download">
|
2022-11-08 03:23:28 -05:00
|
|
|
<Link
|
2022-04-09 20:48:19 -04:00
|
|
|
href={`${rawLink}?download=true`}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2022-11-30 01:10:51 -05:00
|
|
|
<Button
|
|
|
|
iconRight={<Download />}
|
|
|
|
aria-label="Download"
|
|
|
|
style={{ borderTopRightRadius: 0, borderBottomRightRadius: 0 }}
|
|
|
|
/>
|
2022-11-08 03:23:28 -05:00
|
|
|
</Link>
|
2022-04-09 20:48:19 -04:00
|
|
|
</Tooltip>
|
2022-11-12 21:39:03 -05:00
|
|
|
<Tooltip content="Open raw in new tab">
|
2022-11-08 03:23:28 -05:00
|
|
|
<Link href={rawLink || ""} target="_blank" rel="noopener noreferrer">
|
2022-04-09 20:48:19 -04:00
|
|
|
<Button
|
2022-11-30 01:10:51 -05:00
|
|
|
iconLeft={<ExternalLink />}
|
2022-04-09 20:48:19 -04:00
|
|
|
aria-label="Open raw file in new tab"
|
2022-11-30 01:10:51 -05:00
|
|
|
style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
|
2022-04-09 20:48:19 -04:00
|
|
|
/>
|
2022-11-08 03:23:28 -05:00
|
|
|
</Link>
|
2022-04-09 20:48:19 -04:00
|
|
|
</Tooltip>
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
|
|
|
)
|
2022-03-11 21:48:40 -05:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
const Document = ({
|
|
|
|
content,
|
2022-11-12 19:06:23 -05:00
|
|
|
preview,
|
2022-04-09 20:48:19 -04:00
|
|
|
title,
|
|
|
|
initialTab = "edit",
|
|
|
|
skeleton,
|
|
|
|
id
|
|
|
|
}: Props) => {
|
|
|
|
if (skeleton) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className={styles.card}>
|
|
|
|
<div className={styles.fileNameContainer}>
|
|
|
|
<Skeleton width={275} height={36} />
|
|
|
|
</div>
|
|
|
|
<div className={styles.descriptionContainer}>
|
|
|
|
<div style={{ flexDirection: "row", display: "flex" }}>
|
|
|
|
<Skeleton width={125} height={36} />
|
|
|
|
</div>
|
|
|
|
<Skeleton width={"100%"} height={350} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-03-22 01:50:25 -04:00
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
2022-11-16 03:49:12 -05:00
|
|
|
<>
|
2022-04-09 20:48:19 -04:00
|
|
|
<div className={styles.card}>
|
|
|
|
<Link href={`#${title}`} className={styles.fileNameContainer}>
|
2022-11-16 05:16:56 -05:00
|
|
|
<Input
|
2022-04-09 20:48:19 -04:00
|
|
|
id={`${title}`}
|
|
|
|
width={"100%"}
|
2022-11-18 01:36:53 -05:00
|
|
|
height={"2rem"}
|
2022-04-09 20:48:19 -04:00
|
|
|
style={{ borderRadius: 0 }}
|
2022-11-16 05:16:56 -05:00
|
|
|
value={title || "Untitled"}
|
2022-12-04 17:49:18 -05:00
|
|
|
onChange={() => {}}
|
2022-11-16 05:16:56 -05:00
|
|
|
disabled
|
2022-11-21 00:02:09 -05:00
|
|
|
aria-label="Document title"
|
2022-11-16 05:16:56 -05:00
|
|
|
/>
|
2022-04-09 20:48:19 -04:00
|
|
|
</Link>
|
|
|
|
<div className={styles.descriptionContainer}>
|
2022-12-04 17:49:18 -05:00
|
|
|
{/* Not /api/ because of rewrites defined in next.config.mjs */}
|
|
|
|
<DownloadButtons rawLink={`/file/raw/${id}`} />
|
2022-11-16 03:49:12 -05:00
|
|
|
<DocumentTabs
|
|
|
|
defaultTab={initialTab}
|
|
|
|
preview={preview}
|
|
|
|
content={content}
|
|
|
|
isEditing={false}
|
|
|
|
/>
|
2022-04-09 20:48:19 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-16 03:49:12 -05:00
|
|
|
</>
|
2022-04-09 20:48:19 -04:00
|
|
|
)
|
2022-03-06 19:46:59 -05:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
export default memo(Document)
|