Skip to content
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
48 changes: 48 additions & 0 deletions almanac-web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "almanac-web",
"version": "0.1.0",
"private": true,
"dependencies": {
"@tinymce/tinymce-react": "^3.0.1",
"axios": "^0.18.0",
"history": "^4.6.3",
"marked": "^0.6.2",
"moment": "^2.24.0",
"moment-timezone": "^0.5.23",
"prismic-reactjs": "^0.3.2",
"react": "^16.4.2",
"react-datepicker": "^2.0.0",
"react-dom": "^16.4.2",
"react-dropdown": "^1.6.4",
"react-intl": "^2.8.0",
"react-moment": "^0.8.4",
"react-paginate": "^6.2.1",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"react-router-redux": "^5.0.0-alpha.6",
"react-rte": "^0.16.1",
"react-scripts": "1.1.4",
"redux": "^4.0.0",
"redux-devtools-extension": "^2.13.5",
"redux-logger": "^3.0.1",
"redux-sequence-action": "^0.2.1",
"redux-thunk": "^2.3.0",
"superagent": "^3.8.2",
"superagent-promise": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Binary file added almanac-web/public/favicon.ico
Binary file not shown.
18 changes: 18 additions & 0 deletions almanac-web/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link rel="stylesheet" href="//demo.productionready.io/main.css">
<link href="//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" type="text/css">
<link href="//fonts.googleapis.com/css?family=Titillium+Web:700|Source+Serif+Pro:400,700|Merriweather+Sans:400,700|Source+Sans+Pro:400,300,600,700,300italic,400italic,600italic,700italic|3d"
rel="stylesheet" type="text/css">

<title>Almanac</title>
</head>
<body>
<div id="root"></div>

</body>
</html>
15 changes: 15 additions & 0 deletions almanac-web/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
104 changes: 104 additions & 0 deletions almanac-web/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import agent from './agent';
import Header from './Header';
import React from 'react';
import { connect } from 'react-redux';
import { APP_LOAD, REDIRECT, SIGN_IN, LOGOUT } from './constants/actionTypes';
import { Route, Switch } from 'react-router-dom';
import Home from './containers/Home';
import { store } from './store';
import { push } from 'react-router-redux';
import Book from './containers/Book';
import Article from './containers/Article';
import './bootstrap.min.css'
import Profile from './containers/Profile';
import BookCreate from './containers/Book/BookCreate';
import BookList from './containers/Book/BookList';
import ArticleCreate from './containers/Article/ArticleCreate';
import BookEdit from './containers/Book/BookEdit';
import { IntlProvider } from 'react-intl';
import ArticleEdit from './containers/Article/ArticleEdit';
import Login from './containers/Authentication/Login';
import Register from './containers/Authentication/Register';

const mapStateToProps = state => {
return {
appLoaded: state.common.appLoaded,
appName: state.common.appName,
currentUser: state.common.currentUser,
redirectTo: state.common.redirectTo,
}
};

const mapDispatchToProps = dispatch => ({
onLoad: (payload, token) =>
dispatch({ type: APP_LOAD, payload, token, skipTracking: true }),
onRedirect: () =>
dispatch({ type: REDIRECT }),
onLoadProfile: (payload) =>
dispatch({ type: SIGN_IN, payload }),
onClickLogout: () => dispatch({ type: LOGOUT })
});


class App extends React.Component {
componentWillReceiveProps(nextProps) {
if (nextProps.redirectTo) {
store.dispatch(push(nextProps.redirectTo));
this.props.onRedirect();
}
}

componentWillMount() {
const token = window.localStorage.getItem('access_token');
if (token) {
agent.setToken(token);
this.props.onLoadProfile(agent.Auth.current())
}

this.props.onLoad(token ? agent.Auth.current() : null, token);
}
logout = () => {
this.props.onClickLogout();
}
render() {
if (!(window.location.pathname === "/login" ||
window.location.pathname === "/register") &&
!window.localStorage.getItem('access_token')) {
store.dispatch(push("/login"));
}

if (this.props.appLoaded) {
return (
<div>
<Header
appName={this.props.appName}
currentUser={this.props.currentUser}
onClickLogout={this.logout} />
<Switch>
<Route exact path="/" component={Home} />
<Route path="/profiles/:id" component={Profile} />
<Route path="/books/:bookId/articles/create" component={ArticleCreate} />
<Route path="/books/:bookId/articles/:articleId/edit" component={ArticleEdit} />
<Route path="/books/:bookId/articles/:articleId" component={Article} />
<Route path="/books/create" component={BookCreate} />
<Route path="/books/:id/edit" component={BookEdit} />
<Route path="/books/:id" component={Book} />
<Route path="/books" component={BookList} />
<Route path="/login" component={Login} />
<Route path="/register" component={Register} />
</Switch>
</div>
);
}
return (
<div>
<Header
appName={this.props.appName}
currentUser={this.props.currentUser}
onClickLogout={this.logout} />
</div>
);
}
}

export default connect(mapStateToProps, mapDispatchToProps)(App);
9 changes: 9 additions & 0 deletions almanac-web/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
21 changes: 21 additions & 0 deletions almanac-web/src/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { Link } from 'react-router-dom';
import HeaderList from './components/HeaderList'

class Header extends React.Component {
render() {
return (
<nav className="navbar navbar-light">
<div className="container">

<Link to="/" className="navbar-brand">
{this.props.appName.toLowerCase()}
</Link>
<HeaderList currentUser={this.props.currentUser} logout={this.props.onClickLogout} />
</div>
</nav>
);
}
}

export default Header;
26 changes: 26 additions & 0 deletions almanac-web/src/Navbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import Banner from './containers/Home/Banner';

const Navbar = (props) => {
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light mb-3" >
<div className="collapse navbar-collapse">
<Banner appName="TestName"/>
<ul className="navbar-nav mr-auto mt-2 mt-lg-0">

<li className="nav-item">
<a className="nav-link" href="/login">Login</a>
</li>
<li className="nav-item">
<a className="nav-link" href="/tickets">Tickets</a>
</li>
<li className="nav-item">
</li>
</ul>

</div>
</nav>

);
};
export default Navbar
100 changes: 100 additions & 0 deletions almanac-web/src/agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import superagentPromise from 'superagent-promise';
import _superagent from 'superagent';
import { DEFAULT_PAGE_SIZE } from './constants/commonConstants'

