fix: Show tasks completion on document list items (#2342)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Saumya Pandey
2021-07-27 11:31:27 +05:30
committed by GitHub
parent 8ee018a759
commit a81fbd8608
11 changed files with 247 additions and 4 deletions

View File

@@ -34,6 +34,9 @@
"only you": "only you",
"person": "person",
"people": "people",
"{{ total }} tasks": "{{ total }} tasks",
"{{ completed }} tasks done": "{{ completed }} tasks done",
"{{ completed }} of {{ total }} tasks": "{{ completed }} of {{ total }} tasks",
"Currently editing": "Currently editing",
"Currently viewing": "Currently viewing",
"Viewed {{ timeAgo }} ago": "Viewed {{ timeAgo }} ago",

View File

@@ -179,6 +179,7 @@ export const light = {
noticeInfoBackground: colors.warmGrey,
noticeInfoText: colors.almostBlack,
progressBarBackground: colors.slateLight,
scrollbarBackground: colors.smoke,
scrollbarThumb: darken(0.15, colors.smokeDark),
@@ -241,6 +242,7 @@ export const dark = {
noticeInfoBackground: colors.white10,
noticeInfoText: colors.almostWhite,
progressBarBackground: colors.slate,
scrollbarBackground: colors.black,
scrollbarThumb: colors.lightBlack,

21
shared/utils/getTasks.js Normal file
View File

@@ -0,0 +1,21 @@
// @flow
const CHECKBOX_REGEX = /\[(X|\s|_|-)\]\s(.*)?/gi;
export default function getTasks(text: string) {
const matches = [...text.matchAll(CHECKBOX_REGEX)];
let total = matches.length;
if (!total) {
return {
completed: 0,
total: 0,
};
} else {
const notCompleted = matches.reduce(
(accumulator, match) =>
match[1] === " " ? accumulator + 1 : accumulator,
0
);
return { completed: total - notCompleted, total };
}
}