Skip to content

Commit b8fb52a

Browse files
committed
🚧(wip) proof of concept for grist-static preview
1 parent 11c1e4e commit b8fb52a

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed
3.13 MB
Binary file not shown.

src/frontend/apps/drive/src/features/explorer/components/icons/ItemIcon.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ export const getItemIcon = (
9797

9898
export const getIconByMimeType = (
9999
mimeType: string,
100-
type: "mini" | "normal"
100+
type: "mini" | "normal",
101+
extension?: string
101102
) => {
102-
const category = getMimeCategory(mimeType);
103+
const category = getMimeCategory(mimeType, extension);
103104
return ICONS[type][category];
104105
};
105106

src/frontend/apps/drive/src/features/ui/preview/files-preview/FilesPreview.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ImageViewer } from "../image-viewer/ImageViewer";
1111
import { VideoPlayer } from "../video-player/VideoPlayer";
1212
import { AudioPlayer } from "../audio-player/AudioPlayer";
1313
import { PreviewPdf } from "../pdf-preview/PreviewPdf";
14+
import { PreviewGrist } from "../grist-preview/PreviewGrist";
1415

1516
import { NotSupportedPreview } from "../not-supported/NotSupportedPreview";
1617
import { getIconByMimeType } from "@/features/explorer/components/icons/ItemIcon";
@@ -22,6 +23,7 @@ export type FilePreviewType = {
2223
title: string;
2324
mimetype: string;
2425
url: string;
26+
extension?: string | null;
2527
};
2628

2729
type FilePreviewData = FilePreviewType & {
@@ -56,9 +58,10 @@ export const FilePreview = ({
5658
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
5759

5860
const data: FilePreviewData[] = useMemo(() => {
59-
return files?.map((file) => ({
61+
return files?.map((file) => (
62+
{
6063
...file,
61-
category: getMimeCategory(file.mimetype),
64+
category: getMimeCategory(file.mimetype, file.url.split('.').pop() || null),
6265
}));
6366
}, [files]);
6467

@@ -109,6 +112,9 @@ export const FilePreview = ({
109112
);
110113
case MimeCategory.PDF:
111114
return <PreviewPdf src={currentFile.url} />;
115+
case MimeCategory.GRIST:
116+
console.log(currentFile.url);
117+
return <PreviewGrist src={currentFile.url} title={currentFile.title}/>;
112118
default:
113119
return <NotSupportedPreview file={currentFile} />;
114120
}
@@ -148,7 +154,7 @@ export const FilePreview = ({
148154

149155
<div className="file-preview-title">
150156
<img
151-
src={getIconByMimeType(currentFile.mimetype, "mini").src}
157+
src={getIconByMimeType(currentFile.mimetype, "mini", currentFile.url.split('.').pop()).src}
152158
alt=""
153159
width={24}
154160
className={`item-icon`}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { useEffect } from 'react';
2+
3+
interface PreviewGristProps {
4+
title?: string;
5+
src?: string;
6+
}
7+
8+
export const PreviewGrist = ({ src, title }: PreviewGristProps) => {
9+
useEffect(() => {
10+
if (src) {
11+
const script = document.createElement('script');
12+
script.src = 'https://grist-static.com/latest.js';
13+
script.onload = () => {
14+
// Assuming bootstrapGrist is globally available
15+
if (window) {
16+
window.bootstrapGrist?.({
17+
initialFile: "/gristtest.grist", // Todo: use src instead (gots to figure out that CORS issue with NGINX...)
18+
name: title || "Grist document",
19+
elementId: 'grist-app',
20+
singlePage: false,
21+
});
22+
}};
23+
document.body.appendChild(script);
24+
}
25+
}, [src]);
26+
return (
27+
<div className='grist-preview'>
28+
<div id="grist-app" className='grist-preview__app'></div>
29+
</div>
30+
);
31+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.grist-preview {
2+
height: 100%;
3+
padding: 1rem;
4+
}
5+
6+
.grist-preview__app {
7+
height: 100%;
8+
}

src/frontend/apps/drive/src/features/ui/preview/preview.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
@use "./components/volume-bar/VolumeBar.scss";
88
@use "./components/controls/PreviewControls.scss";
99
@use "./not-supported/NotSupportedPreview.scss";
10+
@use "./grist-preview/grist-preview.scss";

0 commit comments

Comments
 (0)