-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathHeader.js
More file actions
137 lines (126 loc) · 4.84 KB
/
Header.js
File metadata and controls
137 lines (126 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import React from 'react'
import classNames from 'classnames'
import { connect } from 'redux-bundler-react'
import { withTranslation } from 'react-i18next'
import { humanSize } from '../../lib/files.js'
// Components
import Breadcrumbs from '../breadcrumbs/Breadcrumbs.js'
import FileInput from '../file-input/FileInput.js'
import Button from '../../components/button/button.tsx'
// Icons
import GlyphDots from '../../icons/GlyphDots.js'
import GlyphPinCloud from '../../icons/GlyphPinCloud.js'
import '../PendingAnimation.css'
const BarOption = ({ children, text, isLink = false, className = '', ...etc }) => (
<div className={classNames(className, 'tc pa3', etc.onClick && 'pointer')} {...etc}>
<span className='nowrap db f4 charcoal'>{children}</span>
<span className={`nowrap db ttu f6 montserrat fw4 ${isLink ? 'link' : 'charcoal-muted'}`}>{text}</span>
</div>
)
// Tweak human-readable size format to be more compact
const size = (s) => humanSize(s, {
round: s >= 1073741824 ? 1 : 0, // show decimal > 1GiB
spacer: ''
})
class Header extends React.Component {
handleContextMenu = (ev) => {
const pos = this.dotsWrapper.getBoundingClientRect()
this.props.handleContextMenu(ev, 'TOP', {
...this.props.files,
// TODO: change to "pinning" and not "pinned"
pinned: this.props.pins.includes(this.props.files.cid.toString())
}, pos)
}
handleBreadCrumbsContextMenu = (ev, breadcrumbsRef, file) => {
const pos = breadcrumbsRef.getBoundingClientRect()
this.props.handleContextMenu(ev, 'TOP', file, pos)
}
render () {
const {
currentDirectorySize,
hasUpperDirectory,
files,
filesPathInfo,
filesSize,
onNavigate,
repoSize,
pendingPins,
failedPins,
completedPins,
t,
children
} = this.props
const pinsInQueue = pendingPins.length + failedPins.length + completedPins.length
return (
<div className='db flex-l justify-between items-center mb3'>
<div className='flex items-center w-100 justify-between mr3'>
<div className='breadheader overflow-hidden mr1'>
<Breadcrumbs className="joyride-files-breadcrumbs" path={files ? files.path : '/404'}
onClick={onNavigate} onContextMenuHandle={(...args) => this.handleBreadCrumbsContextMenu(...args)}
onAddFiles={this.props.onAddFiles} onMove={this.props.onMove}/>
</div>
{ children }
</div>
<div className='flex justify-between items-center bg-snow-muted joyride-files-add'>
{ pinsInQueue > 0 && <a href='#/pins' alt={t('pinningQueue')} title={t('pinningQueue')} className='ml3'>
<GlyphPinCloud
style={{ width: '3rem' }}
className='fill-teal PendingAnimation' />
</a> }
<BarOption title={t('currentLocationDescription')} text={hasUpperDirectory ? t('currentLocation') : t('currentLocationRoot')}>
{ hasUpperDirectory
? (
<span>
{ size(currentDirectorySize) }<span className='f5 gray'>/{ size(filesSize) }</span>
</span>
)
: size(filesSize) }
</BarOption>
<BarOption title={t('localDatastoreDescription')} text={t('localDatastore')}>
{ size(repoSize) }
</BarOption>
<div className='pa3'>
<div className='ml-auto flex items-center'>
{ (files && files.type === 'directory' && filesPathInfo.isMfs)
? <FileInput
onNewFolder={this.props.onNewFolder}
onAddFiles={this.props.onAddFiles}
onAddByPath={this.props.onAddByPath}
onAddByCar={this.props.onAddByCar}
onBulkCidImport={this.props.onBulkCidImport}
onSyncFromPins={this.props.onSyncFromPins}
onCliTutorMode={this.props.onCliTutorMode}
/>
: <div ref={el => { this.dotsWrapper = el }}>
<Button bg='bg-navy'
color='white'
fill='fill-aqua'
className='f6 relative flex justify-center items-center tc'
minWidth='100px'
disabled={!files || filesPathInfo.isRoot || files.type === 'unknown'}
onClick={this.handleContextMenu}>
<GlyphDots className='w1 mr2' />
{ t('app:actions.more') }
</Button>
</div>
}
</div>
</div>
</div>
</div>
)
}
}
export default connect(
'selectPins',
'selectHasUpperDirectory',
'selectFilesSize',
'selectRepoSize',
'selectRepoNumObjects',
'selectFilesPathInfo',
'selectCurrentDirectorySize',
'selectPendingPins',
'selectFailedPins',
'selectCompletedPins',
withTranslation('files')(Header)
)