From 1f7845aa221b486abb0f51bdc156d2bed5c0e16a Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 10 Sep 2019 00:15:13 +0200 Subject: [PATCH] code fixes --- .../src/components/organisms/AssetsUser.tsx | 81 +++++++++---------- client/src/utils/cleanupContentType.ts | 35 ++++---- 2 files changed, 57 insertions(+), 59 deletions(-) diff --git a/client/src/components/organisms/AssetsUser.tsx b/client/src/components/organisms/AssetsUser.tsx index f0d828d..70fa119 100644 --- a/client/src/components/organisms/AssetsUser.tsx +++ b/client/src/components/organisms/AssetsUser.tsx @@ -10,6 +10,8 @@ export default class AssetsUser extends PureComponent< { list?: boolean; recent?: number }, { results: any[]; isLoading: boolean } > { + public static contextType = User + public state = { results: [], isLoading: true } public _isMounted = false @@ -58,51 +60,46 @@ export default class AssetsUser extends PureComponent< public render() { const { account } = this.context + const { recent, list } = this.props + const { isLoading, results } = this.state + + if (!account) return null return ( - account && ( -
- {this.props.recent && ( -

- Your Latest Published Data Sets -

- )} +
+ {this.props.recent && ( +

+ Your Latest Published Data Sets +

+ )} - {this.state.isLoading ? ( - - ) : this.state.results.length ? ( - <> - {this.state.results - .slice( - 0, - this.props.recent - ? this.props.recent - : undefined - ) - .filter(asset => !!asset) - .map((asset: any) => ( - - ))} - {this.props.recent && ( - - All Data Sets - - )} - - ) : ( -
-

No Data Sets Yet.

- + Publish A Data Set -
- )} -
- ) + {isLoading ? ( + + ) : results.length ? ( + <> + {results + .slice(0, recent ? recent : undefined) + .filter(asset => !!asset) + .map((asset: any) => ( + + ))} + {recent && ( + + All Data Sets + + )} + + ) : ( +
+

No Data Sets Yet.

+ + Publish A Data Set +
+ )} +
) } } - -AssetsUser.contextType = User diff --git a/client/src/utils/cleanupContentType.ts b/client/src/utils/cleanupContentType.ts index 0ec5c31..bcc53ab 100644 --- a/client/src/utils/cleanupContentType.ts +++ b/client/src/utils/cleanupContentType.ts @@ -7,23 +7,24 @@ const cleanupContentType = (contentType: string) => { let contentTypeCleaned // TODO: add all the possible archive & compression MIME types - if ( - contentType === 'application/x-lzma' || - contentType === 'application/x-xz' || - contentType === 'application/x-tar' || - contentType === 'application/x-gtar' || - contentType === 'application/x-bzip2' || - contentType === 'application/x-gzip' || - contentType === 'application/x-7z-compressed' || - contentType === 'application/x-rar-compressed' || - contentType === 'application/x-zip-compressed' || - contentType === 'application/x-apple-diskimage' - ) { - contentTypeCleaned = contentTypeSplit - .replace('x-', '') - .replace('-compressed', '') - } else { - contentTypeCleaned = contentTypeSplit + switch (contentType) { + case 'application/x-lzma': + case 'application/x-xz': + case 'application/x-tar': + case 'application/x-gtar': + case 'application/x-bzip2': + case 'application/x-gzip': + case 'application/x-7z-compressed': + case 'application/x-rar-compressed': + case 'application/x-zip-compressed': + case 'application/x-apple-diskimage': + contentTypeCleaned = contentTypeSplit + .replace('x-', '') + .replace('-compressed', '') + break + default: + contentTypeCleaned = contentTypeSplit + break } // Manual replacements