-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use mfs make components more independent flatten some directories
- Loading branch information
Showing
80 changed files
with
1,405 additions
and
1,036 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,124 @@ | ||
import React 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' | ||
|
||
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 function FileBlock (props) { | ||
const extension = fileExtension(props.name) | ||
let icon = 'file' | ||
|
||
if (props.type === 'directory') { | ||
icon = 'folder' | ||
} else if (fileTypes[extension]) { | ||
icon = fileTypes[extension] | ||
} | ||
|
||
const open = () => { | ||
if (props.type === 'directory') { | ||
props.navigate(props.name, props.hash) | ||
} else { | ||
props.open(props.name, props.hash) | ||
} | ||
} | ||
|
||
const copy = wrapper(() => { props.copy(props.hash) }) | ||
const remove = wrapper(() => { props.remove(props.name) }) | ||
|
||
const wrapped = ( | ||
<div> | ||
<div className='icon'> | ||
<Icon name={icon} /> | ||
</div> | ||
<div> | ||
<p className='label'>{props.name}</p> | ||
<p className='info'>{prettyBytes(props.size)} | {props.hash}</p> | ||
</div> | ||
</div> | ||
) | ||
|
||
const unwrapped = ( | ||
<div className='button-overlay'> | ||
{ typeof props.copy === 'function' && | ||
<IconButton icon='clipboard' onClick={copy} /> | ||
} | ||
{ typeof props.remove === 'function' && | ||
<IconButton icon='trash' onClick={remove} /> | ||
} | ||
</div> | ||
) | ||
|
||
return ( | ||
<Block | ||
{...props.open !== null && { onClick: open }} | ||
className='file' | ||
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
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
3 changes: 1 addition & 2 deletions
3
src/js/components/view/icon-button.js → src/components/IconButton.js
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
2 changes: 1 addition & 1 deletion
2
src/js/components/view/icon-dropdown-list.js → src/components/IconDropdownList.js
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.