mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-22 07:00:58 -05:00
parent
0e5f64afd6
commit
f8e67af962
2 changed files with 11 additions and 10 deletions
2
external/lang
vendored
2
external/lang
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 74f2b7110db5abb5cde74903378b0c418e4ffb14
|
Subproject commit fd152393e48ccea8e5e6fdd6bd99fbc343c5b56d
|
|
@ -2,6 +2,7 @@ import axios from "axios";
|
||||||
import { API } from "revolt.js";
|
import { API } from "revolt.js";
|
||||||
|
|
||||||
import styles from "./Attachment.module.scss";
|
import styles from "./Attachment.module.scss";
|
||||||
|
import { Text } from "preact-i18n";
|
||||||
import { useContext, useEffect, useState } from "preact/hooks";
|
import { useContext, useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
import RequiresOnline from "../../../../context/revoltjs/RequiresOnline";
|
import RequiresOnline from "../../../../context/revoltjs/RequiresOnline";
|
||||||
|
@ -11,6 +12,7 @@ import {
|
||||||
} from "../../../../context/revoltjs/RevoltClient";
|
} from "../../../../context/revoltjs/RevoltClient";
|
||||||
|
|
||||||
import Preloader from "../../../ui/Preloader";
|
import Preloader from "../../../ui/Preloader";
|
||||||
|
import { Button } from "@revoltchat/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
attachment: API.File;
|
attachment: API.File;
|
||||||
|
@ -19,6 +21,7 @@ interface Props {
|
||||||
const fileCache: { [key: string]: string } = {};
|
const fileCache: { [key: string]: string } = {};
|
||||||
|
|
||||||
export default function TextFile({ attachment }: Props) {
|
export default function TextFile({ attachment }: Props) {
|
||||||
|
const [gated, setGated] = useState(attachment.size > 100_000);
|
||||||
const [content, setContent] = useState<undefined | string>(undefined);
|
const [content, setContent] = useState<undefined | string>(undefined);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const status = useContext(StatusContext);
|
const status = useContext(StatusContext);
|
||||||
|
@ -29,13 +32,7 @@ export default function TextFile({ attachment }: Props) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof content !== "undefined") return;
|
if (typeof content !== "undefined") return;
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
|
if (gated) return;
|
||||||
if (attachment.size > 100_000) {
|
|
||||||
setContent(
|
|
||||||
"This file is > 100 KB, for your sake I did not load it.\nSee tracking issue here for previews: https://github.com/revoltchat/revite/issues/35",
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
|
@ -60,13 +57,17 @@ export default function TextFile({ attachment }: Props) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [content, loading, status, attachment._id, attachment.size, url]);
|
}, [content, loading, gated, status, attachment._id, attachment.size, url]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={styles.textContent}
|
className={styles.textContent}
|
||||||
data-loading={typeof content === "undefined"}>
|
data-loading={typeof content === "undefined"}>
|
||||||
{content ? (
|
{gated ? (
|
||||||
|
<Button palette="accent" onClick={() => setGated(false)}>
|
||||||
|
<Text id="app.main.channel.misc.load_file" />
|
||||||
|
</Button>
|
||||||
|
) : content ? (
|
||||||
<pre>
|
<pre>
|
||||||
<code>{content}</code>
|
<code>{content}</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
Loading…
Reference in a new issue