Skip to content

Commit bbf6f13

Browse files
committed
add enable_likes behaviour and polish code
1 parent a62f7d0 commit bbf6f13

5 files changed

Lines changed: 75 additions & 38 deletions

File tree

backend/src/kitconcept/intranet/behaviors/configure.zcml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
provides=".blocks_settings.ITTWBlocksSettings"
1919
/>
2020

21+
<plone:behavior
22+
name="kitconcept.enable_likes"
23+
title="Enable Like functionality"
24+
description="Enables the like functionality for content objects"
25+
provides=".enable_likes.IEnableLikes"
26+
/>
27+
2128
<plone:behavior
2229
name="kitconcept.intranet.votes"
2330
title="Saves userID who liked an item"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from kitconcept.intranet import _
2+
from plone.autoform.interfaces import IFormFieldProvider
3+
from plone.supermodel import model
4+
from zope import schema
5+
from zope.interface import provider
6+
7+
8+
@provider(IFormFieldProvider)
9+
class IEnableLikes(model.Schema):
10+
11+
enable_likes = schema.Bool(
12+
title=_("Enable Likes"),
13+
description=_("Enable Likes for this Content Object"),
14+
required=False,
15+
default=True,
16+
)

backend/src/kitconcept/intranet/profiles/default/types/Document.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<element value="kitconcept.intranet.organisational_unit" />
1414
<element value="kitconcept.intranet.lcm" />
1515
<element value="kitconcept.intranet.votes" />
16+
<element value="kitconcept.enable_likes" />
1617
</property>
1718

1819
</object>

frontend/packages/volto-intranet/src/components/Rating/Rating.jsx

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,19 @@ const DotFormattedDate = ({ date, className, locale }) => {
6464
</FormattedDate>
6565
);
6666
};
67+
68+
// I will remove it once I update the useLiveData function of VLT.
69+
function useLiveData(field) {
70+
const formData = useSelector((state) => state.form.global?.[field]);
71+
return formData;
72+
}
6773
const Rating = (props) => {
6874
const location = useLocation();
6975
const content = useSelector((state) => state.content.data);
7076
const pathname = location.pathname;
71-
const allow_discussion = content?.allow_discussion;
77+
const allow_discussion =
78+
useLiveData('allow_discussion') || content?.allow_discussion;
79+
const enable_likes = useLiveData('enable_likes') || content?.enable_likes;
7280
const votes = content?.votes;
7381
const loggedIn = useSelector((state) => state.userSession.token, shallowEqual)
7482
? true
@@ -136,37 +144,39 @@ const Rating = (props) => {
136144
<Container className="content-engagement">
137145
<div className="engagement-container">
138146
<div className="engagement-section">
139-
<div className={cx('likes-section', { anon: !loggedIn })}>
140-
{loggedIn ? (
141-
<Button aria-label="liked" onClick={() => onLike()}>
142-
<div className="icon-wrapper">
143-
{liked ? (
144-
<Icon
145-
name={thumbsFilledSVG}
146-
size="33px"
147-
className="liked"
148-
/>
149-
) : (
147+
{enable_likes && (
148+
<div className={cx('likes-section', { anon: !loggedIn })}>
149+
{loggedIn ? (
150+
<Button aria-label="liked" onClick={() => onLike()}>
151+
<div className="icon-wrapper">
152+
{liked ? (
153+
<Icon
154+
name={thumbsFilledSVG}
155+
size="33px"
156+
className="liked"
157+
/>
158+
) : (
159+
<Icon name={thumbsSVG} size="33px" />
160+
)}
161+
</div>
162+
</Button>
163+
) : (
164+
<Link
165+
aria-label="unliked"
166+
to={`${pathname}/login`}
167+
title={intl.formatMessage(messages.loginToLike)}
168+
>
169+
<div className="icon-wrapper">
150170
<Icon name={thumbsSVG} size="33px" />
151-
)}
152-
</div>
153-
</Button>
154-
) : (
155-
<Link
156-
aria-label="unliked"
157-
to={`${pathname}/login`}
158-
title={intl.formatMessage(messages.loginToLike)}
159-
>
160-
<div className="icon-wrapper">
161-
<Icon name={thumbsSVG} size="33px" />
162-
</div>
163-
</Link>
164-
)}
165-
<div className="likes-count">
166-
<span>({amount})</span>
171+
</div>
172+
</Link>
173+
)}
174+
<div className="likes-count">
175+
<span>({amount})</span>
176+
</div>
167177
</div>
168-
</div>
169-
{(allow_discussion || comment_count >= 0) && (
178+
)}
179+
{(allow_discussion || comment_count > 0) && (
170180
<div className="comments-section">
171181
<Button aria-label="comments">
172182
<div className="icon-wrapper">

frontend/packages/volto-intranet/src/theme/components/rating.scss

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
.content-engagement {
2-
position: relative;
3-
display: block;
4-
width: calc(100cqw - 40px);
5-
max-width: inherit;
62
padding-top: 30px;
73
padding-bottom: 80px;
84
border-color: var(--theme-foreground-color);
95
border-top: 1px solid;
106
margin-top: 80px;
11-
content: '';
127
@include default-container-width();
138
@include adjustMarginsToContainer($default-container-width);
149
}
@@ -33,6 +28,10 @@
3328
align-items: center;
3429
margin-right: 30px;
3530

31+
button {
32+
cursor: pointer;
33+
}
34+
3635
.likes-count,
3736
.comments-count {
3837
span {
@@ -42,11 +41,18 @@
4241
}
4342
}
4443
}
44+
45+
.comments-section {
46+
button {
47+
cursor: default;
48+
}
49+
}
4550
}
4651
.content-metadata {
4752
display: flex;
4853
flex: 1;
4954
justify-content: flex-end;
55+
gap: 50px;
5056
.created,
5157
.modified {
5258
font-size: 14px;
@@ -58,7 +64,4 @@
5864
display: flex;
5965
}
6066
}
61-
.created {
62-
margin-right: 50px;
63-
}
6467
}

0 commit comments

Comments
 (0)