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

Markdown rendering #1544

Merged
merged 15 commits into from Feb 15, 2023
Merged

Markdown rendering #1544

merged 15 commits into from Feb 15, 2023

Conversation

notmd
Copy link
Collaborator

@notmd notmd commented Feb 13, 2023

close #1350 #837

Update: Ready to review now

Lightmode

image

Darkmode

image

@notmd notmd mentioned this pull request Feb 13, 2023
@mashdragon
Copy link
Contributor

@notmd thank you for solving this. The only test case that fails is ordered lists (1., 2., etc.) are not rendering the numbers. The line spacing is also really big still in message blocks.

Also, one thing that was discussed was to also render the Markdown when the user presses Review. Here is a diff that does this for your convenience:

Git diff
diff --git a/website/src/components/Tasks/CreateTask.tsx b/website/src/components/Tasks/CreateTask.tsx
index 448ad287..b28f5ad6 100644
--- a/website/src/components/Tasks/CreateTask.tsx
+++ b/website/src/components/Tasks/CreateTask.tsx
@@ -10,6 +10,7 @@ import { getTypeSafei18nKey } from "src/lib/i18n";
 import { TaskType } from "src/types/Task";
 import { CreateTaskReply } from "src/types/TaskResponses";
 import { CreateTaskType } from "src/types/Tasks";
+import RenderedMarkdown from "../Messages/RenderedMarkdown";
 
 export const CreateTask = ({
   task,
@@ -37,6 +38,11 @@ export const CreateTask = ({
     }
   };
 
+  let renderedMessage = <></>;
+  if (!isEditable) {
+    renderedMessage = <RenderedMarkdown markdown={inputText}></RenderedMarkdown>;
+  }
+
   return (
     <div data-cy="task" data-task-type="create-task">
       <TwoColumnsWithCards>
@@ -55,16 +61,19 @@ export const CreateTask = ({
                 {t(getTypeSafei18nKey(`tasks:${taskType.id}.instruction`))}
               </Text>
             )}
-            <TrackedTextarea
-              text={inputText}
-              onTextChange={textChangeHandler}
-              thresholds={{ low: 20, medium: 40, goal: 50 }}
-              textareaProps={{
-                placeholder: t(getTypeSafei18nKey(`tasks:${taskType.id}.response_placeholder`)),
-                isDisabled,
-                isReadOnly: !isEditable,
-              }}
-            />
+            <div hidden={!isEditable}>
+              <TrackedTextarea
+                text={inputText}
+                onTextChange={textChangeHandler}
+                thresholds={{ low: 20, medium: 40, goal: 50 }}
+                textareaProps={{
+                  placeholder: t(getTypeSafei18nKey(`tasks:${taskType.id}.response_placeholder`)),
+                  isDisabled,
+                  isReadOnly: !isEditable,
+                }}
+              />
+            </div>
+            {renderedMessage}
           </Stack>
         </>
       </TwoColumnsWithCards>

Line spacing is interestingly not a problem for this Review rendering. So maybe there is an issue with the message block styling.

@notmd
Copy link
Collaborator Author

notmd commented Feb 13, 2023

@mashdragon Thank you for the feedback, I will check it again tomorrow. About render mark markdown when editing, I plan to make it in another PR and add auto grow feature to the textarea too.

@mashdragon
Copy link
Contributor

One other place that needs rendering is in the modals of the ranking task. I did not remember that before.

@olliestanley olliestanley linked an issue Feb 13, 2023 that may be closed by this pull request
avartarPosition="top"
highlight={tree.id === messageId}
></MessageTableEntry>
{tree.children.length > 0 && (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I fix issue where the tree still display connection when it only have root (no children).

@notmd
Copy link
Collaborator Author

notmd commented Feb 15, 2023

@mashdragon I just tweak style (heading space only) similar to boostrap which is the CSS framework Github use. Can you take a look at the style?

@AbdBarho
Copy link
Collaborator

AbdBarho commented Feb 15, 2023

I am not really sure what is the reason for the disabling css reset stuff / using chakra reset? but anyway looks good!

@notmd
Copy link
Collaborator Author

notmd commented Feb 15, 2023

I am not really sure what is the reason for the disabling css reset stuff / using chakra reset? but anyway looks good!

Tailwind also reset style ol tag . I just look overall the site when change CSS reset to Charka, it still look good.

Copy link
Collaborator

@AbdBarho AbdBarho left a comment

Choose a reason for hiding this comment

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

👏

@AbdBarho AbdBarho merged commit 07bc2f6 into main Feb 15, 2023
@AbdBarho AbdBarho deleted the markdown-rendering branch February 15, 2023 18:50
AbdBarho pushed a commit that referenced this pull request Feb 17, 2023
Follow up of #1544
Also fix #1657

- Add a preview tab just like Github when doing tasks.
- Display preview markdown when clicking the review button.
- Use
[https://github.com/Andarist/react-textarea-autosize](https://github.com/Andarist/react-textarea-autosize)
to make the textarea auto-grow when typing, so users don't need to
scroll anymore.


![image](https://user-images.githubusercontent.com/33456881/219382379-5b29c0c9-d043-490b-97d8-473e1091da08.png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for structured message responses
4 participants