Skip to content

Commit

Permalink
Merge branch 'checklist' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Jul 26, 2023
2 parents 26d4b0a + beb425b commit 85dfeba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Experimental
### Added
- Comments can now be used as checklists if the comment text starts with "[ ]"
or "[x]" (one can use other symbols in parentheses as well: [v], [*], [], or
or "[x]" (one can use other symbols in parentheses as well: [v], [*], [🗸], or
Russian "Ha").

If the current user matches the author of the post and comment, an interactive
checkbox is displayed at the beginning of the text. When the user clicks the
checkbox, the comment text changes to reflect the checkbox state.
If the current user matches the author of the comment, an interactive checkbox
is displayed at the beginning of the text. When the user clicks the checkbox,
the comment text changes to reflect the checkbox state.

For other users, a fixed-width text representation of the checkbox is shown:
"[ ]" or "[]".
"[ ]" or "[🗸]".

## [1.121.1] - 2023-07-15
### Fixed
Expand Down
9 changes: 4 additions & 5 deletions src/components/initial-checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { saveEditingComment } from '../redux/action-creators';
import { initialAsyncState } from '../redux/async-helpers';
import { isChecked, setCheckState } from '../utils/initial-checkbox';
import { checkMark, isChecked, setCheckState } from '../utils/initial-checkbox';
import style from './initial-checkbox.module.scss';
import { Throbber } from './throbber';
import { useComment, usePost } from './post/post-comment-ctx';
import { useComment } from './post/post-comment-ctx';

export function InitialCheckbox({ checked }) {
const post = usePost();
const comment = useComment();
const myId = useSelector((state) => state.user.id);

const isActive = post.createdBy === comment?.createdBy && post.createdBy === myId;
const isActive = myId && comment?.createdBy === myId;

return (
<>
Expand All @@ -23,7 +22,7 @@ export function InitialCheckbox({ checked }) {
<span className={style.textBox}>
[
<span aria-hidden={!checked} className={cn(!checked && style.hidden)}>
{checkMark}
</span>
]
</span>
Expand Down
7 changes: 5 additions & 2 deletions src/utils/initial-checkbox.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Token } from 'social-text-tokenizer';

/**
* U+2713 Check Mark (🗸)
* U+2714 Heavy Check Mark (✔)
* U+0445 Cyrillic Small Letter Ha (х)
*/
const checkBoxRe = /^\[(?:\s*|[xv*\u2714\u0445])]/i;
const checkBoxRe = /^\[(?:\s*|[xv*\u2713\u2714\u0445])]/i;

export const checkMark = '\u2713';

/**
* @param {string} text
Expand Down Expand Up @@ -46,5 +49,5 @@ export function isChecked(text) {
* @returns {string}
*/
export function setCheckState(text, newState) {
return `[${newState ? '\u2714' : ' '}] ${text.replace(checkBoxRe, '').trim()}`;
return `[${newState ? checkMark : ' '}] ${text.replace(checkBoxRe, '').trim()}`;
}

0 comments on commit 85dfeba

Please sign in to comment.