Skip to content

Commit

Permalink
fix: show line breaks in txt preview
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Mar 14, 2023
1 parent a91c531 commit 37e765d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions frontend/src/components/share/FilePreview.tsx
Expand Up @@ -2,6 +2,7 @@ import { Button, Center, Stack, Text, Title } from "@mantine/core";
import { modals } from "@mantine/modals";
import Link from "next/link";
import React, { Dispatch, SetStateAction, useEffect, useState } from "react";
import api from "../../services/api.service";

const FilePreviewContext = React.createContext<{
shareId: string;
Expand Down Expand Up @@ -58,7 +59,7 @@ const FileDecider = () => {
return <ImagePreview />;
} else if (mimeType.startsWith("audio/")) {
return <AudioPreview />;
} else if (mimeType == "text/plain") {
} else if (mimeType.startsWith("text/")) {
return <TextPreview />;
} else {
setIsNotSupported(true);
Expand Down Expand Up @@ -115,15 +116,18 @@ const TextPreview = () => {
const [text, setText] = useState<string | null>(null);

useEffect(() => {
fetch(`/api/shares/${shareId}/files/${fileId}?download=false`)
.then((res) => res.text())
.then((text) => setText(text));
api.get(`/shares/${shareId}/files/${fileId}?download=false`).then((res) => {
console.log(res.data);
setText(res.data);
});
}, [shareId, fileId]);

return (
<Center style={{ minHeight: 200 }}>
<Stack align="center" spacing={10} style={{ width: "100%" }}>
<Text size="sm">{text}</Text>
<Text sx={{ whiteSpace: "pre-wrap" }} size="sm">
{text}
</Text>
</Stack>
</Center>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/share.service.ts
Expand Up @@ -61,7 +61,7 @@ const doesFileSupportPreview = (fileName: string) => {
mimeType.startsWith("video/"),
mimeType.startsWith("image/"),
mimeType.startsWith("audio/"),
mimeType == "text/plain",
mimeType.startsWith("text/"),
mimeType == "application/pdf",
];

Expand Down

0 comments on commit 37e765d

Please sign in to comment.