From 46fbedf0ad7b167a28daf2030e06f34480576394 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 3 Jun 2018 02:25:34 +0200 Subject: add results page --- app/client/common/fileList.component.js | 68 +++++++++------------------------ 1 file changed, 19 insertions(+), 49 deletions(-) (limited to 'app/client/common/fileList.component.js') diff --git a/app/client/common/fileList.component.js b/app/client/common/fileList.component.js index 13eb300..c16928f 100644 --- a/app/client/common/fileList.component.js +++ b/app/client/common/fileList.component.js @@ -5,7 +5,7 @@ import { Link } from 'react-router-dom'; import moment from 'moment' import * as util from '../util' -const defaultFields = new Set(['date', 'size']) +const defaultFields = new Set(['name', 'date', 'size']) export const FileList = props => { const { @@ -17,19 +17,19 @@ export const FileList = props => { fileListClassName='filelist', rowClassName='row file' } = props - const { mapFn, sortFn } = orderByFn(orderBy) + const { mapFn, sortFn } = util.sort.orderByFn(orderBy) const fileList = (files || []) .map(mapFn) .sort(sortFn) - .map(pair => - { + return - ) + }) return (
@@ -45,39 +45,6 @@ export const FileList = props => { ) } -const numericSort = { - asc: (a,b) => a[0] - b[0], - desc: (a,b) => b[0] - a[0], -} -const stringSort = { - asc: (a,b) => a[0].localeCompare(b[0]), - desc: (a,b) => b[0].localeCompare(a[0]), -} -export const orderByFn = (s='name asc') => { - const [field='name', direction='asc'] = s.split(' ') - let mapFn, sortFn - switch (field) { - case 'epoch': - mapFn = a => [a.epoch || a.epochs, a] - sortFn = numericSort[direction] - break - case 'size': - mapFn = a => [a.size, a] - sortFn = numericSort[direction] - break - case 'date': - mapFn = a => [+new Date(a.date || a.created_at), a] - sortFn = numericSort[direction] - break - case 'name': - default: - mapFn = a => [a.id || a.name, a] - sortFn = stringSort[direction] - break - } - return { mapFn, sortFn } -} - export const fieldSet = fields => { if (fields) { if (fields instanceof Set) { @@ -94,23 +61,29 @@ export const FileRow = props => { const size = util.hush_size(file.size) const date = file.date || file.created_at + const epoch = file.epoch || file.epochs || 0 return (
-
- {file.persisted === false - ? {file.name || file.url} - : (linkFiles && file.url) - ? {file.name || file.url} - : onClick(file)}>{file.name || file.url} - } -
+ {fields.has('name') && +
+ {file.persisted === false + ? {file.name || file.url} + : (linkFiles && file.url) + ? {file.name || file.url} + : onClick(file)}>{file.name || file.url} + } +
+ } {fields.has('age') &&
{util.get_age(date)}
} {fields.has('username') &&
{username}
} + {fields.has('epoch') && +
{epoch > 0 ? 'ep. ' + epoch : ''}
+ } {fields.has('date') &&
{moment(date).format("YYYY-MM-DD")}
} @@ -120,9 +93,6 @@ export const FileRow = props => { {fields.has('size') &&
{size[1]}
} - {fields.has('epoch') && -
{file.epoch > 0 ? 'epoch ' + file.epoch : ' '}
- } {(fields.has('activity') || fields.has('module')) &&
{fields.has('activity') && file.activity} -- cgit v1.2.3-70-g09d2