1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-23 04:42:24 +03:00

[GD-11] Rename CategoryChild

This commit is contained in:
Artyom 2017-05-04 20:15:23 +03:00
parent 150a8df543
commit e1da1fa939
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710
4 changed files with 45 additions and 52 deletions

View File

@ -1,7 +1,7 @@
// @flow
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';
class App extends Component {
@ -11,7 +11,7 @@ class App extends Component {
<Router>
<Switch>
<Route exact path="/" component={ Home } />
<Route path="/haskell/:uid" component={ CategoryChild } />
<Route path="/haskell/:uid" component={ Category } />
<Route component={ NoMatch } />
</Switch>
</Router>

View File

@ -1,7 +1,47 @@
// @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 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 }

View File

@ -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 }

View File

@ -1,13 +1,13 @@
import { GrandCategory } from './GrandCategory';
import { Tiles } from './Tiles';
import { CategoryChild } from './CategoryChild';
import { Category } from './Category';
import { Home } from './Home';
import { NoMatch } from './NoMatch';
module.exports = {
GrandCategory,
Tiles,
CategoryChild,
Category,
Home,
NoMatch
}