1
Fork 0

Remove URL reversing

This commit is contained in:
Jake Howard 2016-04-05 19:40:45 +01:00
parent 38f4c7a041
commit 3f11b1cc18
3 changed files with 14 additions and 67 deletions

View file

@ -1,29 +1,9 @@
import React from 'react';
import Reverser from '../../helpers/reverser';
export default class Item extends React.Component {
constructor() {
super();
this.state = {
url: '#'
};
}
componentDidMount() {
if (!this.props.href && !this.props.ident) {
return;
}
if (this.props.href) {
this.setState({url: this.props.href});
} else {
Reverser(this.props.ident, this.props.args, function (url) {
this.setState({ url });
}.bind(this));
}
}
render() {
const href = this.props.href.endsWith('/') ? this.props.href : this.props.href + '/';
let icon;
if (this.props.icon) {
if (this.props.icon.startsWith('ion')) {
@ -37,7 +17,7 @@ export default class Item extends React.Component {
}
}
return (
<li><a href={this.state.url}>{icon}{this.props.children}</a></li>
<li><a href={href}>{icon}{this.props.children}</a></li>
);
}
}

View file

@ -18,14 +18,15 @@ export default class NavBar extends React.Component {
</ul>
<ul className="nav navbar-nav" id="navigation">
<Dropdown title="Projects">
<Item ident="projects:project" args={['pithos']} icon="ion-social-freebsd-devil">Pithos</Item>
<Item ident="projects:project" args={['bsod-enabler']} icon="ion-ios-monitor">BSOD Enabler</Item>
<Item href="/projects/pithos/" icon="ion-social-freebsd-devil">Pithos</Item>
<Item href="/projects/bsod-enabler/" icon="ion-ios-monitor">BSOD Enabler</Item>
<Item
ident="projects:project"
args={['hipchat-emoticons-for-all']}
icon="ion-chatbox-working">Hipchat Emoticons for All</Item>
href="/projects/hipchat-emoticons-for-all/"
icon="ion-chatbox-working">
Hipchat Emoticons for All
</Item>
<Item href="#" icon="ion-social-windows">Custom PC</Item>
<Item ident="projects:all" icon="ion-android-more-vertical">All Projects...</Item>
<Item href="/projects/all/" icon="ion-android-more-vertical">All Projects...</Item>
</Dropdown>
<Dropdown title="Code">
<Item href="#" icon="ion-code-working">Code Challenges</Item>
@ -33,9 +34,9 @@ export default class NavBar extends React.Component {
<Item href="#" icon="ion-ios-game-controller-a">The Wiki Game Solver</Item>
</Dropdown>
<Dropdown title="College">
<Item ident="robotics:index">Student Robotics</Item>
<Item ident="college:attack-on-blocks" icon="ion-cube">Attack on Blocks Game</Item>
<Item ident="college:student-server" icon="glyphicon-hdd">Student Server</Item>
<Item href="/robotics">Student Robotics</Item>
<Item href="/college/attack-on-blocks" icon="ion-cube">Attack on Blocks Game</Item>
<Item href="/college/student-server" icon="glyphicon-hdd">Student Server</Item>
<Item href="#" icon="ion-ios-paper">EPQ</Item>
<Item href="#">Wall of Sheep</Item>
</Dropdown>
@ -61,9 +62,8 @@ export default class NavBar extends React.Component {
</Dropdown>
<Item href="#">Links</Item>
<Dropdown title="About">
<Item ident="about:me" icon="ion-android-person">Me</Item>
<Item ident="about:website" icon="ion-cloud">Website</Item>
<Item ident="about:index" icon="ion-android-contacts">Contact Me</Item>
<Item href="/about/me" icon="ion-android-person">Me</Item>
<Item href="/about/website" icon="ion-cloud">Website</Item>
</Dropdown>
</ul>
</div>

View file

@ -1,33 +0,0 @@
export default function Reverser(ident, args, onSuccess) {
let body = {};
if (ident) {
body.ident = ident;
if (args) {
body.args = args;
}
}
if (body !== {}) {
body = JSON.stringify(body);
fetch('/reverse/', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body
}).then(function (response) {
if (response.status === 302) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
throw error;
}
}).then(
(response) => response.json()
).then(onSuccess)
.catch(function (err) {
console.log(err);
});
}
}