Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
859c02195c Show buttons under modal 2021-07-21 21:08:39 +02:00
38b2d91f18 Only show buttons when needed 2021-07-21 21:06:46 +02:00
b9c749d4e4 Initial commit 2021-07-08 22:24:04 +02:00
6 changed files with 80 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import { isEqual } from 'lodash';
import { fetchCategories } from './actions/categories';
import ScrollTop from './components/ScrollTop.js';
import Sidebar from './components/sidebar/Sidebar.js';
import PostList from './components/postlist/PostList.js';
import PostModal from './components/PostModal.js';
@ -41,6 +42,8 @@ class App extends React.Component {
/>
)}
<ScrollTop />
{this.props.error && (
<Messages messages={[{ type: 'error', text: this.props.error.message }]} />
)}

View file

@ -0,0 +1,40 @@
import React from 'react';
export default class ScrollTop extends React.Component {
scrollListener = ::this.scrollListener;
state = { showTop: false, showBottom: false };
componentDidMount() {
window.addEventListener('scroll', this.scrollListener);
}
scrollListener() {
const showBottom = window.innerHeight + window.scrollY < document.body.offsetHeight;
this.setState({
showTop: window.pageYOffset > 0 ? true : false,
showBottom: showBottom,
});
}
render() {
return (
<div className="scroll-to-top">
{this.state.showTop && (
<i
className="scroll-to-top__icon scroll-to-top__icon--top"
onClick={() => window.scrollTo(0, 0)}
/>
)}
{this.state.showBottom && (
<i
className="scroll-to-top__icon scroll-to-top__icon--bottom"
onClick={() => window.scrollTo(0, document.body.scrollHeight)}
/>
)}
</div>
);
}
}

View file

@ -26,3 +26,4 @@
@import './post-message/index';
@import './posts/index';
@import './posts-info/index';
@import './scroll-to-top/index';

View file

@ -5,4 +5,6 @@
padding: 0;
cursor: pointer;
z-index: 1000;
}

View file

@ -0,0 +1,33 @@
.scroll-to-top {
display: flex;
gap: 10px;
position: fixed;
right: 15%;
bottom: 0;
margin: 0 0 20px 0;
&:hover {
cursor: pointer;
}
&__icon {
font-style: initial;
padding: 10px;
background-color: var(--lightest-accent-color);
&--top:before {
@include font-awesome;
content: "\f062";
}
&--bottom:before {
@include font-awesome;
content: "\f063";
}
}
}

View file

@ -0,0 +1 @@
@import './scroll-to-top';