-
Notifications
You must be signed in to change notification settings - Fork 1
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 render idea working #1713
base: master
Are you sure you want to change the base?
Changes from all commits
ca40bac
de05df3
d763e5d
04c91e7
87e780b
68d2443
3269b74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.textBox, | ||
.markdownBox { | ||
min-height: 550px; | ||
max-height: 550px; /* Add max-height to enable scrolling */ | ||
margin: 10px; | ||
font-size: 16px; | ||
line-height: 1.5; | ||
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er dette forskjellig fra default? |
||
padding: 8px 12px; | ||
display: block; | ||
font-family: inherit; | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er ikke begge disse default? |
||
color: #333333; | ||
background-color: #ffffff; | ||
border: 1px solid #cccccc; | ||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vi pleier å prøve å bruke farger fra 'constants' filen. Bare så fargene skal være konsekvente. Det gjør du ved å skrive:
Se i "constants.scss" filen for å se alle fargene |
||
border-radius: 4px; | ||
resize: vertical; | ||
box-sizing: border-box; | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mulig box-sizing er default i prosjektet (Er ikke det generelt i css, men burde vært det). Da trenger du ikke definere det på nytt her |
||
width: 100%; | ||
overflow-y: auto; /* Enable vertical scrolling */ | ||
} | ||
|
||
.markdownBox { | ||
cursor: pointer; /* Add cursor pointer to indicate it's clickable */ | ||
} | ||
Comment on lines
+21
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dette er vel ikke nødvendig nå som det er en button? |
||
|
||
.markdownContent { | ||
/* stylelint-disable-next-line selector-max-type */ | ||
p, | ||
pre { | ||
margin: 0; | ||
} | ||
|
||
/* Make sure content doesn't overflow horizontally */ | ||
width: 100%; | ||
box-sizing: border-box; | ||
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jeg tror |
||
overflow-wrap: break-word; /* Ensure long words don't overflow */ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useState } from 'react'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { toast } from 'react-toastify'; | ||
import { z } from 'zod'; | ||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, Textarea } from '~/Components'; | ||
import { SamfMarkdown } from '~/Components/SamfMarkdown'; | ||
import { putRecrutmentInterviewNotes } from '~/api'; | ||
import { KEY } from '~/i18n/constants'; | ||
import styles from './RecruitmentInterviewNotesForm.module.scss'; | ||
|
||
const recruitmentNotesSchema = z.object({ | ||
notes: z.string(), | ||
|
@@ -24,6 +26,7 @@ interface RecruitmentInterviewNotesFormProps { | |
export function RecruitmentInterviewNotesForm({ initialData, interviewId }: RecruitmentInterviewNotesFormProps) { | ||
const { t } = useTranslation(); | ||
const [currentNotes, setCurrentNotes] = useState(initialData.notes || ''); | ||
const [markdownState, setMarkdownState] = useState<boolean>(false); | ||
const form = useForm<RecruitmentInterviewNotesFormType>({ | ||
resolver: zodResolver(recruitmentNotesSchema), | ||
defaultValues: { | ||
|
@@ -43,9 +46,25 @@ export function RecruitmentInterviewNotesForm({ initialData, interviewId }: Recr | |
}, | ||
}); | ||
|
||
const textareaRef = useRef<HTMLTextAreaElement>(null); | ||
|
||
useEffect(() => { | ||
if (markdownState && textareaRef.current) { | ||
const textarea = textareaRef.current; | ||
textarea.focus(); | ||
// Set cursor position to end of text | ||
textarea.setSelectionRange(textarea.value.length, textarea.value.length); | ||
} | ||
}, [markdownState]); | ||
|
||
const handleFocus = () => { | ||
setMarkdownState(true); | ||
}; | ||
|
||
const handleNotesChange = (newNotes: string) => { | ||
if (newNotes !== currentNotes && interviewId) { | ||
setCurrentNotes(newNotes); | ||
|
||
handleUpdateNotes.mutate({ notes: newNotes, interviewId }); | ||
} | ||
}; | ||
|
@@ -61,13 +80,37 @@ export function RecruitmentInterviewNotesForm({ initialData, interviewId }: Recr | |
<FormItem> | ||
<FormLabel>{t(KEY.recruitment_interview_notes)}</FormLabel> | ||
<FormControl> | ||
<Textarea | ||
{...field} | ||
onBlur={(newNotes) => { | ||
field.onBlur(); // Call the default onBlur handler from react-hook-form | ||
handleNotesChange(newNotes.target.value); // Call your custom function on blur | ||
}} | ||
/> | ||
<div> | ||
{markdownState ? ( | ||
<Textarea | ||
{...field} | ||
ref={textareaRef} | ||
className={styles.textBox} | ||
onBlur={(newNotes) => { | ||
field.onBlur(); // Call the default onBlur handler from react-hook-form | ||
handleNotesChange(newNotes.target.value); // Call your custom function on blur | ||
Comment on lines
+90
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dette er nok ikke helt din skyld, men tror jeg hadde foretrukket (om mulig) at vi ikke forholdt oss til "newNotes", men heller bare forholdt oss til verdien til feltet i formet. Vet ikke om det funker med conditional rendering? |
||
setMarkdownState(false); | ||
}} | ||
/> | ||
) : ( | ||
<div | ||
onClick={handleFocus} | ||
className={styles.markdownBox} | ||
// biome-ignore lint/a11y/useSemanticElements: <explanation> | ||
role="button" | ||
tabIndex={0} | ||
onKeyDown={(e) => { | ||
if (e.key === 'Enter' || e.key === ' ') { | ||
handleFocus(); | ||
} | ||
}} | ||
Mathias-a marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
<div className={styles.markdownContent}> | ||
<SamfMarkdown>{currentNotes}</SamfMarkdown> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
Mathias-a marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nå har jeg ikke sett så nøye på dette, men dette kan nok løses med padding og/eller gap. Tror det er en bedre løsning. Forklaring på hvorfor jeg foretrekker det finner du her
https://dev.to/moruno21/dont-use-margin-in-css-33f9