Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create document viewer component #976

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'katex/dist/katex.min.css';

import { CssBaseline } from '@mui/material';
import { ThemeProvider } from '@mui/system';
import ThemeProvider from '@mui/material/styles/ThemeProvider';

import * as React from 'react';
import 'react-quill/dist/quill.snow.css';
Expand Down Expand Up @@ -50,7 +50,7 @@ export const globalTypes = {
},
},
};
const theme = buildTheme()
const theme = buildTheme();
export const decorators = [
(Story, { globals }) => {
return (
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@ag-grid-community/client-side-row-model": "31.3.2",
"@ag-grid-community/react": "^31.3.2",
"@ag-grid-community/styles": "^31.3.2",
"@cyntler/react-doc-viewer": "1.16.6",
"@storybook/react-vite": "8.1.11",
"http-status-codes": "2.3.0",
"interweave": "13.1.0",
Expand All @@ -97,7 +98,7 @@
"@emotion/cache": "~11.10.7 || ~11.11.0 || ~11.13.0",
"@emotion/react": "~11.10.6 || ~11.11.0 || ~11.13.0",
"@emotion/styled": "~11.10.6 || ~11.11.0 || ~11.13.0",
"@graasp/sdk": "^4.14.0",
"@graasp/sdk": "*",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert.

"@graasp/translations": "^1.23.0",
"@mui/icons-material": "~5.14.0 || ~5.15.0 || ~5.16.0",
"@mui/lab": "~5.0.0-alpha.150",
Expand All @@ -116,7 +117,7 @@
"@emotion/cache": "~11.11.0",
"@emotion/react": "11.11.4",
"@emotion/styled": "11.11.5",
"@graasp/sdk": "4.22.0",
"@graasp/sdk": "https://github.com/graasp/graasp-sdk.git#616-docs-mimetypes",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to update.

"@mui/icons-material": "5.16.0",
"@mui/lab": "5.0.0-alpha.171",
"@mui/material": "5.16.0",
Expand Down
22 changes: 22 additions & 0 deletions src/items/Document.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Meta, StoryObj } from '@storybook/react';

import FileDocument from './FileDocument';

const meta: Meta<typeof FileDocument> = {
title: 'Items/Document File',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Document is actually what it is, but because of our other nomenclature I would prefer something a bit closer to "viewer" and to the library you used.

Suggested change
title: 'Items/Document File',
title: 'Items/FileDocumentViewer',

component: FileDocument,

render: (args) => {
return <FileDocument {...args} />;
},
};

export default meta;

type Story = StoryObj<typeof FileDocument>;

export const Document: Story = {
args: {
uri: 'https://www.lehman.edu/faculty/john/classroomrespolicy1.docx',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just read the docs, do you think we could use a local file like this:

   { uri: require("./example-files/pdf.pdf") }, // Local File

},
};
18 changes: 18 additions & 0 deletions src/items/FileDocument.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import DocViewer, { DocViewerRenderers } from '@cyntler/react-doc-viewer';
import '@cyntler/react-doc-viewer/dist/index.css';

type Props = {
uri: string;
};
const FileDocument = ({ uri }: Props): JSX.Element => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const FileDocument = ({ uri }: Props): JSX.Element => {
const FileDocumentViewer = ({ uri }: Props): JSX.Element => {

const docs = [{ uri }];
return (
<DocViewer
documents={docs}
pluginRenderers={DocViewerRenderers}
prefetchMethod='GET'
/>
);
};

export default FileDocument;
18 changes: 18 additions & 0 deletions src/items/FileItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SCREEN_MAX_HEIGHT, UNEXPECTED_ERROR_MESSAGE } from '../constants';
import { ERRORS } from '../enums';
import DownloadButtonFileItem from './DownloadButtonFileItem';
import FileAudio from './FileAudio';
import FileDocument from './FileDocument';
import FileImage from './FileImage';
import FilePdf from './FilePdf';
import FileVideo from './FileVideo';
Expand Down Expand Up @@ -136,6 +137,23 @@ const FileItem = ({
pdfViewerLink={pdfViewerLink}
/>
);
} else if (
MimeTypes.isDocument(mimetype) ||
MimeTypes.isPresentation(mimetype) ||
MimeTypes.isSpreadsheet(mimetype)
) {
return (
<Box height='100%' width='100%' id={id}>
<FileDocument uri={url} />
<DownloadButtonFileItem
id={id}
name={originalFileName ?? item.name}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to show the item.name

Suggested change
name={originalFileName ?? item.name}
name={item.name}

url={url}
text={downloadText}
onClick={onClick}
/>
</Box>
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/items/SizingWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const SizingWrapper = ({
}): JSX.Element => {
const width = getWidthFromSizing(size);
return (
<Box maxWidth='100%' width={width}>
<Box maxWidth='100%' width={width} flex={1}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be careful here, why do you need flex=1? Add a comment, and could you please try out many different item types to be sure sizing is not broken?

{children}
</Box>
);
Expand Down
8 changes: 7 additions & 1 deletion src/items/withCaption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ export const CaptionWrapper = <T extends WithCaptionItem>({
const description = normalizeDescription(item.description);

return (
<Stack direction={direction} gap={0.5} alignItems={alignItems} width='100%'>
<Stack
direction={direction}
gap={0.5}
alignItems={alignItems}
width='100%'
flex={1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

>
{children}
<TextDisplay content={description} />
</Stack>
Expand Down
Loading