From a0205a5c7dd72184cb575195ced3132091072239 Mon Sep 17 00:00:00 2001 From: Johnny A <5891646+johnny243@users.noreply.github.com> Date: Mon, 4 Jul 2022 13:10:41 -0400 Subject: [PATCH] fix(advanced checklist): animations and error handling (#1200) * chore: lint * fix: task completion persisted before animation ends * fix: open/completed task transition timing * fix: save draft * fix: transitions * fix: do not show generic error when first rendering a note Co-authored-by: Johnny Almonte --- .../src/app/hooks.ts | 12 +- .../src/common/components/CheckBoxInput.tsx | 11 +- .../src/features/tasks/CreateTask.tsx | 3 +- .../features/tasks/InvalidContentError.tsx | 6 +- .../src/features/tasks/TaskGroup.tsx | 25 ++- .../src/features/tasks/TaskItem.scss | 22 ++- .../src/features/tasks/TaskItem.tsx | 75 ++++---- .../src/features/tasks/TaskSectionList.tsx | 8 +- .../src/features/tasks/TasksSection.tsx | 167 +++++++++--------- .../src/stylesheets/main.scss | 4 + 10 files changed, 187 insertions(+), 146 deletions(-) diff --git a/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/app/hooks.ts b/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/app/hooks.ts index bad2dfc77..453dae958 100644 --- a/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/app/hooks.ts +++ b/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/app/hooks.ts @@ -1,5 +1,5 @@ -import React, { useEffect, useRef, useState } from 'react' import useResizeObserver from '@react-hook/resize-observer' +import React, { useEffect, useRef, useState } from 'react' import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux' import type { AppDispatch, RootState } from './store' @@ -42,3 +42,13 @@ export const useDebouncedCallback = (callback: () => void, waitMs: number = 500) callback() }, waitMs) } + +export const usePrevious = (value: any) => { + const ref = useRef() + + useEffect(() => { + ref.current = value + }, [value]) + + return ref.current +} diff --git a/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/common/components/CheckBoxInput.tsx b/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/common/components/CheckBoxInput.tsx index 9a9727646..62e0f2a65 100644 --- a/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/common/components/CheckBoxInput.tsx +++ b/packages/components/src/Packages/Editors/org.standardnotes.advanced-checklist/src/common/components/CheckBoxInput.tsx @@ -1,18 +1,15 @@ -import React, { ChangeEvent, forwardRef } from 'react' +import { ChangeEvent, forwardRef, MouseEvent } from 'react' type CheckBoxInputProps = { checked?: boolean disabled?: boolean testId?: string onChange?: (event: ChangeEvent) => void + onClick?: (event: MouseEvent) => void } export const CheckBoxInput = forwardRef( - ({ checked, disabled, testId, onChange }, ref) => { - function onCheckBoxButtonClick({ currentTarget }: React.MouseEvent) { - !checked ? currentTarget.classList.add('explode') : currentTarget.classList.remove('explode') - } - + ({ checked, disabled, testId, onChange, onClick }, ref) => { return (