1+ import { useQuery } from '@apollo/react-hooks' ;
2+ import gql from 'graphql-tag' ;
3+ import React from 'react' ;
4+ import { Card , Container , Loader , Menu } from 'semantic-ui-react' ;
5+ import { XFileCard , XFileUploadModal } from '../components/file' ;
6+ import { XErrorMessage } from '../components/messages' ;
7+ export const MULTI_FILE_QUERY = gql `
8+ {
9+ files {
10+ id
11+ name
12+ contentType
13+ size
14+ creationTime
15+ lastModifiedTime
16+
17+ links {
18+ id
19+ alias
20+ clicks
21+ expirationTime
22+ }
23+ }
24+ }`
25+
26+ const XMultiFileView = ( ) => {
27+ const { called, loading, error, data } = useQuery ( MULTI_FILE_QUERY , {
28+ pollInterval : 5000 ,
29+ } ) ;
30+
31+ const showCards = ( ) => {
32+ if ( ! data || ! data . files || data . files . length < 1 ) {
33+ return (
34+ // TODO: Better styling
35+ < h1 > No files found!</ h1 >
36+ ) ;
37+ }
38+ return ( < Card . Group centered itemsPerRow = { 4 } >
39+ { data . files . map ( file => ( < XFileCard key = { file . id } { ...file } /> ) ) }
40+ </ Card . Group > ) ;
41+ } ;
42+
43+ return (
44+ < Container style = { { padding : '10px' } } >
45+ < Menu secondary >
46+ < Menu . Item position = 'right' > < XFileUploadModal /> </ Menu . Item >
47+ </ Menu >
48+ < Container fluid style = { { padding : '20px' } } >
49+ < Loader disabled = { ! called || ! loading } />
50+ < XErrorMessage title = 'Error Loading Files' err = { error } />
51+ { showCards ( ) }
52+ </ Container >
53+ </ Container >
54+ ) ;
55+ }
56+
57+ // XTargetCardGroup.propTypes = {
58+ // targets: PropTypes.arrayOf(PropTypes.shape({
59+ // id: PropTypes.number.isRequired,
60+ // name: PropTypes.string.isRequired,
61+ // tags: PropTypes.arrayOf(PropTypes.string),
62+ // })).isRequired,
63+ // };
64+
65+ export default XMultiFileView
0 commit comments