From 99d7ce24e92a6cc76716386dbf55fccfd2df28e9 Mon Sep 17 00:00:00 2001 From: Nicole Anderson Date: Sun, 24 Sep 2017 20:07:01 -0700 Subject: [PATCH] Work-in-progress on routing, renders mock-api content at - /static/#/browse/src - /static/#/browse/src/lib.rs --- package.json | 3 ++ static/app.js | 22 ++++++++-- static/codeBrowser.tsx | 96 ++++++++++++++++++++++++++++++++++++++++++ static/pages.js | 39 +++++++++++++++++ static/srcView.js | 2 +- 5 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 static/codeBrowser.tsx create mode 100644 static/pages.js diff --git a/package.json b/package.json index 6f78695..41a2e70 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,16 @@ }, "dependencies": { "@types/react": "^16.0.5", + "@types/react-dom": "^15.5.4", "@types/react-redux": "^5.0.8", + "@types/react-router-dom": "^4.0.7", "@types/redux": "^3.6.0", "css-loader": "^0.28.7", "eslint-plugin-jquery": "^1.2.1", "react": "^15.4.2", "react-dom": "^15.4.2", "react-redux": "^5.0.5", + "react-router-dom": "^4.2.2", "redux": "^3.7.0", "redux-thunk": "^2.2.0", "style-loader": "^0.18.2" diff --git a/static/app.js b/static/app.js index 45bf631..50bf4fc 100644 --- a/static/app.js +++ b/static/app.js @@ -24,6 +24,18 @@ import { DirView } from './dirView'; import { SourceViewController } from './srcView'; import { Summary } from './summary'; +import { + HashRouter, + Route, + Redirect +} from 'react-router-dom'; + +import { + Home, + Search, + Source +} from './pages'; + // TODOs in build class RustwApp extends React.Component { @@ -128,9 +140,13 @@ let store = createStore(rustwReducer, applyMiddleware(thunk)); export function renderApp() { ReactDOM.render( - - - , + +
+ + + +
+
, document.getElementById('container') ); } diff --git a/static/codeBrowser.tsx b/static/codeBrowser.tsx new file mode 100644 index 0000000..6ea8175 --- /dev/null +++ b/static/codeBrowser.tsx @@ -0,0 +1,96 @@ +// Copyright 2017 The Rustw Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +import * as React from 'react'; + +import * as utils from './utils'; +import { DirView } from './dirView'; +import { SourceView } from './srcView'; + +declare const $: any; + +interface Props { + path: string, +} + +// TODO: consider switching path to default prop with value of 'src' +// interface DefaultProps { +// path: string, +// } + +interface State { + isFile: boolean, + lines?: Array, + files?: any, + highlight?: any, + lineStart?: any, + getSource?: (path :string) => any, + name: any, +} + +export class CodeBrowser extends React.Component { + constructor(props: Props) { + super(props); + this.state = { + isFile: false, + lines: [], + files: [], + highlight: [], + lineStart: [], + getSource: (path) => {}, + name: this.props.path, + } + } + + componentWillMount() { + const path = this.props.path; + $.ajax({ + url: 'http://localhost:3000/src' + path, // json-server mock API base url + type: 'GET', + dataType: 'JSON', + cache: false + }) + .done((json: any) => { + if (json.Directory) { + this.setState({ + isFile: false, + files: json.Directory.files, + lines: [], + highlight: [], + lineStart: [], + name: this.props.path, + }); + } else if (json.Source) { + this.setState({ + isFile: true, + lines: json.Source.lines, + highlight: [], + lineStart: [], + }); + } else { + console.log("Unexpected source data.") + console.log(json); + } + }) + .fail(function (xhr: any, status: any, errorThrown: any) { + // console.log(errStr); + console.log("error: " + errorThrown + "; status: " + status); + + }); + } + + render() { + const path = this.props.path.split('/'); + + if (this.state.isFile) { + return + } else { + return ; + } + } +} diff --git a/static/pages.js b/static/pages.js new file mode 100644 index 0000000..69f338f --- /dev/null +++ b/static/pages.js @@ -0,0 +1,39 @@ +// Copyright 2017 The Rustw Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +import * as React from 'react'; + +import { CodeBrowser } from './codeBrowser'; + +const PageTemplate = ({children}) => +
+
+ {children} +
+
+ +export const Home = () => + +
+ [Home] +
+
+ +export const Search = () => + +
+ [Search] +
+
+ +export const Source = ({match}) => + +
+ +
+
diff --git a/static/srcView.js b/static/srcView.js index 3c96e53..9821fc5 100644 --- a/static/srcView.js +++ b/static/srcView.js @@ -85,7 +85,7 @@ function view_in_vcs(target) { window.open(CONFIG.vcs_link.replace("$file", file_name).replace("$line", line_number), '_blank'); } -class SourceView extends React.Component { +export class SourceView extends React.Component { constructor(props) { super(props); this.state = { refMenu: null };