mirror of
https://github.com/aelve/guide.git
synced 2024-12-23 12:52:31 +03:00
[GD-11] Rename CategoryChild
This commit is contained in:
parent
150a8df543
commit
e1da1fa939
@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { CategoryChild, Home, NoMatch } from './components/index';
|
import { Category, Home, NoMatch } from './components/index';
|
||||||
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
|
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
@ -11,7 +11,7 @@ class App extends Component {
|
|||||||
<Router>
|
<Router>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/" component={ Home } />
|
<Route exact path="/" component={ Home } />
|
||||||
<Route path="/haskell/:uid" component={ CategoryChild } />
|
<Route path="/haskell/:uid" component={ Category } />
|
||||||
<Route component={ NoMatch } />
|
<Route component={ NoMatch } />
|
||||||
</Switch>
|
</Switch>
|
||||||
</Router>
|
</Router>
|
||||||
|
@ -1,7 +1,47 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
import * as T from '../types';
|
||||||
|
import { fetchData } from '../utils/index';
|
||||||
|
import { If } from 'jsx-control-statements';
|
||||||
|
|
||||||
|
function extractUid(link : string) {
|
||||||
|
const lastOccur = link.lastIndexOf('-');
|
||||||
|
return link.slice(lastOccur + 1);
|
||||||
|
}
|
||||||
|
|
||||||
class Category extends Component {
|
class Category extends Component {
|
||||||
|
state: {
|
||||||
|
cat: T.Cat;
|
||||||
|
};
|
||||||
|
componentWillMount() {
|
||||||
|
this.setState({ cat: [] });
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
const uid = extractUid(this.props.match.params.uid);
|
||||||
|
|
||||||
|
fetchData('http://localhost:8080/haskell/api/category/'+uid)
|
||||||
|
.then(data => this.setState({cat: data}))
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
|
||||||
|
const item = (uid, name) => {
|
||||||
|
return ( <li key={uid}>{name}</li> )
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>{ this.state.cat.title }</h1>
|
||||||
|
<If condition={this.state.cat.description !== undefined}>
|
||||||
|
<div dangerouslySetInnerHTML={{__html:
|
||||||
|
this.state.cat.description.html}} />
|
||||||
|
</If>
|
||||||
|
<If condition={this.state.cat.items !== undefined}>
|
||||||
|
{ this.state.cat.items.map(i => item(i.uid, i.name)) }
|
||||||
|
</If>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = { Category }
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
// @flow
|
|
||||||
|
|
||||||
import React, { Component } from 'react';
|
|
||||||
import * as T from '../types';
|
|
||||||
import { fetchData } from '../utils/index';
|
|
||||||
import { If } from 'jsx-control-statements';
|
|
||||||
|
|
||||||
function extractUid(link : string) {
|
|
||||||
const lastOccur = link.lastIndexOf('-');
|
|
||||||
return link.slice(lastOccur + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CategoryChild extends Component {
|
|
||||||
state: {
|
|
||||||
cat: T.Cat;
|
|
||||||
};
|
|
||||||
componentWillMount() {
|
|
||||||
this.setState({ cat: [] });
|
|
||||||
}
|
|
||||||
componentDidMount() {
|
|
||||||
const uid = extractUid(this.props.match.params.uid);
|
|
||||||
|
|
||||||
fetchData('http://localhost:8080/haskell/api/category/'+uid)
|
|
||||||
.then(data => this.setState({cat: data}))
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
|
|
||||||
const item = (uid, name) => {
|
|
||||||
return ( <li key={uid}>{name}</li> )
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>{ this.state.cat.title }</h1>
|
|
||||||
<If condition={this.state.cat.description !== undefined}>
|
|
||||||
<div dangerouslySetInnerHTML={{__html:
|
|
||||||
this.state.cat.description.html}} />
|
|
||||||
</If>
|
|
||||||
<If condition={this.state.cat.items !== undefined}>
|
|
||||||
{ this.state.cat.items.map(i => item(i.uid, i.name)) }
|
|
||||||
</If>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { CategoryChild }
|
|
@ -1,13 +1,13 @@
|
|||||||
import { GrandCategory } from './GrandCategory';
|
import { GrandCategory } from './GrandCategory';
|
||||||
import { Tiles } from './Tiles';
|
import { Tiles } from './Tiles';
|
||||||
import { CategoryChild } from './CategoryChild';
|
import { Category } from './Category';
|
||||||
import { Home } from './Home';
|
import { Home } from './Home';
|
||||||
import { NoMatch } from './NoMatch';
|
import { NoMatch } from './NoMatch';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
GrandCategory,
|
GrandCategory,
|
||||||
Tiles,
|
Tiles,
|
||||||
CategoryChild,
|
Category,
|
||||||
Home,
|
Home,
|
||||||
NoMatch
|
NoMatch
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user