summaryrefslogtreecommitdiff
path: root/frontend/site
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-09-26 14:56:02 +0200
committerJules Laplace <julescarbon@gmail.com>2020-09-26 14:56:02 +0200
commita17b76ac75f506f5da6fe8adf9c36632b60d4226 (patch)
treeabb0af0c4409b830dea2ef808c146223ee973933 /frontend/site
parent2231a6e1c05b07bb7ec5906716aedec93d02429c (diff)
refactor to use app-rooted js imports
Diffstat (limited to 'frontend/site')
-rw-r--r--frontend/site/actions.js19
-rw-r--r--frontend/site/app.js33
-rw-r--r--frontend/site/index.js17
-rw-r--r--frontend/site/site/site.actions.js24
-rw-r--r--frontend/site/site/site.reducer.js37
-rw-r--r--frontend/site/store.js38
-rw-r--r--frontend/site/types.js11
-rw-r--r--frontend/site/viewer/viewer.container.js96
8 files changed, 0 insertions, 275 deletions
diff --git a/frontend/site/actions.js b/frontend/site/actions.js
deleted file mode 100644
index e672028..0000000
--- a/frontend/site/actions.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import { bindActionCreators } from 'redux'
-// import { actions as crudActions } from './api'
-
-import * as siteActions from './site/site.actions'
-
-import { store } from './store'
-
-export default
- // Object.keys(crudActions)
- // .map(a => [a, crudActions[a]])
- // .concat(
- [
- ['site', siteActions],
- ] //)
- .map(p => [p[0], bindActionCreators(p[1], store.dispatch)])
- .concat([
- // ['socket', socketActions],
- ])
- .reduce((a,b) => (a[b[0]] = b[1])&&a,{}) \ No newline at end of file
diff --git a/frontend/site/app.js b/frontend/site/app.js
deleted file mode 100644
index cf52460..0000000
--- a/frontend/site/app.js
+++ /dev/null
@@ -1,33 +0,0 @@
-import React, { Component } from 'react'
-import { ConnectedRouter } from 'connected-react-router'
-import { Route } from 'react-router'
-
-import ViewerContainer from './viewer/viewer.container'
-import actions from './actions'
-
-export default class App extends Component {
- componentDidMount() {
- const path_partz = window.location.pathname.split('/')
- const graph_name = path_partz[1]
- let path_name = null
- if (path_partz.length > 2) {
- path_name = path_partz[2]
- }
- // console.log('loading', graph_name, path_name)
- actions.site.loadSite(graph_name, path_name)
- }
-
- render() {
- return (
- <ConnectedRouter history={this.props.history}>
- <div className='app'>
- <Route path={'/:graph_name/:page_name'} component={ViewerContainer} exact />
- <Route exact key='root' path='/' render={() => {
- // setTimeout(() => this.props.history.push('/'), 10)
- return null
- }} />
- </div>
- </ConnectedRouter>
- )
- }
-}
diff --git a/frontend/site/index.js b/frontend/site/index.js
deleted file mode 100644
index 6f1a0a5..0000000
--- a/frontend/site/index.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import { Provider } from 'react-redux'
-
-import App from './app'
-
-import { store, history } from './store'
-
-const container = document.createElement('div')
-container.classList.add('container')
-document.body.appendChild(container)
-
-ReactDOM.render(
- <Provider store={store}>
- <App history={history} />
- </Provider>, container
-)
diff --git a/frontend/site/site/site.actions.js b/frontend/site/site/site.actions.js
deleted file mode 100644
index 5724df8..0000000
--- a/frontend/site/site/site.actions.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import * as types from '../types'
-import { api } from '../../util'
-import { history } from '../store'
-// import actions from '../../actions'
-// import { session } from '../../session'
-
-export const setSiteTitle = title => dispatch => {
- document.querySelector('title').innerText = title
- dispatch({ type: types.site.set_site_title, payload: title })
-}
-
-export const loadSite = (graph_name, path_name) => dispatch => (
- api(dispatch, types.site, 'site', '/' + graph_name + '/index.json')
- // .then(res => {
- // const { graph } = res.data
- // // console.log(graph)
- // // console.log(graph.home_page)
- // const first_path = ["", graph_name, path_name].join("/")
- // if (!path_name || !(first_path in graph.pages)) {
- // // console.log(graph.home_page)
- // window.location.href = graph.home_page
- // }
- // })
-)
diff --git a/frontend/site/site/site.reducer.js b/frontend/site/site/site.reducer.js
deleted file mode 100644
index f630b9c..0000000
--- a/frontend/site/site/site.reducer.js
+++ /dev/null
@@ -1,37 +0,0 @@
-import * as types from '../types'
-// import { session, getDefault, getDefaultInt } from '../../session'
-
-const initialState = {
- siteTitle: 'swimmer',
- graph: {
- loading: true,
- }
-}
-
-export default function siteReducer(state = initialState, action) {
- console.log(action.type, action)
- switch (action.type) {
- case types.site.set_site_title:
- return {
- ...state,
- siteTitle: action.payload,
- }
-
- case types.site.loaded:
- return {
- ...state,
- graph: action.data.graph,
- }
-
- case '@@router/LOCATION_CHANGE':
- return {
- ...state,
- graph: {
- ...state.graph,
- }
- }
-
- default:
- return state
- }
-}
diff --git a/frontend/site/store.js b/frontend/site/store.js
deleted file mode 100644
index cd77990..0000000
--- a/frontend/site/store.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import { applyMiddleware, compose, combineReducers, createStore } from 'redux'
-import { connectRouter, routerMiddleware } from 'connected-react-router'
-import { createBrowserHistory } from 'history'
-import thunk from 'redux-thunk'
-// import { login } from './util'
-
-import siteReducer from './site/site.reducer'
-
-const createRootReducer = history => (
- combineReducers({
- auth: (state = {}) => state,
- router: connectRouter(history),
- site: siteReducer,
- })
-)
-
-const configureStore = (initialState = {}, history) => {
- const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
-
- const store = createStore(
- createRootReducer(history),
- initialState,
- composeEnhancers(
- applyMiddleware(
- thunk,
- routerMiddleware(history)
- ),
- ),
- )
-
- return store
-}
-
-const history = createBrowserHistory()
-const store = configureStore({}, history)
-const { dispatch } = store
-
-export { store, history, dispatch }
diff --git a/frontend/site/types.js b/frontend/site/types.js
deleted file mode 100644
index 8388eff..0000000
--- a/frontend/site/types.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import { with_type, crud_type } from '../api/crud.types'
-
-export const site = with_type('site', [
- 'set_site_title', 'loading', 'loaded', 'error',
-])
-
-export const system = with_type('system', [
- 'load_site',
-])
-
-export const init = '@@INIT'
diff --git a/frontend/site/viewer/viewer.container.js b/frontend/site/viewer/viewer.container.js
deleted file mode 100644
index da81551..0000000
--- a/frontend/site/viewer/viewer.container.js
+++ /dev/null
@@ -1,96 +0,0 @@
-import React, { Component } from 'react'
-import { Route } from 'react-router-dom'
-import { bindActionCreators } from 'redux'
-import { connect } from 'react-redux'
-
-import actions from '../actions'
-import { Loader } from '../../common/loader.component'
-import TileHandle from '../../views/page/components/tile.handle'
-
-import '../../views/page/page.css'
-
-class ViewerContainer extends Component {
- state = {
- page: {},
- }
-
- constructor(props) {
- super(props)
- this.pageRef = React.createRef()
- this.handleMouseDown = this.handleMouseDown.bind(this)
- }
-
- componentDidUpdate(prevProps) {
- // console.log('didUpdate', this.props.graph !== prevProps.graph, this.props.location.pathname !== prevProps.location.pathname)
- if (this.props.graph !== prevProps.graph || this.props.location.pathname !== prevProps.location.pathname) {
- this.load()
- }
- }
-
- load() {
- const { graph_name, page_name } = this.props.match.params
- const page_path = ["", graph_name, page_name].join('/')
- const { pages, home_page } = this.props.graph
- const page = pages[page_path]
- if (!page) {
- // console.log('-> home page')
- console.log(page_path)
- const { home_page } = this.props.graph
- this.setState({ page: pages[home_page] })
- } else {
- // console.log(page)
- console.log(page_path)
- this.setState({ page })
- }
- }
-
- handleMouseDown(e, tile) {
- // console.log(tile)
- }
-
- render() {
- const { page } = this.state
- if (this.props.graph.loading || !page.id) {
- return (
- <div>
- <div className='body'>
- <div className='page loading'>
- <Loader />
- </div>
- </div>
- </div>
- )
- }
- const { settings } = page
- const pageStyle = { backgroundColor: settings ? settings.background_color : '#000000' }
- // console.log(page)
- return (
- <div className='body'>
- <div className='page' ref={this.pageRef} style={pageStyle}>
- {page.tiles.map(tile => {
- return (
- <TileHandle
- viewing
- key={tile.id}
- tile={tile}
- bounds={this.state.bounds}
- onMouseDown={e => this.handleMouseDown(e, tile)}
- onDoubleClick={e => {}}
- />
- )
- })}
- </div>
- </div>
- )
- }
-}
-
-const mapStateToProps = state => ({
- site: state.site,
- graph: state.site.graph,
-})
-
-const mapDispatchToProps = dispatch => ({
-})
-
-export default connect(mapStateToProps, mapDispatchToProps)(ViewerContainer)