Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Radium #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@ import "babel-core/polyfill";
import React from "react";
import Router from "react-router";

// Common utilities
import Session from "./common/session";

// Routers
import LoggedOutRouter from "./routers/logged_out";
import LoggedInRouter from "./routers/logged_in";
import AppRouter from "./routers/app";


// ID of the DOM element to mount app on
const DOM_APP_EL_ID = "app";


// Initialize routes depending on session
let routes;

if (Session.isLoggedIn()) {
routes = LoggedInRouter.getRoutes();
} else {
routes = LoggedOutRouter.getRoutes();
}
let routes = AppRouter.getRoutes();

/**
* Given a set of routes and params associated with the current active state,
Expand Down Expand Up @@ -79,4 +69,4 @@ Router.run(routes, function(Handler, state) {
fetchData(state.routes, state.params).then((data) => {
React.render(<Handler data={data} />, document.getElementById(DOM_APP_EL_ID));
});
});
});
7 changes: 6 additions & 1 deletion src/pages/home/page.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from "react";
import { getData } from "../../common/request";
// import { MatchMediaItem } from "radium"


export default class HomePage extends React.Component {
// constructor() {
// this.mixins = [MatchMediaItem]
// }

componentWillMount() {
console.log("[HomePage] will mount with server response: ", this.props.data.home);
}
Expand All @@ -20,4 +25,4 @@ export default class HomePage extends React.Component {

HomePage.fetchData = function(params) {
return getData("/home");
}
}
7 changes: 6 additions & 1 deletion src/pages/landing/page.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from "react";
import { getData } from "../../common/request";
// import { MatchMediaItem } from "radium"


export default class LandingPage extends React.Component {
// constructor() {
// this.mixins = [MatchMediaItem]
// }

componentWillMount() {
console.log("[LandingPage] will mount with server response: ", this.props.data.landing);
}
Expand All @@ -20,4 +25,4 @@ export default class LandingPage extends React.Component {

LandingPage.fetchData = function(params) {
return getData("/landing");
}
}
48 changes: 48 additions & 0 deletions src/routers/app.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from "react";
import { Route, RouteHandler } from "react-router";

// Routers
import LoggedOutRouter from "./logged_out";
import LoggedInRouter from "./logged_in";

// Common utilities
import Session from "../common/session";


// Media queries
// import { MatchMediaBase } from "radium"


// MatchMediaBase.init({
// sm: "(min-width: 768px)",
// md: "(min-width: 992px)",
// lg: "(min-width: 1200px)"
// });

export default class AppRouter extends React.Component {
constructor() {
// this.mixins = [MatchMediaBase]
}

render() {
return (
<RouteHandler {...this.props} />
);
}
}

AppRouter.getRoutes = function() {
let routes;

if (Session.isLoggedIn()) {
routes = LoggedInRouter.getRoutes();
} else {
routes = LoggedOutRouter.getRoutes();
}

return (
<Route name="app" path="/" handler={AppRouter}>
{routes}
</Route>
);
}
4 changes: 2 additions & 2 deletions src/routers/logged_in.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default class LoggedInRouter extends React.Component {

LoggedInRouter.getRoutes = function() {
return (
<Route name="app" path="/" handler={LoggedInRouter}>
<Route handler={LoggedInRouter}>
<DefaultRoute name="home" handler={HomePage} />
</Route>
);
}
}
4 changes: 2 additions & 2 deletions src/routers/logged_out.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default class LoggedOutRouter extends React.Component {

LoggedOutRouter.getRoutes = function() {
return (
<Route name="app" path="/" handler={LoggedOutRouter}>
<Route handler={LoggedOutRouter}>
<DefaultRoute name="landing" handler={LandingPage} />
</Route>
);
}
}