Skip to content

Commit

Permalink
1233: Removed some unnessary props and renamed the file
Browse files Browse the repository at this point in the history
  • Loading branch information
lunars97 committed Nov 20, 2023
1 parent 9ac544a commit 773d118
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 131 deletions.
4 changes: 2 additions & 2 deletions native/src/components/Categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { URL_PREFIX } from '../constants/webview'
import TileModel from '../models/TileModel'
import testID from '../testing/testID'
import { LanguageResourceCacheStateType, PageResourceCacheStateType } from '../utils/DataContainer'
import CategoryListItem from './CategoryListItem'
import CategoryList from './CategoryList'
import OrganizationContentInfo from './OrganizationContentInfo'
import Page from './Page'
import Tiles from './Tiles'
Expand Down Expand Up @@ -81,7 +81,7 @@ const Categories = ({
path={category.path}
AfterContent={category.organization && <OrganizationContentInfo organization={category.organization} />}
Footer={children.map(it => (
<CategoryListItem
<CategoryList
key={it.path}
category={it}
subCategories={categories.getChildren(it)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type CategoryListItemProps = {
language: string
}

const CategoryListItem = ({
const CategoryList = ({
language,
category,
subCategories,
Expand Down Expand Up @@ -99,4 +99,4 @@ const CategoryListItem = ({
</>
)

export default memo(CategoryListItem)
export default memo(CategoryList)
7 changes: 3 additions & 4 deletions native/src/components/LayoutedScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ import Layout from './Layout'
type LayoutedScrollViewProps = {
children?: React.ReactNode
refreshControl?: React.ReactElement<RefreshControlProps>
nestedScrollEnabled?: boolean
}

const LayoutedScrollView = (props: LayoutedScrollViewProps): ReactElement => {
const { children, refreshControl, nestedScrollEnabled = true } = props
const { children, refreshControl } = props
return (
<Layout>
<ScrollView
keyboardShouldPersistTaps='always'
nestedScrollEnabled
refreshControl={refreshControl}
contentContainerStyle={{
flexGrow: 1,
}}
nestedScrollEnabled={nestedScrollEnabled}>
}}>
{children}
</ScrollView>
</Layout>
Expand Down
9 changes: 5 additions & 4 deletions native/src/components/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactElement } from 'react'
import { FlatList, RefreshControl, AccessibilityRole } from 'react-native'
import { FlatList, RefreshControl } from 'react-native'
import styled from 'styled-components/native'

const NoItemsMessage = styled.Text`
Expand All @@ -16,7 +16,7 @@ type ListProps<T> = {
Header?: ReactElement
Footer?: ReactElement
scrollEnabled?: boolean
accessibilityRole?: AccessibilityRole | undefined
accessibilityLabel?: string
refresh?: () => void
onEndReached?: () => void
}
Expand All @@ -28,7 +28,7 @@ const List = <T,>({
Header,
Footer,
refresh,
accessibilityRole,
accessibilityLabel,
onEndReached,
scrollEnabled,
}: ListProps<T>): ReactElement => (
Expand All @@ -51,7 +51,8 @@ const List = <T,>({
}}
onEndReachedThreshold={1}
scrollEnabled={scrollEnabled}
accessibilityRole={accessibilityRole}
accessibilityRole='list'
accessibilityLabel={accessibilityLabel}
/>
)

Expand Down
2 changes: 1 addition & 1 deletion native/src/components/SearchListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SEARCH_PREVIEW_MAX_CHARS } from '../constants'
import { contentDirection } from '../constants/contentDirection'
import { PageResourceCacheStateType } from '../utils/DataContainer'
import { getCachedThumbnail } from './Categories'
import { CategoryThumbnail } from './CategoryListItem'
import { CategoryThumbnail } from './CategoryList'
import Pressable from './base/Pressable'

const FlexStyledLink = styled(Pressable)`
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/SubCategoryListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CategoryModel } from 'api-client'
import { contentDirection } from '../constants/contentDirection'
import { PageResourceCacheStateType } from '../utils/DataContainer'
import { getCachedThumbnail } from './Categories'
import { CategoryThumbnail } from './CategoryListItem'
import { CategoryThumbnail } from './CategoryList'
import Pressable from './base/Pressable'

const SubCategoryTitleContainer = styled.View<{ language: string }>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import React from 'react'
import { CategoriesMapModelBuilder, CityModelBuilder, LanguageModelBuilder } from 'api-client'

import render from '../../testing/render'
import CategoryListItem from '../CategoryListItem'
import CategoryList from '../CategoryList'

jest.mock('styled-components')
jest.mock('react-native-webview', () => ({
default: () => jest.fn(),
}))

describe('CategoryListItem', () => {
describe('CategoryList', () => {
const cityModel = new CityModelBuilder(1).build()[0]!
const language = new LanguageModelBuilder(1).build()[0]!
const { categories: categoriesMapModel, resourceCache } = new CategoriesMapModelBuilder(
Expand All @@ -29,7 +29,7 @@ describe('CategoryListItem', () => {

it('should render category and subcategories', () => {
const { getByText } = render(
<CategoryListItem
<CategoryList
category={category}
subCategories={subCategories}
onItemPress={onItemPress}
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/__tests__/SearchListItem.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jest.mock('react-native-webview', () => ({
describe('SearchListItem', () => {
const cityModel = new CityModelBuilder(1).build()[0]!
const language = new LanguageModelBuilder(1).build()[0]!
const accessibilityHint = 'Navigates to the chosen item'
const accessibilityHint = 'Navigates to the chosen page'
const { categories: categoriesMapModel, resourceCache } = new CategoriesMapModelBuilder(
cityModel.code,
language.code,
Expand Down
20 changes: 3 additions & 17 deletions native/src/components/base/TextButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactElement } from 'react'
import { StyleProp, ViewStyle, AccessibilityRole } from 'react-native'
import { StyleProp, ViewStyle } from 'react-native'
import styled from 'styled-components/native'

import Pressable from './Pressable'
Expand All @@ -25,31 +25,17 @@ type TextButtonProps = {
text: string
onPress: () => Promise<void> | void
disabled?: boolean
accessible?: boolean
focusable?: boolean
accessibilityRole?: AccessibilityRole | undefined
type?: 'primary' | 'clear'
style?: StyleProp<ViewStyle>
}

const TextButton = ({
text,
onPress,
disabled = false,
type = 'primary',
style,
accessible,
accessibilityRole,
focusable,
}: TextButtonProps): ReactElement => (
const TextButton = ({ text, onPress, disabled = false, type = 'primary', style }: TextButtonProps): ReactElement => (
<StyledPressable
onPress={onPress}
primary={type === 'primary'}
disabled={disabled}
style={style}
accessible={accessible}
accessibilityRole={accessibilityRole}
focusable={focusable}>
accessibilityRole='button'>
<StyledText>{text}</StyledText>
</StyledPressable>
)
Expand Down
86 changes: 19 additions & 67 deletions native/src/routes/CityNotCooperating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import React, { ReactElement, useState } from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components/native'

import List from '../components/List'
import NothingFound from '../components/NothingFound'
import Icon from '../components/base/Icon'
import TextButton from '../components/base/TextButton'
import buildConfig, { buildConfigAssets } from '../constants/buildConfig'

const Container = styled.View`
const Container = styled.ScrollView`
display: flex;
flex: 1;
margin: 30px 30px 0 30px;
padding: 30px;
`

const Heading = styled.Text`
font-family: ${props => props.theme.fonts.native.decorativeFontBold};
font-size: 18px;
margin: 20px 20px 30px;
padding: 20px 20px 40px;
text-align: center;
`

Expand All @@ -30,7 +27,6 @@ const ListHeading = styled(Heading)`
align-self: flex-start;
font-size: 15px;
padding: 10px 0;
margin-bottom: -200px;
`

const ListItem = styled.View`
Expand All @@ -56,56 +52,31 @@ const StepExplanation = styled.Text`
padding-bottom: 4px;
`

const FooterContainer = styled.View`
display: flex;
justify-content: flex-end;
margin-bottom: 330px;
`

const StyledButton = styled(TextButton)`
z-index: 1;
margin: 15px auto 0;
width: 70%;
`

const TemplateText = styled.Text`
top: -20px;
border: 1px solid ${props => props.theme.colors.themeColor};
padding: 50px 30px 30px;
margin-top: -20px;
margin-bottom: 40px;
`

const StyledIcon = styled(Icon)`
margin: 10px 0;
align-self: center;
width: 50%;
height: 30%;
height: 20%;
`

type Step = {
number: string
id: string
explanation: string
}

const CityNotCooperating = (): ReactElement | null => {
const { t } = useTranslation('cityNotCooperating')
const [isCopied, setIsCopied] = useState<boolean>(false)
const template = buildConfig().featureFlags.cityNotCooperatingTemplate
const CityNotCooperatingIcon = buildConfigAssets().CityNotCooperatingIcon

const steps: Step[] = [
{
id: '1',
number: '1',
explanation: 'findOutMail',
},
{
id: '2',
number: '2',
explanation: 'sendText',
},
]

if (!template) {
return null
}
Expand All @@ -115,43 +86,24 @@ const CityNotCooperating = (): ReactElement | null => {
setIsCopied(true)
}

const renderStepsList = ({ item }: { item: Step; index: number }) => (
<ListItem>
<StepNumber>{item.number}</StepNumber>
<StepExplanation>{t(item.explanation)}</StepExplanation>
</ListItem>
)

const CooperationHeader = (
<>
return (
<Container>
<Heading>{t('callToAction')}</Heading>

<Description>{t('explanation')}</Description>
{CityNotCooperatingIcon && <StyledIcon Icon={CityNotCooperatingIcon} />}
<ListHeading>{t('whatToDo')}</ListHeading>
</>
)

const CooperationFooter = (
<FooterContainer>
<StyledButton
onPress={copyToClipboard}
text={isCopied ? t('common:copied') : t('copyText')}
accessibilityRole='button'
/>
<ListItem>
<StepNumber>1</StepNumber>
<StepExplanation>{t('findOutMail')}</StepExplanation>
</ListItem>
<ListItem>
<StepNumber>2</StepNumber>
<StepExplanation>{t('sendText')}</StepExplanation>
</ListItem>

<StyledButton onPress={copyToClipboard} text={isCopied ? t('common:copied') : t('copyText')} />
<TemplateText>{template}</TemplateText>
</FooterContainer>
)

return (
<Container>
<List
items={steps}
accessibilityRole='list'
renderItem={renderStepsList}
Header={CooperationHeader}
Footer={CooperationFooter}
noItemsMessage={<NothingFound />}
/>
</Container>
)
}
Expand Down
4 changes: 2 additions & 2 deletions native/src/routes/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ const SearchModal = ({
resourceCache={resourceCache[item.category.path] ?? {}}
contentWithoutHtml={item.contentWithoutHtml}
language={languageCode}
accessibilityHint={t('itemHint')}
query={query}
accessibilityHint={t(`It navigates to the description of the item`)}
onItemPress={onItemPress}
/>
)
Expand All @@ -114,7 +114,7 @@ const SearchModal = ({
<List
items={searchResults}
renderItem={renderItem}
accessibilityRole='text'
accessibilityLabel={`${searchCategories(categories, query).length} ${t('searchResults')}`}
noItemsMessage={
<>
<NothingFound />
Expand Down
2 changes: 2 additions & 0 deletions translations/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8368,6 +8368,8 @@
"de": {
"nothingFound": "Es wurden leider keine passenden Ergebnisse gefunden.",
"searchPlaceholder": "Suche",
"itemHint": "Es navigiert zur Beschreibung der Seite",
"searchResults": "Suchergebnisse",
"pageTitle": "Suche",
"delete": "Eingabe löschen"
},
Expand Down
Loading

0 comments on commit 773d118

Please sign in to comment.