mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-29 01:28:59 -05:00
fix: show line breaks in txt preview
This commit is contained in:
parent
a91c531642
commit
37e765ddc7
2 changed files with 10 additions and 6 deletions
|
@ -2,6 +2,7 @@ import { Button, Center, Stack, Text, Title } from "@mantine/core";
|
||||||
import { modals } from "@mantine/modals";
|
import { modals } from "@mantine/modals";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import React, { Dispatch, SetStateAction, useEffect, useState } from "react";
|
import React, { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||||
|
import api from "../../services/api.service";
|
||||||
|
|
||||||
const FilePreviewContext = React.createContext<{
|
const FilePreviewContext = React.createContext<{
|
||||||
shareId: string;
|
shareId: string;
|
||||||
|
@ -58,7 +59,7 @@ const FileDecider = () => {
|
||||||
return <ImagePreview />;
|
return <ImagePreview />;
|
||||||
} else if (mimeType.startsWith("audio/")) {
|
} else if (mimeType.startsWith("audio/")) {
|
||||||
return <AudioPreview />;
|
return <AudioPreview />;
|
||||||
} else if (mimeType == "text/plain") {
|
} else if (mimeType.startsWith("text/")) {
|
||||||
return <TextPreview />;
|
return <TextPreview />;
|
||||||
} else {
|
} else {
|
||||||
setIsNotSupported(true);
|
setIsNotSupported(true);
|
||||||
|
@ -115,15 +116,18 @@ const TextPreview = () => {
|
||||||
const [text, setText] = useState<string | null>(null);
|
const [text, setText] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`/api/shares/${shareId}/files/${fileId}?download=false`)
|
api.get(`/shares/${shareId}/files/${fileId}?download=false`).then((res) => {
|
||||||
.then((res) => res.text())
|
console.log(res.data);
|
||||||
.then((text) => setText(text));
|
setText(res.data);
|
||||||
|
});
|
||||||
}, [shareId, fileId]);
|
}, [shareId, fileId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Center style={{ minHeight: 200 }}>
|
<Center style={{ minHeight: 200 }}>
|
||||||
<Stack align="center" spacing={10} style={{ width: "100%" }}>
|
<Stack align="center" spacing={10} style={{ width: "100%" }}>
|
||||||
<Text size="sm">{text}</Text>
|
<Text sx={{ whiteSpace: "pre-wrap" }} size="sm">
|
||||||
|
{text}
|
||||||
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Center>
|
</Center>
|
||||||
);
|
);
|
||||||
|
|
|
@ -61,7 +61,7 @@ const doesFileSupportPreview = (fileName: string) => {
|
||||||
mimeType.startsWith("video/"),
|
mimeType.startsWith("video/"),
|
||||||
mimeType.startsWith("image/"),
|
mimeType.startsWith("image/"),
|
||||||
mimeType.startsWith("audio/"),
|
mimeType.startsWith("audio/"),
|
||||||
mimeType == "text/plain",
|
mimeType.startsWith("text/"),
|
||||||
mimeType == "application/pdf",
|
mimeType == "application/pdf",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue