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

127 fonsizes na celej stranke #257

Merged
merged 15 commits into from
Dec 9, 2023
25 changes: 0 additions & 25 deletions src/components/Archive/Archive.module.scss

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/Archive/Archive.module.scss.d.ts

This file was deleted.

34 changes: 21 additions & 13 deletions src/components/Archive/Archive.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Stack, Typography} from '@mui/material'
import {useQuery} from '@tanstack/react-query'
import axios from 'axios'
import {FC} from 'react'

import {Event, Publication} from '@/types/api/competition'
import {useSeminarInfo} from '@/utils/useSeminarInfo'

import {Link} from '../Clickable/Clickable'
import {Link} from '../Clickable/Link'
import {Loading} from '../Loading/Loading'
import styles from './Archive.module.scss'

// TODO: check whether we can safely assume presence of these and either update it on BE so it gets generated that way, or update it in our `types/api/competition`
type MyPublication = Publication & {
Expand All @@ -24,7 +24,7 @@ const PublicationButton: FC<{
publicationName: string
}> = ({publicationId, publicationName}) => {
return (
<Link href={`/api/competition/publication/${publicationId}/download`} target="_blank">
<Link variant="button2" href={`/api/competition/publication/${publicationId}/download`} target="_blank">
Časopis {publicationName}
</Link>
)
Expand All @@ -36,7 +36,11 @@ const ResultsButton: FC<{
}> = ({eventYear, eventSeason}) => {
const season = eventSeason === 0 ? 'zima' : 'leto'
const url = `../vysledky/${eventYear}/${season}`
return <Link href={url}>Výsledky</Link>
return (
<Link variant="button2" href={url}>
Výsledky
</Link>
)
}

const ProblemsButton: FC<{
Expand All @@ -45,7 +49,11 @@ const ProblemsButton: FC<{
}> = ({eventYear, eventSeason}) => {
const season = eventSeason === 0 ? 'zima' : 'leto'
const url = `../zadania/${eventYear}/${season}/1`
return <Link href={url}>Zadania</Link>
return (
<Link variant="button2" href={url}>
Zadania
</Link>
)
}

export const Archive: FC = () => {
Expand All @@ -58,16 +66,16 @@ export const Archive: FC = () => {
const eventList = eventListData?.data ?? []

return (
<div className={styles.archive}>
<Stack gap={2.5}>
{eventListIsLoading && <Loading />}
{eventList.map((event) => (
<div key={event.id} className={styles.archiveRow}>
<span className={styles.eventName}>
<Stack key={event.id} direction="row" justifyContent="space-between">
<Typography variant="h3" component="span">
{event.year + '. ročník '}
{event.season_code === 0 ? 'zimný' : 'letný'}
{' semester'}
</span>
<div className={styles.actions}>
</Typography>
<Stack gap={2} direction="row" alignItems="center">
<ResultsButton eventYear={event.year} eventSeason={event.season_code} />
<ProblemsButton eventYear={event.year} eventSeason={event.season_code} />
{event.publication_set.map((publication) => (
Expand All @@ -77,9 +85,9 @@ export const Archive: FC = () => {
publicationName={publication.name}
/>
))}
</div>
</div>
</Stack>
</Stack>
))}
</div>
</Stack>
)
}
27 changes: 27 additions & 0 deletions src/components/Clickable/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Typography, TypographyProps} from '@mui/material'
import clsx from 'clsx'
import {ButtonHTMLAttributes, FC, ReactNode} from 'react'

import styles from './Clickable.module.scss'

type ButtonProps = {
onClick?: () => void
disabled?: boolean
children: ReactNode
variant?: TypographyProps['variant']
} & Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'type'>

export const Button: FC<ButtonProps> = ({children, onClick, disabled, type, variant}) => {
return (
<Typography
variant={variant ?? 'button3'}
component="button"
onClick={onClick}
className={clsx(styles.actionButton, disabled && styles.disabled)}
disabled={disabled}
type={type}
>
{children}
</Typography>
)
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
import {Typography} from '@mui/material'
import {Typography, TypographyProps} from '@mui/material'
import clsx from 'clsx'
import NextLink from 'next/link'
import {ButtonHTMLAttributes, ComponentProps, FC, ReactNode} from 'react'
import {ComponentProps, FC, ReactNode} from 'react'

import styles from './Clickable.module.scss'

type ButtonProps = {
onClick?: () => void
disabled?: boolean
children: ReactNode
} & Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'type'>

export const Button: FC<ButtonProps> = ({children, onClick, disabled, type}) => {
return (
<Typography
variant="button3"
component="button"
onClick={onClick}
className={clsx(styles.actionButton, disabled && styles.disabled)}
disabled={disabled}
type={type}
>
{children}
</Typography>
)
}

type LinkProps = {
href?: string
disabled?: boolean
children: ReactNode
variant?: TypographyProps['variant']
} & Pick<ComponentProps<typeof NextLink>, 'target'>

export const Link: FC<LinkProps> = ({children, href, disabled, target}) => {
export const Link: FC<LinkProps> = ({children, href, disabled, target, variant}) => {
// https://a11y-guidelines.orange.com/en/articles/disable-elements/#disable-a-link
return disabled ? (
<Typography
variant="button3"
variant={variant ?? 'button3'}
component="a"
className={clsx(styles.actionButton, styles.disabled)}
aria-disabled
Expand All @@ -46,7 +26,7 @@ export const Link: FC<LinkProps> = ({children, href, disabled, target}) => {
</Typography>
) : (
<Typography
variant="button3"
variant={variant ?? 'button3'}
component={NextLink}
href={href ?? ''}
target={target}
Expand Down
8 changes: 4 additions & 4 deletions src/components/CompetitionPage/CompetitionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {useRouter} from 'next/router'
import {FC, Fragment} from 'react'

import {Link} from '@/components/Clickable/Clickable'
import {Link} from '@/components/Clickable/Link'
import {Competition, Event} from '@/types/api/competition'
import {BannerContainer} from '@/utils/BannerContainer'
import {formatDate} from '@/utils/formatDate'
import {formatDateTime} from '@/utils/formatDate'

import styles from './competition.module.scss'

Expand All @@ -19,8 +19,8 @@ export const CompetitionPage: FC<CompetitionPageProps> = ({
}) => {
const {setBannerText} = BannerContainer.useContainer()

const startDate = upcoming_or_current_event ? formatDate(upcoming_or_current_event.start) : null
const endDate = upcoming_or_current_event ? formatDate(upcoming_or_current_event.end) : null
const startDate = upcoming_or_current_event ? formatDateTime(upcoming_or_current_event.start) : null
const endDate = upcoming_or_current_event ? formatDateTime(upcoming_or_current_event.end) : null
setBannerText(startDate ? `${name} sa bude konať ${startDate}` : '')

const router = useRouter()
Expand Down
4 changes: 2 additions & 2 deletions src/components/CompetitionPage/RulesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {FC} from 'react'
import {Markdown} from '@/components/StaticSites/Markdown'
import {Competition} from '@/types/api/generated/competition'
import {BannerContainer} from '@/utils/BannerContainer'
import {formatDate} from '@/utils/formatDate'
import {formatDateTime} from '@/utils/formatDate'

type RulesPageProps = Pick<Competition, 'rules' | 'upcoming_or_current_event' | 'name'>

export const RulesPage: FC<RulesPageProps> = ({name, rules, upcoming_or_current_event}) => {
const {setBannerText} = BannerContainer.useContainer()

const startDate = formatDate(upcoming_or_current_event?.start)
const startDate = formatDateTime(upcoming_or_current_event?.start)
setBannerText(upcoming_or_current_event ? `${name} sa bude konať ${startDate}` : '')

return <Markdown content={rules ?? ''} />
Expand Down
9 changes: 0 additions & 9 deletions src/components/FormItems/Form.module.scss

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/FormItems/Form.module.scss.d.ts

This file was deleted.

12 changes: 9 additions & 3 deletions src/components/Latex/Latex.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Typography} from '@mui/material'
import {MathComponentProps} from 'mathjax-react/dist/components/MathComponent'
import dynamic from 'next/dynamic'
import {FC, Fragment} from 'react'
Expand Down Expand Up @@ -25,15 +26,15 @@ export const Latex: FC<{children: string}> = ({children}) => {
const matches = Array.from(children.matchAll(re))

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

const result = []
let currentPosition = 0

for (const m of matches) {
result.push(
<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 @@ -42,7 +43,12 @@ export const Latex: FC<{children: string}> = ({children}) => {
}
}

result.push(<span dangerouslySetInnerHTML={{__html: `${children.slice(Math.max(0, currentPosition))}`}} />)
result.push(
<Typography
variant="body1"
dangerouslySetInnerHTML={{__html: `${children.slice(Math.max(0, currentPosition))}`}}
/>,
)

return (
// nas globalny CSS reset nastavuje SVGcka na display:block, tak to tu resetneme nazad na inline
Expand Down
2 changes: 1 addition & 1 deletion src/components/Latex/LatexExample.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ChangeEvent, FC, useState} from 'react'

import {Link} from '../Clickable/Clickable'
import {Link} from '../Clickable/Link'
import {Latex} from './Latex'
import styles from './LatexExample.module.scss'

Expand Down
40 changes: 23 additions & 17 deletions src/components/PageLayout/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Stack} from '@mui/material'
import {useRouter} from 'next/router'
import {FC} from 'react'
import {SubmitHandler, useForm} from 'react-hook-form'

import {Button} from '@/components/Clickable/Clickable'
import styles from '@/components/FormItems/Form.module.scss'
import {Button} from '@/components/Clickable/Button'
import {FormInput} from '@/components/FormItems/FormInput/FormInput'
import {AuthContainer} from '@/utils/AuthContainer'

Expand Down Expand Up @@ -41,21 +41,27 @@ export const LoginForm: FC<ILoginForm> = ({closeOverlay}) => {
const requiredRule = {required: '* Toto pole nemôže byť prázdne.'}

return (
<form className={styles.form} onSubmit={handleSubmit(onSubmit)}>
<FormInput
control={control}
name="email"
label="Email"
rules={{
...requiredRule,
pattern: {
value: /^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu,
message: '* Vložte správnu emailovú adresu.',
},
}}
/>
<FormInput control={control} name="password" label="Heslo" type="password" rules={requiredRule} />
<Button type="submit">Prihlásiť</Button>
<form onSubmit={handleSubmit(onSubmit)}>
<Stack gap={2}>
<FormInput
control={control}
name="email"
label="Email"
rules={{
...requiredRule,
pattern: {
value: /^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu,
message: '* Vložte správnu emailovú adresu.',
},
}}
/>
<FormInput control={control} name="password" label="Heslo" type="password" rules={requiredRule} />
<Stack alignItems="center" mt={2}>
<Button variant="button2" type="submit">
Prihlásiť
</Button>
</Stack>
</Stack>
</form>
)
}
Loading
Loading