diff --git a/client/app/app.tsx b/client/app/app.tsx index 56edf03..07cf2e4 100644 --- a/client/app/app.tsx +++ b/client/app/app.tsx @@ -1,6 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import Wrapper from './Wrapper'; +import { Routes } from './routes'; import 'babel-polyfill'; -ReactDOM.render(, document.getElementById('app')); +ReactDOM.render(, document.getElementById('app')); diff --git a/client/app/components/login-button/login-button.tsx b/client/app/components/login-button/login-button.tsx index c3f0eb0..47d59a5 100644 --- a/client/app/components/login-button/login-button.tsx +++ b/client/app/components/login-button/login-button.tsx @@ -18,8 +18,6 @@ export class LoginButton extends React.Component { } render() { - console.log(process.env); - return (
diff --git a/client/app/model/category.ts b/client/app/model/category.ts new file mode 100644 index 0000000..4cac201 --- /dev/null +++ b/client/app/model/category.ts @@ -0,0 +1,5 @@ +export interface CategoryModel { + id: number; + category: string; + title: string; +} diff --git a/client/app/model/index.ts b/client/app/model/index.ts new file mode 100644 index 0000000..6ba47fd --- /dev/null +++ b/client/app/model/index.ts @@ -0,0 +1,2 @@ +export * from './category'; +export * from './user'; diff --git a/client/app/model/user.ts b/client/app/model/user.ts new file mode 100644 index 0000000..7f6132b --- /dev/null +++ b/client/app/model/user.ts @@ -0,0 +1,3 @@ +export interface UserModel { + +} diff --git a/client/app/pages/index.ts b/client/app/pages/index.ts index 5ebb9d8..45a4002 100644 --- a/client/app/pages/index.ts +++ b/client/app/pages/index.ts @@ -3,3 +3,5 @@ export * from './home/home'; export * from './not-found/not-found'; export * from './oauth/oauth'; export * from './realms/realms'; +export * from './user-account/user-account'; + diff --git a/client/app/pages/oauth/oauth.tsx b/client/app/pages/oauth/oauth.tsx index 468686e..ea2304f 100644 --- a/client/app/pages/oauth/oauth.tsx +++ b/client/app/pages/oauth/oauth.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { parse } from 'query-string'; -import axios from '../../axios/axios'; +import { UserService } from '../../services'; interface Props extends RouteComponentProps {} @@ -15,9 +15,7 @@ export class Oauth extends React.Component { private async login(queryString: string) { try { const code = parse(queryString).code; - const res = await axios.post('/api/battlenet/authorize', { code }); - const account = res.data.data; - localStorage.setItem('account', JSON.stringify(account)); + await UserService.authorize(code); window.opener.location.reload(); // TODO: this doesn't work on mobile currently window.close(); diff --git a/client/app/pages/realms/realms.tsx b/client/app/pages/realms/realms.tsx index c6963ed..2dc997d 100644 --- a/client/app/pages/realms/realms.tsx +++ b/client/app/pages/realms/realms.tsx @@ -1,25 +1,21 @@ import React from 'react'; import { chain } from 'lodash'; -import { Link } from 'react-router-dom'; -import axios from '../../axios/axios'; +import { Link, RouteComponentProps } from 'react-router-dom'; +import { CategoryService } from '../../services'; +import { CategoryModel } from '../../model'; import { ContentContainer } from '../../components'; import './realms.scss'; import header_realmforums from '../../assets/header-realmforums.gif'; import realms_large from '../../assets/realms-large.gif'; -interface Props {} +interface Props extends RouteComponentProps {} interface State { - realms: Realm[]; -} - -interface Realm { - id: number; - category: string; - title: string; + realms: CategoryModel[]; } export class Realms extends React.Component { + constructor(props: Props) { super(props); this.state = { @@ -29,8 +25,8 @@ export class Realms extends React.Component { async componentDidMount() { try { - const res = await axios.get('/api/category'); - const realms = chain(res.data.data) + const res = await CategoryService.getCategories(); + const realms = chain(res) .filter({ category: 'realm' }) .orderBy(['title']) .value(); @@ -40,7 +36,7 @@ export class Realms extends React.Component { } } - private renderRealms(realms: Realm[]): any { + private renderRealms(realms: CategoryModel[]): any { return realms.map((realm) => { return (
  • diff --git a/client/app/pages/user-account/user-account.tsx b/client/app/pages/user-account/user-account.tsx new file mode 100644 index 0000000..b36338a --- /dev/null +++ b/client/app/pages/user-account/user-account.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { RouteComponentProps } from 'react-router-dom'; +import { ContentContainer } from '../../components'; +import { UserService } from '../../services'; + +interface Props extends RouteComponentProps {} + +interface State {} + +export class UserAccount extends React.Component { + + componentDidMount() { + console.log(UserService.getUser()); + } + + render() { + return ( + + ); + } +} diff --git a/client/app/Wrapper.tsx b/client/app/routes.tsx similarity index 66% rename from client/app/Wrapper.tsx rename to client/app/routes.tsx index 084ca4f..f070034 100644 --- a/client/app/Wrapper.tsx +++ b/client/app/routes.tsx @@ -1,8 +1,7 @@ import React from 'react'; import { BrowserRouter, Route, Switch } from 'react-router-dom'; - import { Footer, Header } from './components'; -import { Forum, Home, NotFound, Oauth, Realms } from './pages'; +import { Forum, Home, NotFound, Oauth, Realms, UserAccount } from './pages'; // styling import './scss/index.scss'; @@ -11,18 +10,7 @@ interface Props {} interface State {} -export default class Wrapper extends React.Component { - constructor(props: Props) { - super(props); - } - - componentDidMount() { - const storedAccount = localStorage.getItem('account'); - - if (storedAccount) { - console.log(JSON.parse(storedAccount)); - } - } +export class Routes extends React.Component { public render() { return ( @@ -34,6 +22,7 @@ export default class Wrapper extends React.Component { +