const superagent = superagentPromise(_superagent, global.Promise);

const API_ROOT = 'http://localhost:8080';

const encode = encodeURIComponent;
const responseBody = res => res.body;

let token = null;
const tokenPlugin = req => {
if (token) {
req.set('authorization', `Bearer ${token}`);
}
}
let basicAuth = "YWNtZTphY21lc2VjcmV0";
const basicPlugin = req => {
req.set('authorization', `Basic ${basicAuth}`)
}

const requests = {
del: url =>
superagent.del(`${API_ROOT}${url}`).use(tokenPlugin).then(responseBody),
get: url =>
superagent.get(`${API_ROOT}${url}`).use(tokenPlugin).then(responseBody),
put: (url, body) =>
superagent.put(`${API_ROOT}${url}`, body).use(tokenPlugin).then(responseBody),
post: (url, body) =>
superagent.post(`${API_ROOT}${url}`, body).use(tokenPlugin).then(responseBody),
postWithBasic: (url, body) =>
superagent.post(`${API_ROOT}${url}?grant_type=password&username=${body.username}&password=${body.password}`).use(basicPlugin).then(responseBody)
};

const directRequest = {
del: url =>
superagent.del(`${url}`).use(tokenPlugin).then(responseBody),
get: url =>
superagent.get(`${url}`).use(tokenPlugin).then(responseBody),
put: (url, body) =>
superagent.put(`${url}`, body).use(tokenPlugin).then(responseBody),
post: (url, body) =>
superagent.post(`${url}`, body).use(tokenPlugin).then(responseBody)
};

const Auth = {
current: () =>
requests.get('/users/user'),
login: (email, password) =>
requests.postWithBasic('/oauth/token', { username: email, password: password }),
register: (username, email, password) =>
requests.post('/users', { username, email, password }),
save: user =>
requests.put('/user', { user })
};

const Tags = {
getAll: () => requests.get('/tags')
};

const limit = (size, page) => `size=${size}&page=${page ? page : 0}`;
const Books = {
all: page =>
requests.get(`/books?${limit(localStorage.getItem("page_size") ? localStorage.getItem("page_size") : DEFAULT_PAGE_SIZE, page)}`),
del: slug =>
requests.del(`/books/${slug}`),
get: slug =>
requests.get(`/books/${slug}`),
update: (id, book) =>
requests.put(`/books/${id}`, { ...book }),
create: book =>
requests.post('/books', { ...book })
};
const Articles = {
del: (bookId, articleId) =>
requests.del(`/books/${bookId}/articles/${articleId}`),
get: (bookId, articleId) =>
requests.get(`/books/${bookId}/articles/${articleId}`),
update: (bookId, articleId, article) =>
requests.put(`/books/${bookId}/articles/${articleId}`, { ...article }),
create: (bookId, article) =>
requests.post(`/books/${bookId}/articles`, { ...article })
};

const Profile = {
get: id =>
requests.get(`/users/${id}`),
me: () =>
requests.get(`/users/me`)
};

export default {
Books,
Auth,
Profile,
directRequest,
Articles,
setToken: _token => { token = _token; }
};
7 changes: 7 additions & 0 deletions almanac-web/src/bootstrap.min.css

Large diffs are not rendered by default.

Loading