added file size

This commit is contained in:
Djeeberjr 2021-07-27 21:24:20 +02:00
parent c20e894d52
commit a24ed03e1f
7 changed files with 465 additions and 452 deletions

View File

@ -10,10 +10,10 @@ const DirectoryElement: React.FC<Props> = (props) => {
return (
<>
<td>
📂
📂 {props.dir.name}
</td>
<td>
{props.dir.name}
</td>
</>
)

View File

@ -16,15 +16,14 @@ const FileBrowser: React.FC = () => {
return (
<div>
<Breadcrum path={path} onDirClick={(newPath)=>{
console.debug(newPath)
setPath(newPath)
}}/>
<div>
<table className="table table-striped table-hover">
<thead>
<tr>
<th>Icon</th>
<th>Name</th>
<th>Size</th>
</tr>
</thead>
<tbody>

View File

@ -1,6 +1,7 @@
import React from "react"
import PropTypes from "prop-types"
import { File } from "../generated/graphql"
import sizeToReadable from "../functions/sizeToReadable"
interface Props {
file: File
@ -10,10 +11,10 @@ const FileElement: React.FC<Props> = (props) => {
return (
<>
<td>
📄
📄 {props.file.name}
</td>
<td>
{props.file.name}
{sizeToReadable(props.file.size)}
</td>
</>
)

View File

@ -0,0 +1,7 @@
function sizeToReadable(size: number): string {
const i = Math.floor(Math.log(size) / Math.log(1024))
return (size / Math.pow(1024, i)).toFixed(2) + " " + ["B", "kB", "MB", "GB", "TB"][i]
}
export default sizeToReadable

View File

@ -33,7 +33,7 @@ export type File = {
id: Scalars["ID"];
name?: Maybe<Scalars["String"]>;
parent?: Maybe<Directory>;
size?: Maybe<Scalars["Int"]>;
size: Scalars["Int"];
};
export type RootQuery = {
@ -67,7 +67,7 @@ export type OpenDirQuery = (
{ __typename?: "RootQuery" }
& { files: Array<Maybe<(
{ __typename?: "File" }
& Pick<File, "id" | "name">
& Pick<File, "id" | "name" | "size">
)>>, directorys: Array<Maybe<(
{ __typename?: "Directory" }
& Pick<Directory, "id" | "name">
@ -80,6 +80,7 @@ export const OpenDirDocument = gql`
files(path: $path) {
id
name
size
}
directorys(path: $path) {
id

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ query openDir($path: String!) {
files(path:$path){
id
name
size
}
directorys(path: $path){
id