-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work-in-progress on routing, renders mock-api content at
- /static/#/browse/src - /static/#/browse/src/lib.rs
- Loading branch information
1 parent
f63767e
commit 1561349
Showing
5 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2017 The Rustw Project Developers. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<string>, | ||
files?: any, | ||
highlight?: any, | ||
lineStart?: any, | ||
getSource?: (path :string) => any, | ||
name: any, | ||
} | ||
|
||
export class CodeBrowser extends React.Component<Props, State> { | ||
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 <SourceView path={path} lines={this.state.lines} highlight={this.state.highlight} scrollTo={this.state.lineStart} /> | ||
} else { | ||
return <DirView file={this.state.name} files={this.state.files} getSource={this.state.getSource} />; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 The Rustw Project Developers. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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}) => | ||
<div id="div_app"> | ||
<div id="div_main"> | ||
{children} | ||
</div> | ||
</div> | ||
|
||
export const Home = () => | ||
<PageTemplate> | ||
<section className="home"> | ||
[Home] | ||
</section> | ||
</PageTemplate> | ||
|
||
export const Search = () => | ||
<PageTemplate> | ||
<section className="search"> | ||
[Search] | ||
</section> | ||
</PageTemplate> | ||
|
||
export const Source = ({match}) => | ||
<PageTemplate> | ||
<section className="source"> | ||
<CodeBrowser path={match.params[0]} /> | ||
</section> | ||
</PageTemplate> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters