Skip to content

Commit

Permalink
Merge branch 'release/v3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kitce committed Apr 2, 2022
2 parents 19e739c + 9aa9e4b commit b23f009
Show file tree
Hide file tree
Showing 25 changed files with 243 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .cz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ commitizen:
changelog_start_rev: v2.0.0
name: cz_conventional_commits
tag_format: v$version
version: 3.2.0
version: 3.3.0
version_files:
- package.json
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## v3.3.0 (2022-04-03)

### Fix

- **cache**: remove `Cache#targetReply`
- **mutation**: recover user card modal mutation
- **dependencies**: incorrect `@types/redux-state-sync` version
- **mutation**: conflicts with "LIHKG Show User Info"

### Feat

- **components**: update add label button icon
- **components**: update `BaseIconButton` to support custom icon element
- **mutation**: move add label button to beside of the reply button

### Refactor

- **typings**: update typings

## v3.2.0 (2022-04-02)

### Feat
Expand Down
2 changes: 1 addition & 1 deletion dist/egg.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions dist/libel.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ object-assign
http://jedwatson.github.io/classnames
*/

/*!
* Font Awesome Free 6.1.1 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
* Copyright 2022 Fonticons, Inc.
*/

/*!
* JavaScript Cookie v2.2.1
* https://github.com/js-cookie/js-cookie
Expand Down
2 changes: 1 addition & 1 deletion dist/libel.meta.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Libel
// @version 3.2.0
// @version 3.3.0
// @author kitce <[email protected]>
// @description Label users on LIHKG
// @homepage https://kitce.github.io/libel
Expand Down
4 changes: 2 additions & 2 deletions dist/libel.user.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "libel",
"namespace": "libel",
"displayName": "Libel",
"version": "3.2.0",
"version": "3.3.0",
"description": "Label users on LIHKG",
"author": "kitce <[email protected]>",
"repository": {
Expand Down Expand Up @@ -31,6 +31,11 @@
},
"dependencies": {
"@floating-ui/react-dom": "^0.6.0",
"@fortawesome/fontawesome-free": "^6.1.1",
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-regular-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"@reduxjs/toolkit": "^1.5.1",
"classnames": "^2.3.1",
"date-fns": "^2.27.0",
Expand Down Expand Up @@ -70,7 +75,7 @@
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
"@types/redux-persist": "^4.3.1",
"@types/redux-state-sync": "^3.2.0",
"@types/redux-state-sync": "^3.1.1",
"@types/sass": "^1.16.0",
"@types/semver": "^7.3.6",
"@types/tailwindcss": "^2.0.2",
Expand Down
71 changes: 68 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions src/components/AddLabelButton/AddLabelButton.module.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
@import '../../stylesheets/base';

.container {
@apply cursor-default;

&:empty {
@apply hidden;
}
}

.add-label-button {
@apply absolute top-0 left-0;
@apply h-full w-full;
font-size: 1em;

&:focus,
&:hover {
color: $color-black;

@include dark-mode() {
color: $color-white;
}
}
}
34 changes: 23 additions & 11 deletions src/components/AddLabelButton/AddLabelButton.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
import { faTag } from '@fortawesome/free-solid-svg-icons/faTag';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useCallback, useState } from 'react';
import { uploadImage } from '../../apis/nacx';
import * as ATTRIBUTES from '../../constants/attributes';
import { EventAction, EventCategory, EventLabel } from '../../constants/ga';
import * as TEXTS from '../../constants/texts';
import * as gtag from '../../helpers/gtag';
import { mapPostToSource } from '../../helpers/label';
import { actions as personalActions, IAddLabelPayload } from '../../store/slices/personal';
import { useTypedDispatch } from '../../store/store';
import type { IPost } from '../../types/lihkg';
import Button from '../Button/Button';
import IconButton from '../IconButton/IconButton';
import LabelFormModal, { TLabelFormProps } from '../LabelFormModal/LabelFormModal';
import styles from './AddLabelButton.module.scss';

interface IProps {
user: string;
targetReply: IPost;
post: IPost;
}

const AddLabelButton: React.FunctionComponent<IProps> = (props) => {
const { user, targetReply, children } = props;
type TProps = IProps;

const AddLabelButton: React.FunctionComponent<TProps> = (props) => {
const { user, post } = props;

const dispatch = useTypedDispatch();
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);
const [targetReply, setTargetReply] = useState<HTMLElement | null>(null);

const handleClick: React.MouseEventHandler<HTMLButtonElement> = useCallback((event) => {
event.preventDefault();
if (!loading) {
const targetReplySelector = `[${ATTRIBUTES.dataPostId}="${post.post_id}"]`;
const targetReply = document.querySelector<HTMLDivElement>(targetReplySelector);
setTargetReply(targetReply);
setOpen(true);
// analytics
gtag.event(EventAction.Open, { event_category: EventCategory.Modal, event_label: EventLabel.AddLabel });
Expand All @@ -40,7 +49,7 @@ const AddLabelButton: React.FunctionComponent<IProps> = (props) => {

const handleLabelFormSubmit: TLabelFormProps['onSubmit'] = useCallback(async (data) => {
const { text, reason, color, image, meta } = data;
const source = mapPostToSource(targetReply);
const source = mapPostToSource(post);
const payload: IAddLabelPayload = { user, text, reason, color, image, source };
setLoading(true);
const { screenshot } = meta;
Expand Down Expand Up @@ -72,23 +81,26 @@ const AddLabelButton: React.FunctionComponent<IProps> = (props) => {
handleLabelFormModalClose();
// analytics
gtag.event(EventAction.Add, { event_category: EventCategory.Label, event_label: text });
}, [user, targetReply, handleLabelFormModalClose]);
}, [user, post, handleLabelFormModalClose]);

return (
<React.Fragment>
<Button
<IconButton
className={styles.addLabelButton}
loading={loading}
icon={<FontAwesomeIcon icon={faTag} />}
aria-label={TEXTS.BUTTON_TEXT_ADD_LABEL}
data-tip={TEXTS.BUTTON_TEXT_ADD_LABEL}
title={TEXTS.BUTTON_TEXT_ADD_LABEL}
disabled={loading}
onClick={handleClick}
>
{children}
</Button>
/>
<LabelFormModal
open={open}
user={user}
escape={false}
fragile={false}
loading={loading}
targetReply={targetReply}
onClose={handleLabelFormModalClose}
onSubmit={handleLabelFormSubmit}
/>
Expand Down
5 changes: 4 additions & 1 deletion src/components/BaseIconButton/BaseIconButton.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.base-icon-button {
@apply inline-flex items-center justify-center;
&,
.icon {
@apply inline-flex items-center justify-center;
}

.icon {
&:not(:only-child) {
Expand Down
10 changes: 8 additions & 2 deletions src/components/BaseIconButton/BaseIconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { IconName } from '../Icon/types';
import styles from './BaseIconButton.module.scss';

interface IProps {
icon: IconName;
icon: IconName | JSX.Element;
}

export type TProps = IProps & TButtonProps;
Expand All @@ -19,7 +19,13 @@ const BaseIconButton: React.FunctionComponent<TProps> = (props) => {
className={classnames(className, styles.baseIconButton)}
>
<React.Fragment>
<Icon className={styles.icon} icon={icon} />
{
typeof icon === 'string' ? (
<Icon className={styles.icon} icon={icon} />
) : (
<span className={styles.icon}>{icon}</span>
)
}
{
children && (
<span>{children}</span>
Expand Down
Loading

0 comments on commit b23f009

Please sign in to comment.