diff --git a/src/components/AudioOpener.tsx b/src/components/AudioOpener.tsx new file mode 100644 index 0000000..d6fc436 --- /dev/null +++ b/src/components/AudioOpener.tsx @@ -0,0 +1,41 @@ +import React from "react" +import { useEffect } from "react" +import genDownloadLink from "../functions/genDownloadLink" +import { FileOpenerProps } from "../types/FileOpenerProps" + +const AudioOpener: React.FC = (props) => { + + let audio: HTMLAudioElement + + useEffect(()=>{ + if (audio){ + audio.pause() + audio.remove() + } + + audio = new Audio(genDownloadLink(props.file.id)) + audio.volume = 0.1 + },[props.file]) + + useEffect(()=>{ + if(!props.active){ + audio.pause + console.debug("Pause") + } + console.debug("active",props.active) + },[props.active]) + + return ( +
+ +
+ ) +} + +export default AudioOpener diff --git a/src/components/FileOpen.tsx b/src/components/FileOpen.tsx index 60b6a84..0f9c420 100644 --- a/src/components/FileOpen.tsx +++ b/src/components/FileOpen.tsx @@ -4,6 +4,7 @@ import { useGetFileQuery } from "../generated/graphql" import ImageOpener from "./ImageOpener" import TextOpener from "./TextOpener" import Modal from "./Modal" +import AudioOpener from "./AudioOpener" interface Props { id: string @@ -28,9 +29,9 @@ const FileOpen: React.FC = (props) => { if(data?.file != null){ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types if (data.file.contentType?.startsWith("image/")){ - opener = + opener = }else if (data.file.contentType?.startsWith("text/")){ - opener = + opener = }else{ // Get Opener bases on file extension const ext = data.file.name?.split(".").pop() @@ -40,14 +41,17 @@ const FileOpen: React.FC = (props) => { case "jpeg": case "gif": // TODO: more ext - opener = + opener = break case "txt": case "md": - opener = + opener = + break + case "mp3": + opener = break default: - opener = + opener = break } } diff --git a/src/components/ImageOpener.tsx b/src/components/ImageOpener.tsx index d22dcf1..38bdb4d 100644 --- a/src/components/ImageOpener.tsx +++ b/src/components/ImageOpener.tsx @@ -1,18 +1,12 @@ import React from "react" import PropTypes from "prop-types" -import { File } from "../generated/graphql" import genDownloadLink from "../functions/genDownloadLink" import style from "./../App.module.scss" +import { FileOpenerProps } from "../types/FileOpenerProps" -interface Props { - file: File -} - -const ImageOpener: React.FC = (props) => { +const ImageOpener: React.FC = (props) => { return ( -
- -
+ ) } diff --git a/src/components/TextOpener.tsx b/src/components/TextOpener.tsx index 7a5f76a..cd73130 100644 --- a/src/components/TextOpener.tsx +++ b/src/components/TextOpener.tsx @@ -1,12 +1,8 @@ import React from "react" import PropTypes from "prop-types" -import { File } from "../generated/graphql" +import { FileOpenerProps } from "../types/FileOpenerProps" -interface Props { - file: File -} - -const TextOpener: React.FC = (props) => { +const TextOpener: React.FC = (props) => { return (