Skip to content

Commit

Permalink
Merge pull request #1070 from prolland006/bug1066
Browse files Browse the repository at this point in the history
#1066 Capitalization across Community Platform
  • Loading branch information
davehakkens authored Jul 17, 2021
2 parents cb22542 + f72181d commit cc9b2b3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/components/EventCard/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button } from 'src/components/Button'
import TagDisplay from 'src/components/Tags/TagDisplay/TagDisplay'
import FlagIconEvents from 'src/components/Icons/FlagIcon/FlagIcon'
import { IEvent } from '../../models/events.models'
import { getMonth, getDay } from 'src/utils/helpers'
import { getMonth, getDay, capitalizeFirstLetter } from 'src/utils/helpers'
import { LinkTargetBlank } from '../Links/LinkTargetBlank/LinkTargetBlank'

interface IProps {
Expand Down Expand Up @@ -76,7 +76,7 @@ export const EventCard = (props: IProps) => (
>
<Flex alignItems={'center'} width={1}>
<Text bold color="black" fontSize={[3, 3, 4]}>
{props.event.title}
{capitalizeFirstLetter(props.event.title)}
</Text>
</Flex>
<Text auxiliary width={1}>
Expand Down
33 changes: 32 additions & 1 deletion src/components/Form/Fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import {
} from './elements'
import { FieldRenderProps } from 'react-final-form'
import 'react-datepicker/dist/react-datepicker.css'
import { capitalizeFirstLetter } from 'src/utils/helpers'

// any props can be passed to field and down to child component
// input and meta props come from react field render props and will be
// picked up by typing
type FieldProps = FieldRenderProps<any, any> & { children?: React.ReactNode }

type InputModifiers = {
capitalize?: boolean
}
export interface IFieldProps extends FieldProps {
// additional fields intending to pass down
disabled?: boolean
Expand All @@ -25,10 +30,19 @@ interface IDatePickerFieldProps extends IFieldProps {
customChange?: (location) => void
}

const processInputModifiers = (value: any, modifiers: InputModifiers = {}) => {
if (typeof value !== 'string') return value
if (modifiers.capitalize) {
value = capitalizeFirstLetter(value)
}
return value
}

export const InputField = ({
input,
meta,
customOnBlur,
modifiers,
...rest
}: IFieldProps) => (
<>
Expand All @@ -37,17 +51,22 @@ export const InputField = ({
{...input}
{...rest}
onBlur={e => {
if (modifiers) {
e.target.value = processInputModifiers(e.target.value, modifiers)
input.onChange(e)
}
if (customOnBlur) {
customOnBlur(e)
}
input.onBlur()
input.onBlur(e)
}}
/>
{meta.error && meta.touched ? (
<ErrorMessage>{meta.error}</ErrorMessage>
) : null}
</>
)

export const DatePickerField = ({
input,
meta,
Expand Down Expand Up @@ -82,6 +101,8 @@ export const TextAreaField = ({
input,
meta,
disabled,
modifiers,
customOnBlur,
...rest
}: IFieldProps) =>
disabled ? (
Expand All @@ -93,6 +114,16 @@ export const TextAreaField = ({
invalid={meta.error && meta.touched}
{...input}
{...rest}
onBlur={e => {
if (modifiers) {
e.target.value = processInputModifiers(e.target.value, modifiers)
input.onChange(e)
}
if (customOnBlur) {
customOnBlur(e)
}
input.onBlur()
}}
/>
{meta.error && meta.touched && <ErrorMessage>{meta.error}</ErrorMessage>}
</>
Expand Down
1 change: 1 addition & 0 deletions src/pages/Events/Content/EventsCreate/EventsCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class EventsCreate extends React.Component<IProps, IState> {
data-cy="title"
validate={required}
validateFields={[]}
modifiers={{ capitalize: true }}
component={InputField}
maxLength="140"
placeholder="Title of your event (max 140 characters)"
Expand Down
22 changes: 13 additions & 9 deletions src/pages/Howto/Content/Common/Howto.form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,29 @@ interface IInjectedProps extends IProps {

const AnimationContainer = (props: any) => {
const variants = {
pre: {
opacity: 0
pre: {
opacity: 0,
},
enter: {
opacity: 1,
duration: .200,
display: "block",
duration: 0.2,
display: 'block',
},
post: {
display: "none",
duration: .200,
display: 'none',
duration: 0.2,
top: '-100%',
},
}
return (
<motion.div layout
<motion.div
layout
initial="pre"
animate="enter"
exit="post"
variants={variants}>
{ props.children }
variants={variants}
>
{props.children}
</motion.div>
)
}
Expand Down Expand Up @@ -239,6 +241,7 @@ export class HowtoForm extends React.PureComponent<IProps, IState> {
validateFields={[]}
validate={this.validateTitle}
isEqual={COMPARISONS.textInput}
modifiers={{ capitalize: true }}
component={InputField}
maxLength="50"
placeholder="Make a chair from.. (max 50 characters)"
Expand Down Expand Up @@ -296,6 +299,7 @@ export class HowtoForm extends React.PureComponent<IProps, IState> {
data-cy="intro-description"
validate={required}
validateFields={[]}
modifiers={{ capitalize: true }}
isEqual={COMPARISONS.textInput}
component={TextAreaField}
style={{
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Howto/Content/Common/HowtoStep.form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PureComponent } from 'react';
import { PureComponent } from 'react'
import { Field } from 'react-final-form'
import { TextAreaField, InputField } from 'src/components/Form/Fields'
import Heading from 'src/components/Heading'
Expand Down Expand Up @@ -143,6 +143,7 @@ class HowtoStep extends PureComponent<IProps, IState> {
<Field
name={`${step}.title`}
data-cy="step-title"
modifiers={{ capitalize: true }}
component={InputField}
placeholder="Title of this step (max 30 characters)"
maxLength="30"
Expand All @@ -158,6 +159,7 @@ class HowtoStep extends PureComponent<IProps, IState> {
placeholder="Explain what you are doing in this step. if it gets to long break it into 2 steps (max 700 characters)"
maxLength="700"
data-cy="step-description"
modifiers={{ capitalize: true }}
component={TextAreaField}
style={{ resize: 'vertical', height: '300px' }}
validate={required}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import TimeNeeded from 'src/assets/icons/icon-time-needed.svg'
import DifficultyLevel from 'src/assets/icons/icon-difficulty-level.svg'
import { Button } from 'src/components/Button'
import { IUser } from 'src/models/user.models'
import { isAllowToEditContent, emStringToPx } from 'src/utils/helpers'
import {
isAllowToEditContent,
emStringToPx,
capitalizeFirstLetter,
} from 'src/utils/helpers'
import theme from 'src/themes/styled.theme'
import ArrowIcon from 'src/assets/icons/icon-arrow-select.svg'
import { FlagIconHowTos } from 'src/components/Icons/FlagIcon/FlagIcon'
Expand Down Expand Up @@ -147,7 +151,8 @@ export default class HowtoDescription extends PureComponent<IProps> {
{this.dateLastEditText(howto)}
</Text>
<Heading medium mt={2} mb={1}>
{howto.title}
{/* HACK 2021-07-16 - new howtos auto capitalize title but not older */}
{capitalizeFirstLetter(howto.title)}
</Heading>
<Text preLine paragraph>
{howto.description}
Expand Down
11 changes: 8 additions & 3 deletions src/pages/Howto/Content/Howto/Step/Step.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PureComponent } from 'react';
import { PureComponent } from 'react'
import Linkify from 'react-linkify'
import ReactPlayer from 'react-player'
import { Box } from 'rebass'
Expand All @@ -8,6 +8,7 @@ import ImageGallery from 'src/components/ImageGallery'
import Text from 'src/components/Text'
import { IHowtoStep } from 'src/models/howto.models'
import { IUploadedFileMeta } from 'src/stores/storage'
import { capitalizeFirstLetter } from 'src/utils/helpers'
import styled from 'styled-components'

interface IProps {
Expand Down Expand Up @@ -57,11 +58,15 @@ export default class Step extends PureComponent<IProps> {
>
<Flex width={[1, 1, 4 / 9]} py={4} px={4} flexDirection={'column'}>
<Heading medium mb={0}>
{step.title}
{/* HACK 2021-07-16 - new howtos auto capitalize title but not older */}
{capitalizeFirstLetter(step.title)}
</Heading>
<Box>
<Text preLine paragraph mt={3} color={'grey'}>
<Linkify>{step.text}</Linkify>
<Linkify>
{/* HACK 2021-07-16 - new howtos auto capitalize title but not older */}
{capitalizeFirstLetter(step.text)}
</Linkify>
</Text>
</Box>
</Flex>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Howto/Content/HowtoList/HowToCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FlagIconHowTos } from 'src/components/Icons/FlagIcon/FlagIcon'
import TagDisplay from 'src/components/Tags/TagDisplay/TagDisplay'
import { IHowtoDB } from 'src/models/howto.models'
import Heading from 'src/components/Heading'
import { capitalizeFirstLetter } from 'src/utils/helpers'

interface IProps {
howto: IHowtoDB
Expand Down Expand Up @@ -48,7 +49,8 @@ export const HowToCard = (props: IProps) => (
</Flex>
<Flex px={3} py={3} flexDirection="column">
<Heading small clipped color={'black'}>
{props.howto.title}
{/* HACK 2021-07-16 - new howtos auto capitalize title but not older */}
{capitalizeFirstLetter(props.howto.title)}
</Heading>
<Flex alignItems="center">
{props.howto.creatorCountry && (
Expand Down

0 comments on commit cc9b2b3

Please sign in to comment.