Add saved icon

This commit is contained in:
Sonny Bakker 2021-02-20 23:23:18 +01:00
parent 3818c7190e
commit 20ef9b06a5
7 changed files with 35 additions and 11 deletions

View file

@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import Cookies from 'js-cookie';
import { unSelectPost, markPostRead } from '../actions/posts.js';
import { unSelectPost, markPostRead, toggleSaved } from '../actions/posts.js';
import {
CATEGORY_TYPE,
RULE_TYPE,
@ -51,9 +51,11 @@ class PostModal extends React.Component {
const token = Cookies.get('csrftoken');
const publicationDate = formatDatetime(post.publicationDate);
const titleClassName = post.read ? 'post__title post__title--read' : 'post__title';
const readButtonDisabled = post.read || this.props.isMarkingPost;
const readButtonDisabled = post.read || this.props.isUpdating;
const savedIconClass = post.saved ? 'saved-icon saved-icon--saved' : 'saved-icon';
let ruleUrl = '';
switch (this.props.rule.type) {
case SUBREDDIT:
ruleUrl = `${this.props.subredditUrl}/${this.props.rule.id}/`;
@ -114,6 +116,10 @@ class PostModal extends React.Component {
>
<i className="fas fa-external-link-alt" />
</a>
<span
className={savedIconClass}
onClick={() => this.props.toggleSaved(post, token)}
/>
</div>
</div>
@ -128,8 +134,11 @@ class PostModal extends React.Component {
const mapDispatchToProps = dispatch => ({
unSelectPost: () => dispatch(unSelectPost()),
markPostRead: (post, token) => dispatch(markPostRead(post, token)),
toggleSaved: (post, token) => dispatch(toggleSaved(post, token)),
});
const mapStateToProps = state => ({ isMarkingPost: state.posts.isMarking });
const mapStateToProps = state => ({
isUpdating: state.posts.isUpdating,
});
export default connect(mapStateToProps, mapDispatchToProps)(PostModal);

View file

@ -19,7 +19,6 @@ import { MARK_SECTION_READ } from '../actions/selected.js';
const defaultState = { items: {}, isFetching: false, isUpdating: false };
// TODO isMarking -> isUpdating
export const posts = (state = { ...defaultState }, action) => {
switch (action.type) {
case REQUEST_POSTS:

View file

@ -39,12 +39,6 @@
}
}
&__link {
& i {
padding: 0 0 0 7px;
}
}
&__date {
font-size: small;
}
@ -103,6 +97,6 @@
align-items: center;
margin: 15px 0;
gap: 5px;
gap: 10px;
}
}

View file

@ -12,3 +12,4 @@
@import './small/index';
@import './select/index';
@import './checkbox/index';
@import './saved-icon/index';

View file

@ -0,0 +1,15 @@
.saved-icon {
@include font-awesome;
&:before {
content: "\f0c7";
}
&:hover {
cursor: pointer;
}
&--saved {
color: var(--confirm-color);
}
}

View file

@ -0,0 +1 @@
@import './saved-icon';

View file

@ -9,3 +9,8 @@
@mixin button-padding {
padding: 5px 20px;
}
@mixin font-awesome {
font-family: "Font Awesome 5 Free";
font-weight: 900;
}