FileOpenerProps
This commit is contained in:
parent
c4cd110fd2
commit
5a31062b21
41
src/components/AudioOpener.tsx
Normal file
41
src/components/AudioOpener.tsx
Normal file
@ -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<FileOpenerProps> = (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 (
|
||||||
|
<div>
|
||||||
|
<button onClick={()=>{
|
||||||
|
if (audio){
|
||||||
|
(audio.paused && audio.play()) || audio.pause()
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
Play/Pause
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AudioOpener
|
@ -4,6 +4,7 @@ import { useGetFileQuery } from "../generated/graphql"
|
|||||||
import ImageOpener from "./ImageOpener"
|
import ImageOpener from "./ImageOpener"
|
||||||
import TextOpener from "./TextOpener"
|
import TextOpener from "./TextOpener"
|
||||||
import Modal from "./Modal"
|
import Modal from "./Modal"
|
||||||
|
import AudioOpener from "./AudioOpener"
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
id: string
|
id: string
|
||||||
@ -28,9 +29,9 @@ const FileOpen: React.FC<Props> = (props) => {
|
|||||||
if(data?.file != null){
|
if(data?.file != null){
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
||||||
if (data.file.contentType?.startsWith("image/")){
|
if (data.file.contentType?.startsWith("image/")){
|
||||||
opener = <ImageOpener file={data?.file} />
|
opener = <ImageOpener file={data?.file} active={props.show} />
|
||||||
}else if (data.file.contentType?.startsWith("text/")){
|
}else if (data.file.contentType?.startsWith("text/")){
|
||||||
opener = <TextOpener file={data.file} />
|
opener = <TextOpener file={data.file} active={props.show} />
|
||||||
}else{
|
}else{
|
||||||
// Get Opener bases on file extension
|
// Get Opener bases on file extension
|
||||||
const ext = data.file.name?.split(".").pop()
|
const ext = data.file.name?.split(".").pop()
|
||||||
@ -40,14 +41,17 @@ const FileOpen: React.FC<Props> = (props) => {
|
|||||||
case "jpeg":
|
case "jpeg":
|
||||||
case "gif":
|
case "gif":
|
||||||
// TODO: more ext
|
// TODO: more ext
|
||||||
opener = <ImageOpener file={data.file} />
|
opener = <ImageOpener file={data.file} active={props.show} />
|
||||||
break
|
break
|
||||||
case "txt":
|
case "txt":
|
||||||
case "md":
|
case "md":
|
||||||
opener = <TextOpener file={data.file} />
|
opener = <TextOpener file={data.file} active={props.show} />
|
||||||
|
break
|
||||||
|
case "mp3":
|
||||||
|
opener = <AudioOpener file={data.file} active={props.show} />
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
opener = <ImageOpener file={data?.file} />
|
opener = <ImageOpener file={data?.file} active={props.show} />
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { File } from "../generated/graphql"
|
|
||||||
import genDownloadLink from "../functions/genDownloadLink"
|
import genDownloadLink from "../functions/genDownloadLink"
|
||||||
import style from "./../App.module.scss"
|
import style from "./../App.module.scss"
|
||||||
|
import { FileOpenerProps } from "../types/FileOpenerProps"
|
||||||
|
|
||||||
interface Props {
|
const ImageOpener: React.FC<FileOpenerProps> = (props) => {
|
||||||
file: File
|
|
||||||
}
|
|
||||||
|
|
||||||
const ImageOpener: React.FC<Props> = (props) => {
|
|
||||||
return (
|
return (
|
||||||
<div className={style.imageOpener}>
|
<img className={`img-responsive img-fit-cover ${style.imageOpenerImage}`} src={genDownloadLink(props.file.id)}/>
|
||||||
<img className={`img-responsive img-fit-contain ${style.imageOpenerImage}`} src={genDownloadLink(props.file.id)}/>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { File } from "../generated/graphql"
|
import { FileOpenerProps } from "../types/FileOpenerProps"
|
||||||
|
|
||||||
interface Props {
|
const TextOpener: React.FC<FileOpenerProps> = (props) => {
|
||||||
file: File
|
|
||||||
}
|
|
||||||
|
|
||||||
const TextOpener: React.FC<Props> = (props) => {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<textarea>
|
<textarea>
|
||||||
|
6
src/types/FileOpenerProps.ts
Normal file
6
src/types/FileOpenerProps.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { File } from "../generated/graphql"
|
||||||
|
|
||||||
|
export interface FileOpenerProps{
|
||||||
|
file: File
|
||||||
|
active: boolean
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user