mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added like count to nodes
This commit is contained in:
parent
7f372bb025
commit
5c1610218d
6 changed files with 39 additions and 6 deletions
|
@ -26,7 +26,7 @@ interface IProps {
|
||||||
|
|
||||||
const NodePanelInner: FC<IProps> = memo(
|
const NodePanelInner: FC<IProps> = memo(
|
||||||
({
|
({
|
||||||
node: { title, user, is_liked, is_heroic, deleted_at, created_at },
|
node: { title, user, is_liked, is_heroic, deleted_at, created_at, like_count },
|
||||||
stack,
|
stack,
|
||||||
|
|
||||||
can_star,
|
can_star,
|
||||||
|
@ -53,7 +53,7 @@ const NodePanelInner: FC<IProps> = memo(
|
||||||
{is_loading ? (
|
{is_loading ? (
|
||||||
<Placeholder width="100px" />
|
<Placeholder width="100px" />
|
||||||
) : (
|
) : (
|
||||||
`~${user.username}, ${getPrettyDate(created_at)}`
|
`~${user.username.toLocaleLowerCase()}, ${getPrettyDate(created_at)}`
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -95,6 +95,8 @@ const NodePanelInner: FC<IProps> = memo(
|
||||||
) : (
|
) : (
|
||||||
<Icon icon="heart" size={24} onClick={onLike} />
|
<Icon icon="heart" size={24} onClick={onLike} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{like_count > 0 && <div className={styles.like_count}>{like_count}</div>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -214,17 +214,42 @@
|
||||||
.like {
|
.like {
|
||||||
transition: fill, stroke 0.25s;
|
transition: fill, stroke 0.25s;
|
||||||
will-change: transform;
|
will-change: transform;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
&:global(.is_liked) {
|
&:global(.is_liked) {
|
||||||
svg {
|
svg {
|
||||||
fill: $red;
|
fill: $red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.like_count {
|
||||||
|
color: $red;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
fill: $red;
|
fill: $red;
|
||||||
animation: pulse 0.75s infinite;
|
animation: pulse 0.75s infinite;
|
||||||
|
|
||||||
|
.like_count {
|
||||||
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.like_count {
|
||||||
|
position: absolute;
|
||||||
|
font: $font_12_bold;
|
||||||
|
left: 16px;
|
||||||
|
bottom: 0;
|
||||||
|
opacity: 1;
|
||||||
|
transition: opacity 0.25s, color 0.25s;
|
||||||
|
background: $node_bg;
|
||||||
|
padding: 0 3px;
|
||||||
|
border-radius: 10px;
|
||||||
|
z-index: 3;
|
||||||
|
color: transparentize($color: white, $amount: 0.5);
|
||||||
|
pointer-events: none;
|
||||||
|
touch-action: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.star {
|
.star {
|
||||||
|
|
|
@ -123,7 +123,7 @@ const NodeLayoutUnconnected: FC<IProps> = memo(
|
||||||
|
|
||||||
<NodePanel
|
<NodePanel
|
||||||
node={pick(
|
node={pick(
|
||||||
['title', 'user', 'is_liked', 'is_heroic', 'deleted_at', 'created_at'],
|
['title', 'user', 'is_liked', 'is_heroic', 'deleted_at', 'created_at', 'like_count'],
|
||||||
node
|
node
|
||||||
)}
|
)}
|
||||||
layout={layout}
|
layout={layout}
|
||||||
|
|
|
@ -280,16 +280,20 @@ function* onEditSaga({ id }: ReturnType<typeof nodeEdit>) {
|
||||||
function* onLikeSaga({ id }: ReturnType<typeof nodeLike>) {
|
function* onLikeSaga({ id }: ReturnType<typeof nodeLike>) {
|
||||||
const {
|
const {
|
||||||
current,
|
current,
|
||||||
current: { is_liked },
|
current: { is_liked, like_count },
|
||||||
} = yield select(selectNode);
|
} = yield select(selectNode);
|
||||||
|
|
||||||
yield call(updateNodeEverywhere, { ...current, is_liked: !is_liked });
|
yield call(updateNodeEverywhere, {
|
||||||
|
...current,
|
||||||
|
is_liked: !is_liked,
|
||||||
|
like_count: is_liked ? Math.max(like_count - 1, 0) : like_count + 1,
|
||||||
|
});
|
||||||
|
|
||||||
const { data, error } = yield call(reqWrapper, postNodeLike, { id });
|
const { data, error } = yield call(reqWrapper, postNodeLike, { id });
|
||||||
|
|
||||||
if (!error || data.is_liked === !is_liked) return; // ok and matches
|
if (!error || data.is_liked === !is_liked) return; // ok and matches
|
||||||
|
|
||||||
yield call(updateNodeEverywhere, { ...current, is_liked });
|
yield call(updateNodeEverywhere, { ...current, is_liked, like_count });
|
||||||
}
|
}
|
||||||
|
|
||||||
function* onStarSaga({ id }: ReturnType<typeof nodeLike>) {
|
function* onStarSaga({ id }: ReturnType<typeof nodeLike>) {
|
||||||
|
|
|
@ -124,6 +124,7 @@ export interface INode {
|
||||||
description?: string;
|
description?: string;
|
||||||
is_liked?: boolean;
|
is_liked?: boolean;
|
||||||
is_heroic?: boolean;
|
is_heroic?: boolean;
|
||||||
|
like_count?: number;
|
||||||
|
|
||||||
flow: {
|
flow: {
|
||||||
display: 'single' | 'vertical' | 'horizontal' | 'quadro';
|
display: 'single' | 'vertical' | 'horizontal' | 'quadro';
|
||||||
|
|
|
@ -55,6 +55,7 @@ $font_14_semibold: $semibold 14px $font;
|
||||||
$font_14_medium: $medium 14px $font;
|
$font_14_medium: $medium 14px $font;
|
||||||
$font_12_medium: $medium 12px $font;
|
$font_12_medium: $medium 12px $font;
|
||||||
$font_12_semibold: $semibold 12px $font;
|
$font_12_semibold: $semibold 12px $font;
|
||||||
|
$font_12_bold: $bold 12px $font;
|
||||||
$font_12_regular: $regular 12px $font;
|
$font_12_regular: $regular 12px $font;
|
||||||
$font_10_regular: $regular 10px $font;
|
$font_10_regular: $regular 10px $font;
|
||||||
$font_10_semibold: $semibold 10px $font;
|
$font_10_semibold: $semibold 10px $font;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue