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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ app/assets/javascripts/bundle.js.map

/app/assets/builds/*
!/app/assets/builds/.keep

bundle.js
bundle.js.map
bundle.js.LICENSE.txt
14 changes: 14 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
"stories": [
"../stories/**/*.stories.mdx",
"../stories/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"@storybook/addon-postcss",
"storybook-addon-designs/register"
],
"framework": "@storybook/react"
}
9 changes: 9 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32,791 changes: 16,938 additions & 15,853 deletions app/assets/javascripts/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/views/api/sessions/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1 @@
json.partial! 'api/users/user', user: @user
json.partial! 'api/sessions/session', user: @user
13 changes: 10 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

<% if logged_in? %>
<script>
window.currentUser = {
username: '<%= current_user.username %>',
name: '<%= current_user.name %>'
};
</script>
<% end %>

<%# fonts %>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />

</head>

<body>
<main class="container mx-auto mt-28 px-5 flex">
<%= yield %>
</main>
<%= yield %>
</body>
</html>
Binary file added frontend/assets/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 20 additions & 36 deletions frontend/components/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React from "react";

import { connect } from "react-redux";
import { logoutUser } from "../actions/session_actions";

import { Switch, Route, Link } from "react-router-dom";
import { AuthRoute, ProtectedRoute } from "../utils/route_util";
import {
Expand All @@ -17,20 +14,9 @@ import {
Siddur,
SiddurEdit,
} from "./components";
import { Header } from "./header";

const mapStateToProps = (state) => {
return {
loggedIn: Boolean(state.session.currentUser.id)
};
};

const mapDispatchToProps = (dispatch) => {
return {
logOut: () => dispatch(logoutUser())
};
};

const App = function(props) {
const App = (props) => {

const links = {
"Chumash": "/chumash",
Expand All @@ -41,46 +27,42 @@ const App = function(props) {
};

const externalLinks = {
"Shnayim Mikra": "/shnayimmikra",
"Tikkun Korim": "/tikkun/online",
"Github": "/github",
"Shnayim Mikra": {
path: "/shnayimmikra",
url: "https://shafehorg.github.io/Shnayim-Mikra/",
},
"Tikkun Korim": {
path: "/tikkun/online",
url: "https://www.sharshi.com/tikkunkorim/",
},
"Github": {
path: "/github",
url: "https://github.com/ShafehOrg/daily-learning",
},
};

const nav = (
<nav>
<div className="internal-links">{Object.keys(links).map(text => {
const link = links[text];
return <div key={text}>
<Link to={`${link}`} > {text} </Link>
<Link to={`${ link }`} > { text } </Link>
</div>
})}</div>
<br />
external:
<div className="external-links">{Object.keys(externalLinks).map(text => {
const link = externalLinks[text];
return <div key={text}>
<Link to={`${link}`} > {text} </Link>
<a href={`${ link.url }`} target="_blank" > { text } </a>
</div>
})}</div>
</nav>
);

const session = (
<>
{ props.loggedIn ?
<Link to="/" onClick={props.logOut}> Log out </Link> :
<>
<Link to="/login"> Login </Link>
<Link to="/signup"> Sign Up </Link>
</>
}
</>
)

return (
<div>
<Link to="/" > Shafeh: Daily Learning </Link>
{session}
<Header />
{nav}
<main >
<Switch>
Expand Down Expand Up @@ -137,10 +119,12 @@ const App = function(props) {
<Route exact path="/tikkun/online" render={() => (window.location = "https://www.sharshi.com/tikkunkorim/")} />
<Route exact path="/github" render={() => (window.location = "https://github.com/ShafehOrg/daily-learning")} />
<Route component={() => 404} />
<Link to={{ pathname: "https://example.zendesk.com/hc/en-us/articles/123456789-Privacy-Policies" }} target="_blank" />

</Switch>
</main>
</div>
);
}

export default connect(mapStateToProps, mapDispatchToProps)(App);
export default App;
32 changes: 32 additions & 0 deletions frontend/components/header.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.wrapper {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
padding: 15px 20px;
display: flex;
align-items: center;
justify-content: space-between;
}

svg {
display: inline-block;
vertical-align: top;
}

h1 {
font-weight: 900;
font-size: 20px;
line-height: 1;
margin: 6px 0 6px 10px;
display: inline-block;
vertical-align: top;
}

button + button {
margin-left: 10px;
}

.welcome {
color: #333;
font-size: 14px;
margin-right: 10px;
}
20 changes: 20 additions & 0 deletions frontend/components/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import PropTypes from 'prop-types';

import { Logo } from './logo';
import Session from './session';
import './header.css';

export const Header = () => (
<header>
<div>
<Logo />
<h1>Shafeh</h1>
</div>
<div>
<Session />
</div>
</header>
);


14 changes: 14 additions & 0 deletions frontend/components/logo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.storybook-logo--small {
width: 32px;
height: 32px;
}

.storybook-logo--medium {
width: 48px;
height: 48px;
}

.storybook-logo--large {
width: 64px;
height: 64px;
}
40 changes: 40 additions & 0 deletions frontend/components/logo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import PropTypes from 'prop-types';
import './logo.css';
import Image from '../assets/logo.jpg';

/**
* Primary UI component for the app logo
*/
export const Logo = ({ size, alt, ...props }) => {
return (
<img
src={Image}
alt={alt}
className={['storybook-logo', `storybook-logo--${size}`].join(' ')}
{...props}
/>
);
};

Logo.propTypes = {
/**
* How large should the logo be?
*/
size: PropTypes.oneOf(['small', 'medium', 'large']),
/**
* Optional click handler
*/
onClick: PropTypes.func,
/**
* Optional alt text
* @default 'Logo'
*/
alt: PropTypes.string,
};

Logo.defaultProps = {
size: 'small',
onClick: undefined,
alt: 'Logo',
};
13 changes: 13 additions & 0 deletions frontend/components/provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'
import { Provider } from 'react-redux'
import { HashRouter } from "react-router-dom";

const ProviderWrapper = ({ children, store }) => (
<Provider store={store}>
<HashRouter>
{children}
</HashRouter>
</Provider>
)

export default ProviderWrapper
43 changes: 43 additions & 0 deletions frontend/components/session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from "react";
import { connect } from "react-redux";
import { logoutUser } from "../actions/session_actions";
import { Link } from "react-router-dom";
import PropTypes from 'prop-types';

const mapStateToProps = (state) => {
return {
loggedIn: Boolean(state.session.currentUser.name)
};
};

const mapDispatchToProps = (dispatch) => {
return {
logOut: () => dispatch(logoutUser())
};
};

export const Session = ({ loggedIn, logOut }) => {
return (
<>
{ loggedIn ?
<Link to="/" onClick={ logOut }> Log out </Link> :
<>
<Link to="/login"> Login </Link>
<Link to="/signup"> Sign Up </Link>
</>
}
</>
);
};

Session.propTypes = {
loggedIn: PropTypes.bool.isRequired,
logOut: PropTypes.func.isRequired,
};

Session.defaultProps = {
loggedIn: true,
logOut: () => {},
};

export default connect(mapStateToProps, mapDispatchToProps)(Session);
19 changes: 18 additions & 1 deletion frontend/daily_learning.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ import Root from "./root";
import configureStore from "./store/store";

document.addEventListener("DOMContentLoaded", () => {
const store = configureStore();
const root = document.getElementById("root");

let store;
if (window.currentUser) {
const preloadedState = {
session: {
"currentUser": {
name: currentUser.name,
username: currentUser.username,
}
}
};
store = configureStore(preloadedState);
} else {
store = configureStore();
}
delete window.currentUser;


ReactDOM.render( <Root store={store} />, root );
});
7 changes: 5 additions & 2 deletions frontend/reducers/session_reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { REMOVE_USER, RECEIVE_USER_SIGNIN } from "../actions/session_actions";

/**
* TODO: Save the session state to localStorage
*/
const defaultState = {
currentUser: {
id: null,
name: null,
username: null
},
};
Expand All @@ -12,7 +15,7 @@ const sessionReducer = (state = defaultState, action) => {
case RECEIVE_USER_SIGNIN:
return {
currentUser: {
id: action.user.id,
name: action.user.name,
username: action.user.username
},
};
Expand Down
Loading