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

2808: Add a filter by date option to events #2898

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5028027
2808: Creating a component called CustomDatePicker and filtering even…
bahaaTuffaha Aug 20, 2024
b6683da
2808: Creating a hook for useDateFilter and a toggle to hide and show…
bahaaTuffaha Aug 21, 2024
8dd13b4
2808: web changes and adding translation and direction for RTL plus c…
bahaaTuffaha Aug 21, 2024
3fb9deb
2828: added a library called react-native-ui-datepicker and create Ca…
bahaaTuffaha Aug 22, 2024
566da43
2808: Added DateFilterToggle to native and improvements to useDateFil…
bahaaTuffaha Aug 24, 2024
3c0dbe5
2808: Adding translations and using React-native modal
bahaaTuffaha Aug 25, 2024
63d158a
Merge remote-tracking branch 'origin' into 2808-Add-a-filter-by-date-…
bahaaTuffaha Aug 25, 2024
4df2415
2808: Replacing (react-native-ui-datepicker) with (react-native-calen…
bahaaTuffaha Aug 27, 2024
c67fd25
Added some tests and release note
bahaaTuffaha Aug 27, 2024
60f9de7
Merge remote-tracking branch 'origin' into 2808-Add-a-filter-by-date-…
bahaaTuffaha Aug 27, 2024
193909c
2808: Refactoring code + some improvements
bahaaTuffaha Aug 27, 2024
e701023
Merge remote-tracking branch 'origin' into 2808-Add-a-filter-by-date-…
bahaaTuffaha Aug 27, 2024
5d18825
2808: prettier:check fixed for tsconfig
bahaaTuffaha Aug 27, 2024
c1cab6d
2808: Fixing Typescript issues
bahaaTuffaha Aug 27, 2024
25406e8
2808: Requested changes about DateTime
bahaaTuffaha Aug 29, 2024
3321eb4
2808: Fix translations
steffenkleinle Sep 10, 2024
115de27
2808: Requested changes part 2
bahaaTuffaha Sep 11, 2024
e652e78
Merge remote-tracking branch 'origin' into 2808-Add-a-filter-by-date-…
bahaaTuffaha Sep 11, 2024
000a9a4
2808: Requested changes part 3
bahaaTuffaha Sep 12, 2024
d7ca0ff
2808: Replacing names fromDate and toDate to startDate and endDate
bahaaTuffaha Sep 12, 2024
a6176f5
2808: Replacing alt with placeholder at date-input (web) for tests ge…
bahaaTuffaha Sep 13, 2024
5b10e03
2808: Requested changes Part4
bahaaTuffaha Sep 19, 2024
52db677
Merge remote-tracking branch 'origin' into 2808-Add-a-filter-by-date-…
bahaaTuffaha Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/icons/expand.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/shrink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"react-native": "0.73.7",
"react-native-blob-util": "^0.19.8",
"react-native-calendar-events": "^2.2.0",
"react-native-calendars": "^1.1306.0",
"react-native-gesture-handler": "^2.16.0",
"react-native-get-random-values": "^1.11.0",
"react-native-highlight-words": "^1.0.1",
Expand Down
4 changes: 4 additions & 0 deletions native/src/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CategoriesIcon from '../../../assets/icons/categories.svg'
import ClockIcon from '../../../assets/icons/clock.svg'
import CloseIcon from '../../../assets/icons/close.svg'
import EditLocationIcon from '../../../assets/icons/edit-location.svg'
import ExpandIcon from '../../../assets/icons/expand.svg'
import ExternalLinkIcon from '../../../assets/icons/external-link.svg'
import HappySmileyIcon from '../../../assets/icons/happy-smiley.svg'
import LanguageIcon from '../../../assets/icons/language.svg'
Expand All @@ -29,6 +30,7 @@ import RefreshIcon from '../../../assets/icons/refresh.svg'
import SadSmileyIcon from '../../../assets/icons/sad-smiley.svg'
import SearchIcon from '../../../assets/icons/search.svg'
import SecurityIcon from '../../../assets/icons/security.svg'
import ShrinkIcon from '../../../assets/icons/shrink.svg'
import SprungbrettIcon from '../../../assets/icons/sprungbrett.svg'
import SupportIcon from '../../../assets/icons/support.svg'
import TuNewsActiveIcon from '../../../assets/icons/tu-news-active.svg'
Expand All @@ -52,6 +54,8 @@ export {
EventThumbnailPlaceholder2,
EventThumbnailPlaceholder3,
ExternalLinkIcon,
ExpandIcon,
ShrinkIcon,
LocationFixedIcon,
LocationMarkerIcon,
LocationNotFixedIcon,
Expand Down
122 changes: 122 additions & 0 deletions native/src/components/CalendarRangeModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { DateTime } from 'luxon'
import React, { ReactElement, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Modal } from 'react-native'
import { Calendar } from 'react-native-calendars'
import styled, { useTheme } from 'styled-components/native'

import { getMarkedDates } from '../utils/calendarRangeUtils'
import Caption from './Caption'
import TextButton from './base/TextButton'

const DatePickerWrapper = styled.View`
background-color: ${props => props.theme.colors.textDecorationColor};
border-radius: 20px;
position: absolute;
width: 90%;
top: 228px;
justify-self: center;
/* stylelint-disable-next-line declaration-block-no-redundant-longhand-properties */
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
align-self: center;
`
const StyledView = styled.View`
gap: 8px;
flex-direction: row;
justify-content: ${props => (props.theme.contentDirection === 'rtl' ? 'flex-start' : 'flex-end')};
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
padding: 5px 10px;
`
const StyledTextButton = styled(TextButton)`
background-color: transparent;
transform: scale(0.8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the scale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TextButton too big... just to match the design. what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it should be possible to replace scale with height and width, right? Or is this not possible here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not possible here

`
const StyledPressable = styled.Pressable`
flex: 1;
`

export type CalendarViewerProps = {
modalVisible: boolean
closeModal: () => void
fromDate: DateTime | null
toDate: DateTime | null
setFromDate: (fromDate: DateTime) => void
setToDate: (toDate: DateTime) => void
}

const CalendarRangeModal = ({
modalVisible,
closeModal,
fromDate,
toDate,
setFromDate,
setToDate,
}: CalendarViewerProps): ReactElement => {
const [tempFromDate, setTempFromDate] = useState<DateTime | null>(fromDate)
const [tempToDate, setTempToDate] = useState<DateTime | null>(toDate)
const { t } = useTranslation('events')
const theme = useTheme()

useEffect(() => {
setTempFromDate(fromDate)
setTempToDate(toDate)
}, [fromDate, toDate])
steffenkleinle marked this conversation as resolved.
Show resolved Hide resolved

const handleDayPress = (day: { dateString: string }) => {
const selectedDate = DateTime.fromISO(day.dateString)

if (!tempFromDate) {
setTempFromDate(selectedDate)
setTempToDate(null)
} else if (!tempToDate) {
setTempToDate(selectedDate)
} else {
setTempFromDate(selectedDate)
setTempToDate(null)
}
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<Modal style={{ margin: 0 }} animationType='slide' transparent visible={modalVisible} onRequestClose={closeModal}>
<StyledPressable onPress={closeModal} />
<DatePickerWrapper>
<Caption title={t('selectRange')} />
<Calendar
markingType='period'
markedDates={getMarkedDates(tempFromDate, tempToDate)}
onDayPress={handleDayPress}
theme={{
calendarBackground: theme.colors.textDecorationColor,
dayTextColor: theme.colors.textColor,
textDisabledColor: theme.colors.textSecondaryColor,
todayTextColor: theme.colors.backgroundColor,
textSectionTitleColor: theme.colors.textColor,
arrowColor: theme.colors.textColor,
}}
/>
<StyledView>
<StyledTextButton
onPress={() => {
setTempFromDate(fromDate)
setTempToDate(toDate)
closeModal()
}}
text={t('layout:cancel')}
type='clear'
/>
<StyledTextButton
onPress={() => {
if (Boolean(tempFromDate) && Boolean(tempToDate)) {
setFromDate(tempFromDate || DateTime.local())
setToDate(tempToDate || DateTime.local())
}
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
closeModal()
}}
text={t('ok')}
type='clear'
/>
</StyledView>
</DatePickerWrapper>
</Modal>
)
}

export default CalendarRangeModal
139 changes: 139 additions & 0 deletions native/src/components/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { DateTime } from 'luxon'
import React, { ReactElement, useEffect, useState } from 'react'
import styled from 'styled-components/native'

import { DATE_FORMAT } from 'shared/constants'

import { CalendarTodayIcon } from '../assets'
import Icon from './base/Icon'
import IconButton from './base/IconButton'
import Text from './base/Text'

const DateContainer = styled.View`
width: fit-content;
position: relative;
`
const Input = styled.TextInput`
text-align: center;
`
const StyledInputWrapper = styled.View`
min-width: 316px;
height: 56px;
padding: 0 16px;
border-radius: 8px;
border-color: ${props => props.theme.colors.themeColorLight};
border-width: 3px;
border-style: solid;
flex-direction: row;
justify-content: space-between;
align-items: center;
`
const Wrapper = styled.View`
flex-direction: row;
justify-content: space-between;
align-items: center;
`
const StyledIconButton = styled(IconButton)<{ $isModalOpen: boolean }>`
width: 40px;
height: 40px;
background-color: ${props =>
props.$isModalOpen ? props.theme.colors.themeColorLight : props.theme.colors.textDisabledColor};
`
const StyledTitle = styled.Text`
background-color: ${props => props.theme.colors.backgroundColor};
position: absolute;
top: -12px;
left: 12px;
right: auto;
padding: 2px 5px;
font-size: 12px;
font-weight: 400;
z-index: 1;
`
const StyledError = styled.Text`
font-size: 12px;
font-weight: bold;
color: ${props => props.theme.colors.invalidInput};
`
export type DatePickerProps = {
title: string
value: DateTime | null
setValue: (fromDate: DateTime | null) => void
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
error?: string
modalState: boolean
setModalState: React.Dispatch<React.SetStateAction<boolean>>
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
}
const DatePicker = ({ title, value, setValue, error, modalState, setModalState }: DatePickerProps): ReactElement => {
const formatDate = (date: DateTime | null, part: number) => date?.toFormat(DATE_FORMAT).split('/')[part]

const [inputDay, setInputDay] = useState(formatDate(value, 0))
const [inputMonth, setInputMonth] = useState(formatDate(value, 1))
const [inputYear, setInputYear] = useState(formatDate(value, 2))
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
try {
setValue(DateTime.fromFormat(`${inputDay}/${inputMonth}/${inputYear}`, DATE_FORMAT).toLocal())
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
setValue(null)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
}, [inputDay, inputMonth, inputYear])

useEffect(() => {
if (value) {
setInputDay(formatDate(value, 0))
setInputMonth(formatDate(value, 1))
setInputYear(formatDate(value, 2))
}
}, [value])
steffenkleinle marked this conversation as resolved.
Show resolved Hide resolved

return (
<DateContainer>
<StyledTitle>{title}</StyledTitle>
<StyledInputWrapper>
<Wrapper>
<Input
testID='DatePicker-day'
keyboardType='numeric'
maxLength={2}
onChangeText={event => {
setInputDay(event as string)
}}
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
value={inputDay}
/>
<Text>/</Text>
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
<Input
testID='DatePicker-month'
keyboardType='numeric'
maxLength={2}
onChangeText={event => {
setInputMonth(event)
}}
value={inputMonth}
/>
<Text>/</Text>
<Input
testID='DatePicker-year'
maxLength={4}
keyboardType='numeric'
onChangeText={event => {
setInputYear(event)
}}
value={inputYear}
/>
</Wrapper>
<StyledIconButton
$isModalOpen={modalState}
icon={<Icon Icon={CalendarTodayIcon} />}
accessibilityLabel='calenderEventsIcon'
onPress={() => {
setModalState(true)
}}
/>
</StyledInputWrapper>
{!!error && <StyledError>{error}</StyledError>}
</DateContainer>
)
}

export default DatePicker
Loading
Loading