From 8ad319bc13fc6d2dd23f592404d0c3872d53ee6a Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Fri, 6 Aug 2021 21:52:19 +0200 Subject: [PATCH] improved simple text opener --- src/components/TextOpener.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/TextOpener.tsx b/src/components/TextOpener.tsx index cd73130..02bc975 100644 --- a/src/components/TextOpener.tsx +++ b/src/components/TextOpener.tsx @@ -1,13 +1,24 @@ import React from "react" import PropTypes from "prop-types" import { FileOpenerProps } from "../types/FileOpenerProps" +import { useEffect } from "react" +import { useState } from "react" +import genDownloadLink from "../functions/genDownloadLink" const TextOpener: React.FC = (props) => { + + const [text,setText] = useState("") + + useEffect(()=>{ + if (props.active){ + fetch(genDownloadLink(props.file.id)).then((res)=>res.text()) + .then((result)=>setText(result)) + } + },[props.file]) + return (
- +