-
Notifications
You must be signed in to change notification settings - Fork 865
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
89 changed files
with
1,707 additions
and
1,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
/** | ||
* It's a Block. | ||
* | ||
* @param {Object} props | ||
* | ||
* @prop {Any} wrapped | ||
* @prop {Any} unwrapped | ||
* @prop {Function} [onClick] | ||
* | ||
* @return {ReactElement} | ||
*/ | ||
export default function Block (props) { | ||
let className = 'block' | ||
if (props.className !== '') { | ||
className += ' ' + props.className | ||
} | ||
|
||
if (props.onClick !== null) { | ||
className += ' clickable' | ||
} | ||
|
||
return ( | ||
<div className={className} {...props.onClick !== null && { onClick: props.onClick }}> | ||
<div className='wrapper'> | ||
{props.wrapped} | ||
</div> | ||
{props.unwrapped && props.unwrapped} | ||
</div> | ||
) | ||
} | ||
|
||
Block.propTypes = { | ||
wrapped: PropTypes.any.isRequired, | ||
unwrapped: PropTypes.any, | ||
className: PropTypes.string, | ||
onClick: PropTypes.func | ||
} | ||
|
||
Block.defaultProps = { | ||
className: '', | ||
onClick: null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
function makeBread (root) { | ||
root = root || '/' | ||
if (root.endsWith('/')) { | ||
root = root.substring(0, root.length - 2) | ||
} | ||
|
||
let parts = root.split('/').map(part => { | ||
return { | ||
name: part, | ||
path: part | ||
} | ||
}) | ||
|
||
for (let i = 1; i < parts.length; i++) { | ||
parts[i] = { | ||
name: parts[i].name, | ||
path: parts[i - 1].path + '/' + parts[i].path | ||
} | ||
} | ||
|
||
parts[0] = { | ||
name: 'ipfs', | ||
path: '/' | ||
} | ||
|
||
return parts | ||
} | ||
|
||
export default function Breadcrumbs ({path, navigate}) { | ||
const bread = makeBread(path) | ||
const res = [] | ||
|
||
bread.forEach((link, index) => { | ||
res.push(<a key={`${index}link`} onClick={() => { navigate(link.path) }}>{link.name}</a>) | ||
res.push(<span key={`${index}divisor`}>/</span>) | ||
}) | ||
|
||
res.pop() | ||
return ( | ||
<span className='breadcrumbs'>{res}</span> | ||
) | ||
} | ||
|
||
Breadcrumbs.propTypes = { | ||
path: PropTypes.string.isRequired, | ||
navigate: PropTypes.func.isRequired | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import React, {Component} from 'react' | ||
import PropTypes from 'prop-types' | ||
import fileExtension from 'file-extension' | ||
import prettyBytes from 'pretty-bytes' | ||
|
||
import Block from './Block' | ||
import Icon from './Icon' | ||
import IconButton from './IconButton' | ||
import Button from './Button' | ||
|
||
const wrapper = (fn) => { | ||
return (event) => { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
fn() | ||
} | ||
} | ||
|
||
/** | ||
* Is a File Block. | ||
* | ||
* @param {Object} props | ||
* | ||
* @prop {String} name - file name | ||
* @prop {String} date - date when the file was modified/uploaded | ||
* @prop {String} hash - file's hash in IPFS system | ||
* | ||
* @return {ReactElement} | ||
*/ | ||
export default class FileBlock extends Component { | ||
constructor (props) { | ||
super(props) | ||
|
||
const extension = fileExtension(this.props.name) | ||
let icon = 'file' | ||
|
||
if (this.props.type === 'directory') { | ||
icon = 'folder' | ||
} else if (fileTypes[extension]) { | ||
icon = fileTypes[extension] | ||
} | ||
|
||
this.state = { | ||
icon: icon, | ||
deleting: false | ||
} | ||
} | ||
|
||
open = () => { | ||
if (this.props.type === 'directory') { | ||
this.props.navigate(this.props.name, this.props.hash) | ||
} else { | ||
this.props.open(this.props.name, this.props.hash) | ||
} | ||
} | ||
|
||
copy = wrapper(() => { | ||
this.props.copy(this.props.hash) | ||
}) | ||
|
||
remove = wrapper(() => { | ||
this.props.remove(this.props.name) | ||
}) | ||
|
||
delete = wrapper(() => { | ||
this.setState({ deleting: true }) | ||
}) | ||
|
||
undelete = () => { | ||
this.setState({ deleting: false }) | ||
} | ||
|
||
render () { | ||
const wrapped = ( | ||
<div> | ||
<div className='icon'> | ||
<Icon name={this.state.icon} /> | ||
</div> | ||
<div> | ||
<p className='label'>{this.props.name}</p> | ||
{ this.state.deleting && | ||
<p className='info'>Are you sure? This is permanent.</p> | ||
} | ||
{ !this.state.deleting && | ||
<p className='info'>{prettyBytes(this.props.size)} | {this.props.hash}</p> | ||
} | ||
</div> | ||
</div> | ||
) | ||
|
||
let unwrapped = null | ||
|
||
if (this.state.deleting) { | ||
unwrapped = ( | ||
<div className='button-overlay'> | ||
<Button text='Cancel' onClick={this.undelete} /> | ||
<Button text='Delete' onClick={this.remove} /> | ||
</div> | ||
) | ||
} else { | ||
unwrapped = ( | ||
<div className='button-overlay'> | ||
{ typeof this.props.copy === 'function' && | ||
<IconButton icon='clipboard' onClick={this.copy} /> | ||
} | ||
{ typeof this.props.remove === 'function' && | ||
<IconButton icon='trash' color='#F44336' onClick={this.delete} /> | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
let className = 'file' | ||
if (this.state.deleting) { | ||
className += ' deleting' | ||
} | ||
|
||
return ( | ||
<Block | ||
{...this.props.open !== null && !this.state.deleting && { onClick: this.open }} | ||
className={className} | ||
wrapped={wrapped} | ||
unwrapped={unwrapped} /> | ||
) | ||
} | ||
} | ||
|
||
FileBlock.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
hash: PropTypes.string.isRequired, | ||
size: PropTypes.number.isRequired, | ||
navigate: PropTypes.func, | ||
copy: PropTypes.func, | ||
remove: PropTypes.func, | ||
type: PropTypes.string, | ||
open: PropTypes.func | ||
} | ||
|
||
FileBlock.defaultProps = { | ||
type: 'file' | ||
} | ||
|
||
const fileTypes = { | ||
png: 'image', | ||
jpg: 'image', | ||
tif: 'image', | ||
tiff: 'image', | ||
bmp: 'image', | ||
gif: 'image', | ||
eps: 'image', | ||
raw: 'image', | ||
cr2: 'image', | ||
nef: 'image', | ||
orf: 'image', | ||
sr2: 'image', | ||
jpeg: 'image', | ||
mp3: 'music-alt', | ||
flac: 'music-alt', | ||
ogg: 'music-alt', | ||
oga: 'music-alt', | ||
aa: 'music-alt', | ||
aac: 'music-alt', | ||
m4p: 'music-alt', | ||
webm: 'music-alt', | ||
mp4: 'video-clapper', | ||
mkv: 'video-clapper', | ||
avi: 'video-clapper', | ||
asf: 'video-clapper', | ||
flv: 'video-clapper' | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.