Skip to content

Commit

Permalink
Refactor after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Matushl committed Dec 9, 2023
1 parent b218181 commit 1942946
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 34 deletions.
9 changes: 2 additions & 7 deletions src/components/Latex/Latex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ export const Latex: FC<{children: string}> = ({children}) => {
const matches = Array.from(children.matchAll(re))

if (matches.length === 0) {
return <Typography variant="body1" component="span" dangerouslySetInnerHTML={{__html: `${children}`}} />
return <Typography variant="body1" dangerouslySetInnerHTML={{__html: `${children}`}} />
}

const result = []
let currentPosition = 0

for (const m of matches) {
result.push(
<Typography
variant="body1"
component="span"
dangerouslySetInnerHTML={{__html: `${children.slice(currentPosition, m.index)}`}}
/>,
<Typography variant="body1" dangerouslySetInnerHTML={{__html: `${children.slice(currentPosition, m.index)}`}} />,
<MathComponent tex={trim(m[0])} display={m[0].slice(0, 2) === '\\[' || m[0].slice(0, 2) === '$$'} />,
)

Expand All @@ -50,7 +46,6 @@ export const Latex: FC<{children: string}> = ({children}) => {
result.push(
<Typography
variant="body1"
component="span"
dangerouslySetInnerHTML={{__html: `${children.slice(Math.max(0, currentPosition))}`}}
/>,
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Posts/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Post: FC<IPost> = ({id, caption, short_text, links, sites, added_at
if (!sites.includes(seminarId)) return null

return (
<Stack key={id}>
<Stack>
<Typography variant="postTitle">{caption}</Typography>
<Typography variant="postBody" component="p">
{short_text}
Expand All @@ -39,7 +39,7 @@ export const Post: FC<IPost> = ({id, caption, short_text, links, sites, added_at
))}
</Stack>

<Typography variant="body1" component="p" fontWeight={275} textTransform="uppercase">
<Typography variant="body1" fontWeight={275} textTransform="uppercase">
{formatDate(added_at)}
</Typography>
</Stack>
Expand Down
18 changes: 5 additions & 13 deletions src/components/Problems/Discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,20 @@ export const Discussion: FC<DiscussionProps> = ({problemId, problemNumber, close
<Typography variant="h3" component="span">
{comment.posted_by_name}
</Typography>
<Typography variant="body1" component="span">
{comment.text}
</Typography>
<Typography variant="body1">{comment.text}</Typography>
{comment.hidden_response && (
<Stack ml={2}>
<Typography variant="h3" component="span">
Vedúci:
</Typography>
<Typography variant="body1" component="span">
{comment.hidden_response}
</Typography>
<Typography variant="body1">{comment.hidden_response}</Typography>
</Stack>
)}
{comment.state === CommentState.WaitingForReview && (
<Typography variant="body3" component="span">
* komentár čaká na schválenie
</Typography>
<Typography variant="body3">* komentár čaká na schválenie</Typography>
)}
{comment.state === CommentState.Hidden && (
<Typography variant="body3" component="span">
* tento komentár nie je verejný
</Typography>
<Typography variant="body3">* tento komentár nie je verejný</Typography>
)}
{hiddenResponseDialogId === comment.id ? (
<Stack my={1} gap={1}>
Expand Down Expand Up @@ -203,7 +195,7 @@ export const Discussion: FC<DiscussionProps> = ({problemId, problemNumber, close
</Stack>
</>
) : (
<Typography variant="body2" component="span" sx={{color: 'gray'}}>
<Typography variant="body2" sx={{color: 'gray'}}>
Prispievať do diskusie môžu len prihlásení uživatelia.
</Typography>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Problems/Problems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ export const Problems: FC = () => {
title="Skontroluj prosím, čí údaje o ročníku a škole sú správne."
contentText={
<Stack gap={2}>
<Stack direction={'row'} spacing={1}>
<Stack direction={'row'} gap={1}>
<Typography variant="h3" component="span">
Škola
</Typography>
<Typography variant="h3" fontStyle="normal" fontWeight="400" textTransform="none" component="span">
{profile?.school.verbose_name}
</Typography>
</Stack>
<Stack direction={'row'} spacing={1}>
<Stack direction={'row'} gap={1}>
<Typography variant="h3" component="span">
Ročník
</Typography>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Profile/ProfileDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ProfileLineInput = {

const ProfileLine: FC<ProfileLineInput> = ({label, value}) => {
return (
<Stack direction={'row'} spacing={1}>
<Stack direction={'row'} gap={1}>
<Typography variant="h2" component="span">
{label}
</Typography>
Expand Down Expand Up @@ -48,7 +48,7 @@ export const ProfileDetail: FC = () => {

return (
<Stack>
<Stack spacing={4}>
<Stack gap={4}>
<ProfileLine label={'meno'} value={profile?.first_name || '-'} />
<ProfileLine label={'priezvisko'} value={profile?.last_name || '-'} />
<ProfileLine label={'e-mail'} value={profile?.email || '-'} />
Expand All @@ -57,7 +57,7 @@ export const ProfileDetail: FC = () => {
<ProfileLine label={'tel. č.'} value={profile?.phone || '-'} />
<ProfileLine label={'tel. č. na rodiča'} value={profile?.parent_phone || '-'} />
</Stack>
<Stack direction={'row'} mt={3} spacing={5}>
<Stack direction={'row'} mt={3} gap={5}>
<Link variant="button2" href={`/${seminar}/profil/uprava`}>
Upraviť údaje
</Link>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Profile/ProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ export const ProfileForm: FC = () => {
}
return (
<form onSubmit={handleSubmit(onSubmit)}>
<Stack spacing={5}>
<Stack gap={5}>
<FormInput control={control} name="first_name" label="krstné meno*" rules={requiredRule} />
<FormInput control={control} name="last_name" label="priezvisko*" rules={requiredRule} />
<SchoolSubForm control={control} watch={watch} setValue={setValue} spacing={5} />
<SchoolSubForm control={control} watch={watch} setValue={setValue} gap={5} />
<FormInput control={control} name="phone" label="telefónne číslo" rules={phoneRule} />
<FormInput control={control} name="parent_phone" label="telefónne číslo na rodiča" rules={phoneRule} />
<p style={{fontWeight: 'bold'}}>* takto označéné polia sú povinné</p>
<Stack direction={'row'} mt={3} spacing={2} justifyContent="space-between">
<Stack direction={'row'} mt={3} gap={2} justifyContent="space-between">
<Button onClick={returnBack} variant="button2">
Späť
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/RegisterForm/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const RegisterForm: FC = () => {
/>
<FormInput control={control} name="first_name" label="krstné meno*" rules={requiredRule} />
<FormInput control={control} name="last_name" label="priezvisko*" rules={requiredRule} />
<SchoolSubForm control={control} watch={watch} setValue={setValue} spacing={2} />
<SchoolSubForm control={control} watch={watch} setValue={setValue} gap={2} />
<FormInput control={control} name="phone" label="telefónne číslo" rules={phoneRule} />
<FormInput control={control} name="parent_phone" label="telefónne číslo na rodiča" rules={phoneRule} />
<Typography variant="body2" fontWeight={800}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/SchoolSubForm/SchoolSubForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type SchoolSubFormProps<T extends SchoolSubFormValues> = {
control: Control<T, unknown>
watch: UseFormWatch<T>
setValue: UseFormSetValue<T>
spacing: number
gap: number
}

export const SchoolSubForm = ({control, watch, setValue, spacing}: SchoolSubFormProps<SchoolSubFormValues>) => {
export const SchoolSubForm = ({control, watch, setValue, gap}: SchoolSubFormProps<SchoolSubFormValues>) => {
const [school_not_found, without_school] = watch(['school_not_found', 'without_school'])

const otherSchoolItem = useRef<SelectOption>()
Expand Down Expand Up @@ -81,7 +81,7 @@ export const SchoolSubForm = ({control, watch, setValue, spacing}: SchoolSubForm

const requiredRule = {required: '* Toto pole nemôže byť prázdne.'}
return (
<Stack gap={spacing}>
<Stack gap={gap}>
<FormCheckbox control={control} name="without_school" label="nie som študent základnej ani strednej školy." />
<FormAutocomplete
control={control}
Expand Down

0 comments on commit 1942946

Please sign in to comment.