summaryrefslogtreecommitdiff
path: root/app/client/common/folderList.component.js
blob: 91d0bffbb73ba8383602a4ea9d403cb1a52956ce (plain)
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
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import util from '../util'

import Group from './group.component'
import Param from './param.component'
import Loading from './loading.component'

export default function FolderList ({ db, path, emptyText, activity }) {
  if (! db) return null
  if (db.loading || !db.data) {
    return (
      <div className='col folderList'>
        <Loading progress={db.progress} />
      </div>
    )
  }
  let folderList = db.data.folders
  if (activity) {
    folderList = folderList.filter(f => f.activity === activity)
  }
  if (! folderList.length && emptyText) {
    return (
      <div className='col folderList'>
        {emptyText}
      </div>
    )
  }
  console.log(folders)
  const folders = folderList.map(raw_folder => {
    const folder = db.data.folderLookup[raw_folder.id]
    const fileCount = folder.files ? folder.files.length : 0
    const [ className, size ] = util.hush_null(fileCount)
    return (
      <Param title={<Link to={path + folder.id + '/'}>{folder.name}</Link>}>
        <span className={className}>{fileCount} file{util.courtesy_s(fileCount)}</span>
      </Param>
    )
  })

  return (
    <div className='col folderList'>
      <Group title='Projects'>
        {folders}
      </Group>
    </div>
  )
}