-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathFileInput.js
More file actions
164 lines (146 loc) · 5.25 KB
/
FileInput.js
File metadata and controls
164 lines (146 loc) · 5.25 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React from 'react'
import { connect } from 'redux-bundler-react'
import PropTypes from 'prop-types'
import { withTranslation } from 'react-i18next'
import { normalizeFiles } from '../../lib/files.js'
// Icons
import DocumentIcon from '../../icons/StrokeDocument.js'
import FolderIcon from '../../icons/StrokeFolder.js'
import NewFolderIcon from '../../icons/StrokeNewFolder.js'
import DecentralizationIcon from '../../icons/StrokeDecentralization.js'
import DataIcon from '../../icons/StrokeData.js'
import GlyphPinCloud from '../../icons/GlyphPinCloud.js'
// Components
import { Dropdown, DropdownMenu, Option } from '../dropdown/Dropdown.js'
import Button from '../../components/button/button.tsx'
import { cliCmdKeys } from '../../bundles/files/consts.js'
const AddButton = withTranslation('app')(
({ t, onClick }) => (
<Button id='import-button' bg='bg-navy' color='white' className='f6 flex justify-center items-center' minWidth='100px' onClick={onClick}>
<span><span className='aqua'>+</span> {t('actions.import')}</span>
</Button>
)
)
class FileInput extends React.Component {
state = {
dropdown: false
}
toggleDropdown = () => {
this.setState(s => ({ dropdown: !s.dropdown }))
}
onAddFolder = () => {
this.toggleDropdown()
return this.folderInput.click()
}
onAddFile = async () => {
this.toggleDropdown()
return this.filesInput.click()
}
onInputChange = (input) => async () => {
this.props.onAddFiles(normalizeFiles(input.files))
input.value = null
}
onAddByPath = () => {
this.props.onAddByPath()
this.toggleDropdown()
}
onAddByCar = () => {
this.props.onAddByCar()
this.toggleDropdown()
}
onBulkCidImport = () => {
this.props.onBulkCidImport()
this.toggleDropdown()
}
onSyncFromPins = () => {
this.props.onSyncFromPins()
this.toggleDropdown()
}
onNewFolder = () => {
this.props.onNewFolder()
this.toggleDropdown()
}
onCliTutorMode = async (cliOptions) => {
await this.props.doSetCliOptions(cliOptions)
this.props.onCliTutorMode()
this.toggleDropdown()
}
render () {
const { t, isCliTutorModeEnabled } = this.props
return (
<div className={this.props.className}>
<Dropdown>
<AddButton onClick={this.toggleDropdown} />
<DropdownMenu
top={3}
open={this.state.dropdown}
onDismiss={this.toggleDropdown} >
<Option onClick={this.onAddFile} id='add-file' onCliTutorMode={() => this.onCliTutorMode(cliCmdKeys.ADD_FILE)}
isCliTutorModeEnabled={isCliTutorModeEnabled}>
<DocumentIcon className='fill-aqua w2 mr1' />
{t('app:terms.file')}
</Option>
<Option onClick={this.onAddFolder} id='add-folder' onCliTutorMode={() => this.onCliTutorMode(cliCmdKeys.ADD_DIRECTORY)}
isCliTutorModeEnabled={isCliTutorModeEnabled}>
<FolderIcon className='fill-aqua w2 mr1' />
{t('app:terms.folder')}
</Option>
<Option onClick={this.onNewFolder} id='add-new-folder' onCliTutorMode={() => this.onCliTutorMode(cliCmdKeys.CREATE_NEW_DIRECTORY)}
isCliTutorModeEnabled={isCliTutorModeEnabled}>
<NewFolderIcon className='fill-aqua w2 h2 mr1' />
{t('newFolder')}
</Option>
<Option onClick={this.onAddByPath} id='add-by-path' onCliTutorMode={() => this.onCliTutorMode(cliCmdKeys.FROM_IPFS)}
isCliTutorModeEnabled={isCliTutorModeEnabled}>
<DecentralizationIcon className='fill-aqua w2 mr1' />
{t('addByPath')}
</Option>
<Option onClick={this.onAddByCar} id='add-by-car' onCliTutorMode={() => this.onCliTutorMode(cliCmdKeys.FROM_CAR)}
isCliTutorModeEnabled={isCliTutorModeEnabled}>
<DataIcon className='fill-aqua w2 mr1' />
{t('addByCar')}
</Option>
<Option onClick={this.onBulkCidImport} id='bulk-cid-import'>
<DocumentIcon className='fill-aqua w2 mr1' />
{t('bulkImport')}
</Option>
<Option onClick={this.onSyncFromPins} id='sync-from-pins'>
<GlyphPinCloud className='fill-aqua w2 mr1' />
{t('syncFromPins.title')}
</Option>
</DropdownMenu>
</Dropdown>
<input
id='file-input'
type='file'
className='dn'
multiple
ref={el => { this.filesInput = el }}
onChange={this.onInputChange(this.filesInput)} />
<input
id='directory-input'
type='file'
className='dn'
multiple
webkitdirectory='true'
ref={el => { this.folderInput = el }}
onChange={this.onInputChange(this.folderInput)} />
</div>
)
}
}
FileInput.propTypes = {
t: PropTypes.func.isRequired,
onAddFiles: PropTypes.func.isRequired,
onAddByPath: PropTypes.func.isRequired,
onAddByCar: PropTypes.func.isRequired,
onBulkCidImport: PropTypes.func.isRequired,
onNewFolder: PropTypes.func.isRequired,
onSyncFromPins: PropTypes.func.isRequired
}
export default connect(
'selectIsCliTutorModeEnabled',
'doOpenCliTutorModal',
'doSetCliOptions',
withTranslation('files')(FileInput)
)