Split rendering sidebar & app
This commit is contained in:
parent
762826ed85
commit
98f6b39874
8 changed files with 41 additions and 28 deletions
|
|
@ -10,10 +10,6 @@ import PostModal from './components/PostModal.js';
|
||||||
import Messages from '../../components/Messages.js';
|
import Messages from '../../components/Messages.js';
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
componentDidMount() {
|
|
||||||
this.props.fetchCategories();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: render sidebar separate from main component
|
// TODO: render sidebar separate from main component
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
|
@ -70,8 +66,4 @@ const mapStateToProps = state => {
|
||||||
return { error, post: state.selected.post };
|
return { error, post: state.selected.post };
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
export default connect(mapStateToProps)(App);
|
||||||
fetchCategories: () => dispatch(fetchCategories()),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(App);
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { filterCategories, filterRules } from './filters.js';
|
import { filterCategories, filterRules } from './filters.js';
|
||||||
|
|
||||||
|
import { fetchCategories } from '../../actions/categories';
|
||||||
import { CATEGORY_TYPE, RULE_TYPE } from '../../constants.js';
|
import { CATEGORY_TYPE, RULE_TYPE } from '../../constants.js';
|
||||||
import LoadingIndicator from '../../../../components/LoadingIndicator.js';
|
import LoadingIndicator from '../../../../components/LoadingIndicator.js';
|
||||||
import CategoryItem from './CategoryItem.js';
|
import CategoryItem from './CategoryItem.js';
|
||||||
|
|
@ -11,6 +12,10 @@ import ReadButton from './ReadButton.js';
|
||||||
|
|
||||||
// TODO: show empty category message
|
// TODO: show empty category message
|
||||||
class Sidebar extends React.Component {
|
class Sidebar extends React.Component {
|
||||||
|
componentDidMount() {
|
||||||
|
this.props.fetchCategories();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const categoryItems = this.props.categories.items.map(category => {
|
const categoryItems = this.props.categories.items.map(category => {
|
||||||
const rules = this.props.rules.items.filter(rule => {
|
const rules = this.props.rules.items.filter(rule => {
|
||||||
|
|
@ -54,4 +59,8 @@ const mapStateToProps = state => ({
|
||||||
selected: state.selected,
|
selected: state.selected,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(Sidebar);
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
fetchCategories: () => dispatch(fetchCategories()),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(Sidebar);
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,29 @@ import { Provider } from 'react-redux';
|
||||||
import configureStore from './configureStore.js';
|
import configureStore from './configureStore.js';
|
||||||
|
|
||||||
import App from './App.js';
|
import App from './App.js';
|
||||||
|
import Sidebar from './components/sidebar/Sidebar.js';
|
||||||
|
|
||||||
const page = document.getElementById('homepage--page');
|
const homepageBody = document.getElementById('homepage--page');
|
||||||
|
const containers = [...homepageBody.children].filter(element => element.matches('.main'));
|
||||||
if (page) {
|
const sidebars = document.getElementsByClassName('sidebar');
|
||||||
const store = configureStore();
|
const store = configureStore();
|
||||||
|
|
||||||
|
[...sidebars].forEach(sidebar => {
|
||||||
|
const sidebarMount = (
|
||||||
|
<Provider store={store}>
|
||||||
|
<Sidebar />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
ReactDOM.render(sidebarMount, sidebar);
|
||||||
|
});
|
||||||
|
|
||||||
|
[...containers].forEach(container => {
|
||||||
const settings = JSON.parse(document.getElementById('homepageSettings').textContent);
|
const settings = JSON.parse(document.getElementById('homepageSettings').textContent);
|
||||||
const { feedUrl, subredditUrl, timelineUrl, categoriesUrl } = settings;
|
const { feedUrl, subredditUrl, timelineUrl, categoriesUrl } = settings;
|
||||||
|
|
||||||
const app = (
|
const app = (
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
{/* TODO: split App into Main & Sidebar mounts */}
|
|
||||||
<App
|
<App
|
||||||
feedUrl={feedUrl.substring(1, feedUrl.length - 3)}
|
feedUrl={feedUrl.substring(1, feedUrl.length - 3)}
|
||||||
subredditUrl={subredditUrl.substring(1, subredditUrl.length - 3)}
|
subredditUrl={subredditUrl.substring(1, subredditUrl.length - 3)}
|
||||||
|
|
@ -28,5 +39,5 @@ if (page) {
|
||||||
</Provider>
|
</Provider>
|
||||||
);
|
);
|
||||||
|
|
||||||
ReactDOM.render(app, page);
|
ReactDOM.render(app, container);
|
||||||
}
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
{% block page_class %}homepage--page{% endblock %}
|
{% block page_id %}id="homepage--page"{% endblock %}
|
||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
<div className="sidebar"></div>
|
<div class="sidebar"></div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
font-family: Rubik, sans-serif;
|
font-family: Rubik, sans-serif;
|
||||||
font-size: $font-size;
|
font-size: $font-size;
|
||||||
|
|
||||||
|
// TODO add grid area names
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 3fr;
|
grid-template-columns: 1fr 3fr;
|
||||||
grid-gap: 20px;
|
grid-gap: 20px;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
.main {
|
.main {
|
||||||
|
grid-column: 2;
|
||||||
|
grid-row: 2;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
#homepage--page {
|
#homepage--page {
|
||||||
grid-column: 2;
|
& .main {
|
||||||
grid-row: 2;
|
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: initial;
|
align-items: initial;
|
||||||
|
|
||||||
background-color: initial;
|
background-color: initial;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="body {% block page_class %}{% endblock %}">
|
<body {% block page_id %}{% endblock %} class="body">
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<ol>
|
<ol>
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue