From f8e67af962c60828addd24cecbc2c746d1adbb44 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Mon, 16 May 2022 19:32:58 +0100 Subject: [PATCH] fix: allow viewing text files > 100kB closes #35 --- external/lang | 2 +- .../common/messaging/attachments/TextFile.tsx | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/external/lang b/external/lang index 74f2b711..fd152393 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit 74f2b7110db5abb5cde74903378b0c418e4ffb14 +Subproject commit fd152393e48ccea8e5e6fdd6bd99fbc343c5b56d diff --git a/src/components/common/messaging/attachments/TextFile.tsx b/src/components/common/messaging/attachments/TextFile.tsx index 6b2d32fb..b967c11a 100644 --- a/src/components/common/messaging/attachments/TextFile.tsx +++ b/src/components/common/messaging/attachments/TextFile.tsx @@ -2,6 +2,7 @@ import axios from "axios"; import { API } from "revolt.js"; import styles from "./Attachment.module.scss"; +import { Text } from "preact-i18n"; import { useContext, useEffect, useState } from "preact/hooks"; import RequiresOnline from "../../../../context/revoltjs/RequiresOnline"; @@ -11,6 +12,7 @@ import { } from "../../../../context/revoltjs/RevoltClient"; import Preloader from "../../../ui/Preloader"; +import { Button } from "@revoltchat/ui"; interface Props { attachment: API.File; @@ -19,6 +21,7 @@ interface Props { const fileCache: { [key: string]: string } = {}; export default function TextFile({ attachment }: Props) { + const [gated, setGated] = useState(attachment.size > 100_000); const [content, setContent] = useState(undefined); const [loading, setLoading] = useState(false); const status = useContext(StatusContext); @@ -29,13 +32,7 @@ export default function TextFile({ attachment }: Props) { useEffect(() => { if (typeof content !== "undefined") return; if (loading) 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; - } + if (gated) return; setLoading(true); @@ -60,13 +57,17 @@ export default function TextFile({ attachment }: Props) { setLoading(false); }); } - }, [content, loading, status, attachment._id, attachment.size, url]); + }, [content, loading, gated, status, attachment._id, attachment.size, url]); return (
- {content ? ( + {gated ? ( + + ) : content ? (
                     {content}