Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/redesign files bar #1513

Merged
merged 4 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/locales/en/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"pins": "Pins",
"pinned": "Pinned",
"blocks": "Blocks",
"allBlocks": "all blocks",
"more": "More",
"files": "Files",
"cidNotFileNorDir": "The current link isn't a file, nor a directory. Try to <0>inspect</0> it instead."
Expand Down
4 changes: 4 additions & 0 deletions src/bundles/files/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { infoFromPath } from './utils'
export default () => ({
selectFiles: (state) => state.files.pageContent,

selectCurrentDirectorySize: (state) => state.files.pageContent?.content?.reduce((prev, curr) => prev + curr.size, 0),

selectPins: (state) => state.files.pins,

selectFilesSize: (state) => state.files.mfsSize,
Expand All @@ -26,6 +28,8 @@ export default () => ({

selectFilesErrors: (state) => state.files.failed,

selectHasUpperDirectory: (state) => !!state.files.pageContent?.upper,

selectFilesPathInfo: createSelector(
'selectRouteInfo',
(routeInfo) => {
Expand Down
51 changes: 22 additions & 29 deletions src/files/header/Header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import filesize from 'filesize'
import SimplifyNumber from 'simplify-number'
import classNames from 'classnames'
import { connect } from 'redux-bundler-react'
import { withTranslation } from 'react-i18next'
// Components
Expand All @@ -10,18 +10,12 @@ import Button from '../../components/button/Button'
// Icons
import GlyphDots from '../../icons/GlyphDots'

function BarOption ({ children, title, isLink = false, className = '', ...etc }) {
className += ' tc pa3'

if (etc.onClick) className += ' pointer'

return (
<div className={className} {...etc}>
<span className='nowrap db f4 navy'>{children}</span>
<span className={`db ttl ${isLink ? 'navy underline' : 'gray'}`}>{title}</span>
</div>
)
}
const BarOption = ({ children, title, className = '', ...etc }) => (
<div className={classNames(className, 'tc pa3')} {...etc}>
<span className='nowrap db f4 navy'>{children}</span>
<span className='db ttl gray'>{title}</span>
</div>
)

function humanSize (size) {
if (!size) return 'N/A'
Expand All @@ -42,14 +36,14 @@ class Header extends React.Component {

render () {
const {
currentDirectorySize,
hasUpperDirectory,
files,
t,
pins,
filesPathInfo,
filesSize,
repoNumObjects,
onNavigate,
repoSize,
onNavigate
t
} = this.props

return (
Expand All @@ -59,19 +53,17 @@ class Header extends React.Component {
</div>

<div className='mb3 flex justify-between items-center bg-snow-muted joyride-files-add'>
<BarOption title={t('files')} isLink onClick={() => { onNavigate('/files') }}>
{ humanSize(filesSize) }
</BarOption>

<BarOption title={t('pins')} isLink onClick={() => { onNavigate('/pins') }}>
{ pins ? SimplifyNumber(pins.length) : '-' }
</BarOption>

<BarOption title={t('blocks')}>
{ repoNumObjects ? SimplifyNumber(repoNumObjects, { decimal: 0 }) : 'N/A' }
<BarOption title={t('files')}>
{ hasUpperDirectory
? (
<span>
{ humanSize(currentDirectorySize) }<span className='f5 gray'>/{ humanSize(filesSize) }</span>
</span>
)
: humanSize(filesSize) }
</BarOption>

<BarOption title={t('repo')}>
<BarOption title={t('allBlocks')}>
{ humanSize(repoSize) }
</BarOption>

Expand Down Expand Up @@ -104,10 +96,11 @@ class Header extends React.Component {
}

export default connect(
'selectPins',
'selectHasUpperDirectory',
'selectFilesSize',
'selectRepoSize',
'selectRepoNumObjects',
'selectFilesPathInfo',
'selectCurrentDirectorySize',
withTranslation('files')(Header)
)