Skip to content

Commit

Permalink
fix create document thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
ibastawisi committed Jan 13, 2025
1 parent 8137b6a commit e9b35a4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/DocumentCardThumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const DocumentCardThumbnail: React.FC<{ documentId?: string, head?: string }> =
const [thumbnail, setThumbnail] = useState(head ? thumbnailCache.get(head) : null);

useEffect(() => {
if (!documentId || !head || thumbnail) return;
if (!documentId || !head) return;
getDocumentThumbnail(documentId, head).then(setThumbnail);
}, [thumbnail]);
}, [documentId, head]);

if (thumbnail) return <Box className='document-thumbnail' dangerouslySetInnerHTML={{ __html: thumbnail.replaceAll('<a', '<span').replaceAll('</a', '</span') }} />;
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Documents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const Documents: React.FC<{ staticDocuments: UserDocument[] }> = ({ staticDocume
<Avatar sx={{ my: 2, bgcolor: 'primary.main' }}><PostAdd /></Avatar>
<Button variant="outlined" component={RouterLink} prefetch={false} href="/new">New document</Button>
</Box>
<Box sx={{ display: "flex", flexWrap: "wrap", justifyContent: { xs: "space-around", sm: "space-between" }, alignItems: "center", position: "sticky", top: { 'xs': 55.99, 'sm': 63.99 }, backgroundColor: 'var(--mui-palette-background-default)', zIndex: 2, py: 1 }}>
<Box sx={{ display: "flex", flexWrap: "wrap", justifyContent: { xs: "space-around", sm: "space-between" }, alignItems: "center", position: "sticky", top: { 'xs': 55.99, 'sm': 63.99 }, backgroundColor: 'var(--mui-palette-background-default)', zIndex: 5, py: 1 }}>
<Typography variant="h6" component="h2" sx={{ display: { xs: 'none', sm: 'block' } }}>Documents</Typography>
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 0.5, justifyContent: "center", mb: 1 }}>
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 0.5, justifyContent: "center" }}>
Expand Down
5 changes: 2 additions & 3 deletions src/components/NewDocument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ const NewDocument: React.FC = () => {
if (localResponse.type === actions.forkLocalDocument.fulfilled.type) {
const editorDocument = localResponse.payload as ReturnType<typeof actions.forkLocalDocument.fulfilled>["payload"];
const { data, ...rest } = editorDocument;
const editorDocumentSize = new Blob([JSON.stringify(editorDocument)]).size;
const localDocument = { ...rest, revisions: [], size: editorDocumentSize, thumbnail: null };
const localDocument = { ...rest, revisions: [] };
setBase({ id: editorDocument.id, local: localDocument });
setInput({ ...input, data, baseId: editorDocument.id });
} else {
Expand Down Expand Up @@ -162,7 +161,7 @@ const NewDocument: React.FC = () => {
<Typography component="h1" variant="h5">{baseId ? "Fork a document" : "Create a new document"}</Typography>
{baseId && <>
<Typography variant="overline" sx={{ color: 'text.secondary', my: 1 }}>Based on</Typography>
<DocumentCard userDocument={base} sx={{ width: 396 }} />
<DocumentCard userDocument={base} user={user} sx={{ width: 396 }} />
</>}
<Box component="form" onSubmit={handleSubmit} noValidate autoComplete="off" spellCheck="false" sx={{ mt: 1 }}>
<TextField margin="normal" size="small" fullWidth autoFocus
Expand Down
2 changes: 1 addition & 1 deletion src/components/User/UserDocuments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const UserDocuments: React.FC<{ documents?: UserDocument[] }> = ({ documents })
return (
<Box sx={{ display: 'flex', flexDirection: "column", flex: 1 }}>
{!showLoading && !showEmpty && <>
<Box sx={{ display: "flex", flexWrap: "wrap", justifyContent: 'space-between', alignItems: "center", gap: 1, minHeight: 40, position: "sticky", top: { 'xs': 55.99, 'sm': 63.99 }, backgroundColor: 'var(--mui-palette-background-default)', zIndex: 2, py: 1 }}>
<Box sx={{ display: "flex", flexWrap: "wrap", justifyContent: 'space-between', alignItems: "center", gap: 1, minHeight: 40, position: "sticky", top: { 'xs': 55.99, 'sm': 63.99 }, backgroundColor: 'var(--mui-palette-background-default)', zIndex: 5, py: 1 }}>
<Typography variant="h6" component="h2" sx={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>Published Documents</Typography>
<DocumentSortControl value={sort} setValue={setSort} />
</Box>
Expand Down

0 comments on commit e9b35a4

Please sign in to comment.