From a17b76ac75f506f5da6fe8adf9c36632b60d4226 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 26 Sep 2020 14:56:02 +0200 Subject: refactor to use app-rooted js imports --- frontend/views/upload/components/upload.form.js | 16 ---- frontend/views/upload/components/upload.index.js | 104 --------------------- .../views/upload/components/upload.indexOptions.js | 62 ------------ frontend/views/upload/components/upload.menu.js | 18 ---- frontend/views/upload/components/upload.show.js | 70 -------------- frontend/views/upload/upload.actions.js | 17 ---- frontend/views/upload/upload.container.js | 37 -------- frontend/views/upload/upload.css | 10 -- frontend/views/upload/upload.reducer.js | 21 ----- 9 files changed, 355 deletions(-) delete mode 100644 frontend/views/upload/components/upload.form.js delete mode 100644 frontend/views/upload/components/upload.index.js delete mode 100644 frontend/views/upload/components/upload.indexOptions.js delete mode 100644 frontend/views/upload/components/upload.menu.js delete mode 100644 frontend/views/upload/components/upload.show.js delete mode 100644 frontend/views/upload/upload.actions.js delete mode 100644 frontend/views/upload/upload.container.js delete mode 100644 frontend/views/upload/upload.css delete mode 100644 frontend/views/upload/upload.reducer.js (limited to 'frontend/views/upload') diff --git a/frontend/views/upload/components/upload.form.js b/frontend/views/upload/components/upload.form.js deleted file mode 100644 index 2010088..0000000 --- a/frontend/views/upload/components/upload.form.js +++ /dev/null @@ -1,16 +0,0 @@ -import React, { Component } from 'react' -import { Link } from 'react-router-dom' - -import { MenuButton, FileInput } from '../../../common' - -export default class UploadForm extends Component { - render() { - return ( -
- - - -
- ) - } -} diff --git a/frontend/views/upload/components/upload.index.js b/frontend/views/upload/components/upload.index.js deleted file mode 100644 index 6123001..0000000 --- a/frontend/views/upload/components/upload.index.js +++ /dev/null @@ -1,104 +0,0 @@ -import React, { Component } from 'react' -import { Link } from 'react-router-dom' - -import { uploadUri, formatDateTime } from '../../../util' -import { MenuButton, SmallMenuButton, Loader } from '../../../common' -import actions from '../../../actions' - -import UploadIndexOptions from './upload.indexOptions' -import UploadMenu from './upload.menu' - -// const { result, collectionLookup } = this.props - -export default class UploadIndex extends Component { - componentDidMount() { - this.fetch(false) - } - - componentDidUpdate(prevProps) { - if (this.props.upload.options.sort !== prevProps.upload.options.sort) { - this.fetch(false) - } - } - - fetch(load_more) { - const { options, index } = this.props.upload - const { order: index_order } = index - const [ sort, order ] = options.sort.split('-') - actions.upload.index({ - sort, order, limit: 50, offset: load_more ? index_order.length : 0, - }, load_more) - } - - render() { - const { searchOptions, uploadActions } = this.props - const { options } = this.props.upload - const { loading, lookup, order } = this.props.upload.index - if (loading) { - return ( -
- -
- {order && !!order.length && -
- {order.map(id => )} -
- } -
- -
- ) - } - if (!lookup || !order.length) { - return ( -
- -
- -

- {"No uploads"} -

-
-
- ) - } - return ( -
- -
- -
- {order.map(id => )} -
-
- {order.length >= 50 && } -
- ) - } -} - -const UploadItem = ({ data }) => { - // console.log(data) - const imageUri = uploadUri(data) - return ( -
-
- - {"Uploaded - -
-
-
- -
-
- {data.username} -
-
- {formatDateTime(data.created_at)} -
-
-
- ) -} - diff --git a/frontend/views/upload/components/upload.indexOptions.js b/frontend/views/upload/components/upload.indexOptions.js deleted file mode 100644 index 22d3fdc..0000000 --- a/frontend/views/upload/components/upload.indexOptions.js +++ /dev/null @@ -1,62 +0,0 @@ -import React, { Component } from 'react' -import { Link } from 'react-router-dom' -import { bindActionCreators } from 'redux' -import { connect } from 'react-redux' - -import actions from '../../../actions' - -import { Select, Checkbox } from '../../../common' - -const thumbnailOptions = [ - { name: 'th', label: 'Thumbnails', }, - { name: 'sm', label: 'Small', }, - { name: 'md', label: 'Medium', }, - { name: 'lg', label: 'Large', }, - { name: 'orig', label: 'Original', }, -] - -const sortOptions = [ - { name: 'id-asc', label: 'Most recent' }, - { name: 'id-desc', label: 'Oldest first' }, - { name: 'username-asc', label: 'Username (A-Z)' }, - { name: 'username-desc', label: 'Username (Z-A)' }, - // { name: '-asc', label: '' }, - // { name: '-desc', label: '' }, - // { name: '-asc', label: '' }, - // { name: '-desc', label: '' }, - // { name: '-asc', label: '' }, - // { name: '-desc', label: '' }, -] - -class IndexOptions extends Component { - render() { - const { options, searchOptions } = this.props - return ( -
-
- -
- ) - } -} - -const mapStateToProps = state => ({ - options: state.upload.options, - searchOptions: state.search.options, -}) - -const mapDispatchToProps = dispatch => ({ -}) - -export default connect(mapStateToProps, mapDispatchToProps)(IndexOptions) diff --git a/frontend/views/upload/components/upload.menu.js b/frontend/views/upload/components/upload.menu.js deleted file mode 100644 index 37c7f0b..0000000 --- a/frontend/views/upload/components/upload.menu.js +++ /dev/null @@ -1,18 +0,0 @@ -import React, { Component } from 'react' -import { Link } from 'react-router-dom' - -import { MenuButton, FileInput } from '../../../common' - -import actions from '../../../actions' - -export default class UploadMenu extends Component { - render() { - return ( -
- - - -
- ) - } -} diff --git a/frontend/views/upload/components/upload.show.js b/frontend/views/upload/components/upload.show.js deleted file mode 100644 index 6b36269..0000000 --- a/frontend/views/upload/components/upload.show.js +++ /dev/null @@ -1,70 +0,0 @@ -import React, { Component } from 'react' -import { Link } from 'react-router-dom' -import { connect } from 'react-redux' - -import actions from '../../../actions' -import { formatDate, formatTime, formatAge, uploadUri } from '../../../util' -import { history } from '../../../store' -import { Loader, MenuButton } from '../../../common' - -class UploadShow extends Component { - componentDidMount() { - actions.upload.show(this.props.match.params.id) - } - - componentDidUpdate(prevProps) { - if (prevProps.match.params.id !== this.props.match.params.id) { - actions.upload.show(this.props.match.params.id) - } - } - - handleDestroy() { - const { res: data } = this.props.upload.show - if (confirm("Really delete this upload?")) { - actions.upload.destroy(data).then(() => { - history.push('/upload/') - }) - } - } - - render() { - const { show, destroy } = this.props.upload - if (show.loading || destroy.loading) { - return - } - if (!show.loading && !show.res || show.not_found) { - return
Upload {this.props.match.params.id} not found
- } - const { res: data } = show - return ( -
-
- - -
-
- -
- {'Uploaded by '} - {data.username} - {' on '} - {formatDate(data.created_at)} - {' at '} - {formatTime(data.created_at)} - {'. '} -
-
-
- ) - } -} - -const mapStateToProps = state => ({ - upload: state.upload, -}) - -const mapDispatchToProps = dispatch => ({ - // searchActions: bindActionCreators({ ...searchActions }, dispatch), -}) - -export default connect(mapStateToProps, mapDispatchToProps)(UploadShow) diff --git a/frontend/views/upload/upload.actions.js b/frontend/views/upload/upload.actions.js deleted file mode 100644 index ba2b14b..0000000 --- a/frontend/views/upload/upload.actions.js +++ /dev/null @@ -1,17 +0,0 @@ -import * as types from '../../types' -import { store, history } from '../../store' -import { api, post, pad, preloadImage } from '../../util' -import actions from '../../actions' -import { session } from '../../session' - -export const upload = file => dispatch => { - const formData = { - 'image': file, - 'username': session('username'), - } - // console.log(formData) - return actions.upload.upload(formData).then(data => { - // console.log(data.res) - return data.res - }) -} diff --git a/frontend/views/upload/upload.container.js b/frontend/views/upload/upload.container.js deleted file mode 100644 index ea9df5a..0000000 --- a/frontend/views/upload/upload.container.js +++ /dev/null @@ -1,37 +0,0 @@ -import React, { Component } from 'react' -import { Route, Link } from 'react-router-dom' -import { bindActionCreators } from 'redux' -import { connect } from 'react-redux' - -import './upload.css' - -import actions from '../../actions' -import * as uploadActions from './upload.actions' - -import UploadMenu from './components/upload.menu' -import UploadIndex from './components/upload.index' -import UploadShow from './components/upload.show' - -class Container extends Component { - render() { - return ( -
-
- - -
-
- ) - } -} - -const mapStateToProps = state => ({ - upload: state.upload, - searchOptions: state.search.options, -}) - -const mapDispatchToProps = dispatch => ({ - uploadActions: bindActionCreators({ ...uploadActions }, dispatch), -}) - -export default connect(mapStateToProps, mapDispatchToProps)(Container) diff --git a/frontend/views/upload/upload.css b/frontend/views/upload/upload.css deleted file mode 100644 index 8d77754..0000000 --- a/frontend/views/upload/upload.css +++ /dev/null @@ -1,10 +0,0 @@ -.uploadShow img { - max-width: 30rem; - max-height: 20rem; -} -.upload { - height: 100%; -} -.upload > div:last-child { - flex: 1; -} \ No newline at end of file diff --git a/frontend/views/upload/upload.reducer.js b/frontend/views/upload/upload.reducer.js deleted file mode 100644 index 98dc0a1..0000000 --- a/frontend/views/upload/upload.reducer.js +++ /dev/null @@ -1,21 +0,0 @@ -import * as types from '../../types' -import { session, getDefault, getDefaultInt } from '../../session' - -import { crudState, crudReducer } from '../../api/crud.reducer' - -const initialState = crudState('upload', { - options: { - sort: getDefault('upload.sort', 'id-desc'), - } -}) - -const reducer = crudReducer('upload') - -export default function uploadReducer(state = initialState, action) { - // console.log(action.type, action) - state = reducer(state, action) - switch (action.type) { - default: - return state - } -} -- cgit v1.2.3-70-g09d2