diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/actions.js | 4 | ||||
| -rw-r--r-- | client/app.js | 46 | ||||
| -rw-r--r-- | client/applet.js | 13 | ||||
| -rw-r--r-- | client/index.js | 92 | ||||
| -rw-r--r-- | client/store.js | 2 | ||||
| -rw-r--r-- | client/util.js | 26 |
6 files changed, 75 insertions, 108 deletions
diff --git a/client/actions.js b/client/actions.js index 3fd86e0d..779113f8 100644 --- a/client/actions.js +++ b/client/actions.js @@ -1,9 +1,9 @@ -import * as search from './search/search.actions' +// import * as search from './search/search.actions' // import * as review from './review/review.actions' // import * as metadata from './metadata/metadata.actions' export { - search, + // search, // review, // metadata, } diff --git a/client/app.js b/client/app.js deleted file mode 100644 index 6c008ec6..00000000 --- a/client/app.js +++ /dev/null @@ -1,46 +0,0 @@ -import React, { Component } from 'react' -import { ConnectedRouter } from 'connected-react-router' -import { Route, Switch } from 'react-router' - -import { Header, Sidebar, Footer } from './common' -import * as Metadata from './metadata' -import * as Search from './search' -import * as Review from './review' - -export default class App extends Component { - render() { - return ( - <ConnectedRouter history={this.props.history}> - <div> - <Header /> - <div className='app'> - <Route path="/metadata/" component={Sidebar} /> - <div className='body'> - <Route path="/search/" component={Search.Menu} /> - <Route path="/metadata/:hash/" component={Metadata.Heading} /> - <Switch> - <Route exact path="/metadata/:hash/summary/" component={Metadata.Summary} /> - <Route exact path="/metadata/:hash/mediaRecord/" component={Metadata.MediaRecord} /> - <Route exact path="/metadata/:hash/mediaInfo/" component={Metadata.MediaInfo} /> - <Route exact path="/metadata/:hash/keyframe/:frame/" component={Metadata.KeyframeSingle} /> - <Route exact path="/metadata/:hash/keyframe/" component={Metadata.KeyframeList} /> - <Route exact path="/metadata/:hash/coco/" component={Metadata.Coco} /> - <Route exact path="/metadata/:hash/places365/" component={Metadata.Places365} /> - <Route exact path="/metadata/:hash/sugarcube/" component={Metadata.Sugarcube} /> - <Route exact path="/metadata/:hash/" component={Metadata.Summary} /> - <Route exact path="/metadata/" render={() => <div className='notFound'><h4>NOT FOUND</h4></div>} /> - <Route exact path="/search/" component={Search.Container} /> - <Route exact path="/search/keyframe/:verified/:hash/:frame/" component={Search.Container} /> - <Route exact path="/search/keyframe/:hash/:frame/" component={Search.Container} /> - <Route exact path="/search/browse/:hash/" component={Search.Browse} /> - <Route exact path="/search/random/" component={Search.Random} /> - <Route exact path="/search/review/" component={Review.Saved} /> - </Switch> - </div> - </div> - <Footer /> - </div> - </ConnectedRouter> - ) - } -} diff --git a/client/applet.js b/client/applet.js new file mode 100644 index 00000000..f218a7f2 --- /dev/null +++ b/client/applet.js @@ -0,0 +1,13 @@ +import React, { Component } from 'react' + +// import { Header, Sidebar, Footer } from './common' + +export default class Applet extends Component { + render() { + return ( + <div className='applet'> + <pre style={{ color: '#0f0' }}>{'Megapixels'}</pre> + </div> + ) + } +} diff --git a/client/index.js b/client/index.js index 03015988..bc57f548 100644 --- a/client/index.js +++ b/client/index.js @@ -2,56 +2,78 @@ import React from 'react' import ReactDOM from 'react-dom' import { AppContainer } from 'react-hot-loader' import { Provider } from 'react-redux' +import Tabulator from 'tabulator-tables' -// import App from './app' - +import { toArray } from './util' +import Applet from './applet' import { store } from './store' -// const container = document.createElement('div') -// document.body.appendChild(container) - -toArray(document.querySelectorAll('.applet')).forEach(el => { - try { - const payload = JSON.parse(el.dataSet.getItem('payload')) - } catch(e) { - return - } - switch (payload.command) { - case 'load file': - append_tabulator(el, payload) - break - default: - append_react_applet(el, payload) - break - } -}) - -function append_react_applet(el, payload) { +function appendReactApplet(el, payload) { ReactDOM.render( <AppContainer> <Provider store={store}> - <App command={payload} /> + <Applet command={payload} /> </Provider> </AppContainer>, el ) } -function append_tabulator(el, payload) { + +function appendTabulator(el, payload) { const table = new Tabulator(el, { - height:"311px", - layout:"fitColumns", - placeholder:"No Data Set", - columns:[ - // {title:"Name", field:"name", sorter:"string", width:200}, - // {title:"Progress", field:"progress", sorter:"number", formatter:"progress"}, - // {title:"Gender", field:"gender", sorter:"string"}, + height: '311px', + layout: 'fitColumns', + placeholder: 'No Data Set', + columns: [ + // {title:'Name', field:'name', sorter:'string', width:200}, + // {title:'Progress', field:'progress', sorter:'number', formatter:'progress'}, + // {title:'Gender', field:'gender', sorter:"string"}, // {title:"Rating", field:"rating", formatter:"star", align:"center", width:100}, // {title:"Favourite Color", field:"col", sorter:"string", sortable:false}, // {title:"Date Of Birth", field:"dob", sorter:"date", align:"center"}, // {title:"Driver", field:"car", align:"center", formatter:"tickCross", sorter:"boolean"}, ], }) - const columns = payload.fields.split(', ') + let path = payload.opt + let columns = payload.fields.split(',').map(s => s.trim()) console.log(columns) - if () - table.setData(path) -}
\ No newline at end of file + if (path[0] !== '/') { + console.log(path) + } + // table.setData(path) +} + +function appendApplets() { + toArray(document.querySelectorAll('.applet')).forEach(el => { + console.log(el.dataset.payload) + let payload; + try { + payload = JSON.parse(el.dataset.payload) + } catch (e) { + return + } + console.log(payload) + switch (payload.command) { + case 'load file': + appendTabulator(el, payload) + break + default: + appendReactApplet(el, payload) + break + } + }) +} + +function main() { + const paras = document.querySelectorAll('section p') + if (paras.length) { + paras[0].classList.add('first_paragraph') + } + toArray(document.querySelectorAll('header .links a')).forEach(tag => { + if (window.location.href.match(tag.href)) { + tag.classList.add('active') + } + }) + appendApplets() +} + +main() diff --git a/client/store.js b/client/store.js index 9c0f78cd..3c7acefb 100644 --- a/client/store.js +++ b/client/store.js @@ -6,6 +6,7 @@ import thunk from 'redux-thunk' // import reviewReducer from './review/review.reducer' const rootReducer = combineReducers({ + auth: (state = {}) => state, // auth: (state = login()) => state, // metadata: metadataReducer, // search: searchReducer, @@ -16,6 +17,7 @@ function configureStore(initialState = {}) { const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose const store = createStore( + rootReducer, initialState, composeEnhancers( applyMiddleware( diff --git a/client/util.js b/client/util.js index 92b4addc..50d4992a 100644 --- a/client/util.js +++ b/client/util.js @@ -7,6 +7,7 @@ export const isMobile = isiPhone || isiPad || isAndroid export const isDesktop = !isMobile export const toArray = a => Array.prototype.slice.apply(a) +export const choice = a => a[Math.floor(Math.random() * a.length)] const htmlClassList = document.body.parentNode.classList htmlClassList.add(isDesktop ? 'desktop' : 'mobile') @@ -142,28 +143,3 @@ export const post = (uri, data, credentials) => { // headers['X-CSRFToken'] = csrftoken return fetch(uri, opt).then(res => res.json()) } - -// api queries -export const login = () => { - if (cachedAuth) return cachedAuth - const isLocal = (window.location.hostname === '0.0.0.0' || window.location.hostname === '127.0.0.1') - try { - const auth = JSON.parse(JSON.parse(localStorage.getItem('persist:root')).auth) - // console.log('auth', auth) - token = auth.token - username = auth.user.username - if (token) { - console.log('logged in', username) - } - cachedAuth = auth - if (!token && !isLocal) { - window.location.href = '/' - } - return auth - } catch (e) { - if (!isLocal) { - window.location.href = '/' - } - return {} - } -} |
