-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d59bc94
commit 34202be
Showing
13 changed files
with
233 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { FC, useState } from 'react' | ||
import { Document, Page, pdfjs } from 'react-pdf' | ||
import 'react-pdf/dist/esm/Page/AnnotationLayer.css' | ||
import 'react-pdf/dist/esm/Page/TextLayer.css' | ||
import { createStyles, Paper, ScrollArea, Stack } from '@mantine/core' | ||
import { showErrorNotification } from '@Utils/ApiErrorHandler' | ||
|
||
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js` | ||
|
||
interface PDFViewerProps { | ||
url?: string | ||
height?: number | string | ||
} | ||
|
||
const useStyles = createStyles((theme, { height }: PDFViewerProps) => ({ | ||
layout: { | ||
marginLeft: theme.spacing.md, | ||
marginRight: theme.spacing.md, | ||
borderRadius: theme.radius.md, | ||
|
||
[theme.fn.largerThan(1100 + theme.spacing.md * 2)]: { | ||
maxWidth: 900, | ||
marginLeft: 'auto', | ||
marginRight: 'auto', | ||
}, | ||
|
||
'& canvas': { | ||
minWidth: '100% !important', | ||
maxWidth: '100% !important', | ||
height: 'auto !important', | ||
borderRadius: theme.radius.md, | ||
}, | ||
|
||
'& .react-pdf__Page__textContent': { | ||
display: 'none', | ||
}, | ||
}, | ||
|
||
doc: { | ||
maxHeight: height, | ||
}, | ||
|
||
paper: { | ||
marginBottom: theme.spacing.md, | ||
}, | ||
})) | ||
|
||
const PDFViewer: FC<PDFViewerProps> = (props) => { | ||
const [numPages, setNumPages] = useState(0) | ||
const { classes } = useStyles(props) | ||
|
||
return ( | ||
<ScrollArea className={classes.layout} type="never"> | ||
<Document | ||
file={props.url} | ||
className={classes.doc} | ||
onLoadSuccess={({ numPages }) => { | ||
setNumPages(numPages) | ||
}} | ||
onLoadError={showErrorNotification} | ||
> | ||
<Stack> | ||
{Array.from(new Array(numPages), (el, index) => ( | ||
<Paper className={classes.paper} key={`page_${index + 1}`}> | ||
<Page width={900} pageNumber={index + 1} renderAnnotationLayer={false} /> | ||
</Paper> | ||
))} | ||
</Stack> | ||
</Document> | ||
</ScrollArea> | ||
) | ||
} | ||
|
||
export default PDFViewer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import dayjs from 'dayjs' | ||
import { FC } from 'react' | ||
import { ActionIcon, Avatar, Card, Group, PaperProps, Stack, Text } from '@mantine/core' | ||
import { mdiDownload } from '@mdi/js' | ||
import { Icon } from '@mdi/react' | ||
import { WriteupInfoModel } from '@Api' | ||
|
||
interface TeamWriteupCardProps extends PaperProps { | ||
writeup: WriteupInfoModel | ||
selected?: boolean | ||
onClick: () => void | ||
} | ||
|
||
const TeamWriteupCard: FC<TeamWriteupCardProps> = ({ writeup, selected, ...props }) => { | ||
return ( | ||
<Card | ||
{...props} | ||
p="sm" | ||
shadow="sm" | ||
sx={(theme) => ({ | ||
border: selected | ||
? `2px solid ${theme.colors.brand[theme.colorScheme === 'dark' ? 8 : 6]}` | ||
: 'none', | ||
cursor: 'pointer', | ||
})} | ||
> | ||
<Group noWrap spacing={3} position="apart"> | ||
<Group noWrap position="apart"> | ||
<Avatar src={writeup.team?.avatar} size="md"> | ||
{writeup.team?.name?.slice(0, 1)} | ||
</Avatar> | ||
<Stack spacing={0}> | ||
<Text lineClamp={1} weight={600}> | ||
{writeup.team?.name} | ||
</Text> | ||
<Text lineClamp={1} size="xs" color="dimmed"> | ||
{dayjs(writeup.uploadTimeUTC).format('YYYY-MM-DD HH:mm')} | ||
</Text> | ||
</Stack> | ||
</Group> | ||
<ActionIcon onClick={() => window.open(writeup.url, '_blank')}> | ||
<Icon path={mdiDownload} size={1} /> | ||
</ActionIcon> | ||
</Group> | ||
</Card> | ||
) | ||
} | ||
|
||
export default TeamWriteupCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.