Compare commits
3 Commits
713a96efc5
...
da85c3070c
| Author | SHA1 | Date | |
|---|---|---|---|
| da85c3070c | |||
| 21ae838025 | |||
| 318343e731 |
@@ -12,3 +12,5 @@ generates:
|
|||||||
- "typescript-react-apollo"
|
- "typescript-react-apollo"
|
||||||
config:
|
config:
|
||||||
withHooks: true
|
withHooks: true
|
||||||
|
scalars:
|
||||||
|
DateTime: string
|
||||||
@@ -13,7 +13,8 @@ const DirectoryElement: React.FC<Props> = (props) => {
|
|||||||
📂 {props.dir.name}
|
📂 {props.dir.name}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
</td>
|
</td>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
|
import uploadFile from "../functions/uploadFile"
|
||||||
import { useOpenDirQuery } from "../generated/graphql"
|
import { useOpenDirQuery } from "../generated/graphql"
|
||||||
import Breadcrum from "./Breadcrum"
|
import Breadcrum from "./Breadcrum"
|
||||||
import DragAndDrop from "./DragAndDrop"
|
import DragAndDrop from "./DragAndDrop"
|
||||||
@@ -17,17 +18,22 @@ const FileBrowser: React.FC = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleDrop(files:FileList) {
|
async function handleDrop(files:FileList) {
|
||||||
|
const wait: Promise<boolean>[] = []
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i]
|
const file = files[i]
|
||||||
console.debug(file) // TODO
|
wait.push(uploadFile(file, path + file.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Promise.all(wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<DragAndDrop
|
<DragAndDrop
|
||||||
handleDrop={handleDrop}
|
handleDrop={async (files)=>{
|
||||||
|
await handleDrop(files)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Breadcrum path={path} onDirClick={(newPath)=>{
|
<Breadcrum path={path} onDirClick={(newPath)=>{
|
||||||
setPath(newPath)
|
setPath(newPath)
|
||||||
@@ -40,6 +46,7 @@ const FileBrowser: React.FC = () => {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
<th>Last Modified</th>
|
||||||
<th>Size</th>
|
<th>Size</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React from "react"
|
|||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { File } from "../generated/graphql"
|
import { File } from "../generated/graphql"
|
||||||
import sizeToReadable from "../functions/sizeToReadable"
|
import sizeToReadable from "../functions/sizeToReadable"
|
||||||
|
import dateFormat from "../functions/dateFomat"
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
file: File
|
file: File
|
||||||
@@ -13,9 +14,13 @@ const FileElement: React.FC<Props> = (props) => {
|
|||||||
<td>
|
<td>
|
||||||
📄 {props.file.name}
|
📄 {props.file.name}
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
{dateFormat(props.file.lastModified)}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{sizeToReadable(props.file.size)}
|
{sizeToReadable(props.file.size)}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/functions/dateFomat.ts
Normal file
19
src/functions/dateFomat.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Transforms the DateTime given from the api to a human readable format
|
||||||
|
* @param date Date in ISO 8601 fomat
|
||||||
|
*/
|
||||||
|
function dateFormat(date:string | undefined | null): string {
|
||||||
|
if (!date) return ""
|
||||||
|
|
||||||
|
const parsedDate = new Date(date)
|
||||||
|
const now = new Date()
|
||||||
|
|
||||||
|
if (parsedDate.toDateString() === now.toDateString()){
|
||||||
|
return parsedDate.toLocaleTimeString()
|
||||||
|
}else{
|
||||||
|
return parsedDate.toLocaleDateString()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default dateFormat
|
||||||
17
src/functions/uploadFile.ts
Normal file
17
src/functions/uploadFile.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
async function uploadFile(file:File,id: string): Promise<boolean> {
|
||||||
|
|
||||||
|
console.debug(file)
|
||||||
|
|
||||||
|
|
||||||
|
const res = await fetch(`/api/file?${new URLSearchParams({id:id}).toString()}`,{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": file.type
|
||||||
|
},
|
||||||
|
body: file
|
||||||
|
})
|
||||||
|
|
||||||
|
return res.status == 200
|
||||||
|
}
|
||||||
|
|
||||||
|
export default uploadFile
|
||||||
@@ -12,8 +12,11 @@ export type Scalars = {
|
|||||||
Boolean: boolean;
|
Boolean: boolean;
|
||||||
Int: number;
|
Int: number;
|
||||||
Float: number;
|
Float: number;
|
||||||
|
/** DateTime is a DateTime in ISO 8601 format */
|
||||||
|
DateTime: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Represents a directory */
|
/** Represents a directory */
|
||||||
export type Directory = {
|
export type Directory = {
|
||||||
__typename?: "Directory";
|
__typename?: "Directory";
|
||||||
@@ -31,6 +34,7 @@ export type File = {
|
|||||||
etag?: Maybe<Scalars["String"]>;
|
etag?: Maybe<Scalars["String"]>;
|
||||||
/** The uniqe ID of the file. Represents the path and the s3 key. */
|
/** The uniqe ID of the file. Represents the path and the s3 key. */
|
||||||
id: Scalars["ID"];
|
id: Scalars["ID"];
|
||||||
|
lastModified?: Maybe<Scalars["DateTime"]>;
|
||||||
name?: Maybe<Scalars["String"]>;
|
name?: Maybe<Scalars["String"]>;
|
||||||
parent?: Maybe<Directory>;
|
parent?: Maybe<Directory>;
|
||||||
size: Scalars["Int"];
|
size: Scalars["Int"];
|
||||||
@@ -80,7 +84,7 @@ export type OpenDirQuery = (
|
|||||||
{ __typename?: "RootQuery" }
|
{ __typename?: "RootQuery" }
|
||||||
& { files: Array<Maybe<(
|
& { files: Array<Maybe<(
|
||||||
{ __typename?: "File" }
|
{ __typename?: "File" }
|
||||||
& Pick<File, "id" | "name" | "size">
|
& Pick<File, "id" | "name" | "size" | "lastModified">
|
||||||
)>>, directorys: Array<Maybe<(
|
)>>, directorys: Array<Maybe<(
|
||||||
{ __typename?: "Directory" }
|
{ __typename?: "Directory" }
|
||||||
& Pick<Directory, "id" | "name">
|
& Pick<Directory, "id" | "name">
|
||||||
@@ -133,6 +137,7 @@ export const OpenDirDocument = gql`
|
|||||||
id
|
id
|
||||||
name
|
name
|
||||||
size
|
size
|
||||||
|
lastModified
|
||||||
}
|
}
|
||||||
directorys(path: $path) {
|
directorys(path: $path) {
|
||||||
id
|
id
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ query openDir($path: String!) {
|
|||||||
id
|
id
|
||||||
name
|
name
|
||||||
size
|
size
|
||||||
|
lastModified
|
||||||
}
|
}
|
||||||
directorys(path: $path){
|
directorys(path: $path){
|
||||||
id
|
id
|
||||||
|
|||||||
Reference in New Issue
Block a user