2022-03-22 23:06:15 -04:00
|
|
|
import Header from "@components/header/header"
|
2022-03-21 23:30:45 -04:00
|
|
|
import PageSeo from "@components/page-seo"
|
|
|
|
import VisibilityBadge from "@components/visibility-badge"
|
2022-03-23 00:18:26 -04:00
|
|
|
import DocumentComponent from '@components/view-document'
|
2022-03-21 23:30:45 -04:00
|
|
|
import styles from './post-page.module.css'
|
2022-03-22 23:06:15 -04:00
|
|
|
import homeStyles from '@styles/Home.module.css'
|
2022-03-21 23:30:45 -04:00
|
|
|
|
2022-03-23 00:18:26 -04:00
|
|
|
import type { File, Post } from "@lib/types"
|
2022-03-22 23:06:15 -04:00
|
|
|
import { Page, Button, Text } from "@geist-ui/core"
|
2022-03-21 23:30:45 -04:00
|
|
|
|
2022-03-22 23:06:15 -04:00
|
|
|
type Props = {
|
2022-03-21 23:30:45 -04:00
|
|
|
post: Post
|
|
|
|
}
|
|
|
|
|
2022-03-22 23:06:15 -04:00
|
|
|
const PostPage = ({ post }: Props) => {
|
2022-03-21 23:30:45 -04:00
|
|
|
const download = async () => {
|
2022-03-21 23:43:50 -04:00
|
|
|
const downloadZip = (await import("client-zip")).downloadZip
|
2022-03-21 23:34:05 -04:00
|
|
|
const blob = await downloadZip(post.files.map((file: any) => {
|
2022-03-21 23:30:45 -04:00
|
|
|
return {
|
|
|
|
name: file.title,
|
|
|
|
input: file.content,
|
|
|
|
lastModified: new Date(file.updatedAt)
|
|
|
|
}
|
|
|
|
})).blob()
|
|
|
|
const link = document.createElement("a")
|
|
|
|
link.href = URL.createObjectURL(blob)
|
|
|
|
link.download = `${post.title}.zip`
|
|
|
|
link.click()
|
|
|
|
link.remove()
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page width={"100%"}>
|
|
|
|
<PageSeo
|
|
|
|
title={`${post.title} - Drift`}
|
|
|
|
description={post.description}
|
|
|
|
isPrivate={false}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Page.Header>
|
2022-03-22 23:06:15 -04:00
|
|
|
<Header />
|
2022-03-21 23:30:45 -04:00
|
|
|
</Page.Header>
|
2022-03-22 23:06:15 -04:00
|
|
|
<Page.Content className={homeStyles.main}>
|
2022-03-21 23:30:45 -04:00
|
|
|
{/* {!isLoading && <PostFileExplorer files={post.files} />} */}
|
|
|
|
<div className={styles.header}>
|
|
|
|
<div className={styles.titleAndBadge}>
|
|
|
|
<Text h2>{post.title}</Text>
|
|
|
|
<span><VisibilityBadge visibility={post.visibility} /></span>
|
|
|
|
</div>
|
|
|
|
<Button auto onClick={download}>
|
|
|
|
Download as ZIP archive
|
|
|
|
</Button>
|
|
|
|
</div>
|
2022-03-23 15:36:29 -04:00
|
|
|
{post.files.map(({ id, content, title }: File) => (
|
2022-03-21 23:30:45 -04:00
|
|
|
<DocumentComponent
|
|
|
|
key={id}
|
|
|
|
title={title}
|
|
|
|
initialTab={'preview'}
|
2022-03-23 00:18:26 -04:00
|
|
|
id={id}
|
|
|
|
content={content}
|
2022-03-21 23:30:45 -04:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Page.Content>
|
|
|
|
</Page >
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PostPage
|