Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-72] Implement checklists #382

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

[WEB-72] Implement checklists #382

wants to merge 4 commits into from

Conversation

winnteas
Copy link
Contributor

Why the changes are required?

Users may want to apply a checklist within the editor similar to the numbered and bulleted lists

Changes

  • Added checklist button next to quote button
  • Created checklist element tag in EditorBlock.tsx
    image

@winnteas winnteas changed the title [WEB-25] Implement checklists [WEB-72] Implement checklists Aug 26, 2023
Copy link
Contributor

@lauraw0 lauraw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice nice looks pretty dang good!! just a couple changes needed (as detailed in the comments) plus the following notes:

  1. Pls change it so that the checkboxes are reflected in the published blogs. This may possibly require some refactoring as you will need to not only keep track of the type (e.g. checklist, quote, code....) but also whether the items are checked/crossed out. This means you may need to add an optional type to the type interfaces.
    Editor
    image
    Published blog
    image
  2. Sort of tied to the above point. After you have corrected the interface you will need to ensure that checked items remains checked after refresh. Currently your checked items become unchecked due to the checked value being held in a usestate.

@@ -0,0 +1,23 @@
import React, { MouseEventHandler } from 'react';
import { StyledButton, buttonProps, scaleRate } from './small_buttons-Styled';
import { ReactComponent as Code } from 'src/cse-ui-kit/assets/checklist-button.svg';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename the component as Checklist instead

checked={checked}
onChange={event => {
// Figure out why ReactEditor.findPath does not work
// const path = ReactEditor.findPath(editor as ReactEditor, leaf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your current implementation works so you can just remove these comments but if you wanted to know why the ReactEditor.findPath() doesn't work, i think these could possibly be the reasons:

  1. the editor needs to be passed in from the EditorBlock component
  2. this findPath function is specifically finding a node (https://docs.slatejs.org/libraries/slate-react/react-editor#reacteditor.findpath-editor-reacteditor-node-node-path) but here you are rendering the checklists as leaves. This means that the function will never return the current leaf. You can resolve this by changing the checklists into nodes. NOTE: you can think of a node as sort of a big wrapper/container whilst leaves are sort of the children with decorations. However, I do have some doubts about this cause in that case it should in theory find the leaf level text node surrounding this lead? Not completely sure without delving into it too deeply.
  3. This is probably the most likely reason: the structure of our editor/leaves/nodes does not follow typical slate operations and therefore any functions that involve traversing through the editor path is doomed to fail

Comment on lines +57 to +60
<div
style={{ userSelect: "none" }}
contentEditable={false}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This div doesn't appear to do much so you can remove it

@@ -46,6 +48,51 @@ const Text = styled.span<{
background-color: ${(props) => props.code ? "#eee" : "#fff"};
`;


const CheckListItemElement = ({children, attributes, leaf}: any) => {
const readOnly = useReadOnly()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the use of this hook as it is unlikely for us to set the editor to readonly. We can always add it back in when needed though :D

Comment on lines +123 to +124
checklist: leaf.checklist ?? false,
checked: leaf.checklist ?? false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be used elsewhere so you can remove it. Let me know if i missed its use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants