This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
[C-1452] Implement release-date field #2246
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/mobile/src/screens/upload-screen/fields/ReleaseDateField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { useCallback, useMemo, useState } from 'react' | ||
|
||
import type { Nullable } from '@audius/common' | ||
import { Theme } from '@audius/common' | ||
import { useField } from 'formik' | ||
import moment from 'moment' | ||
import { TouchableOpacity } from 'react-native-gesture-handler' | ||
import type { | ||
CustomCancelButtonPropTypes, | ||
CustomConfirmButtonPropTypes | ||
} from 'react-native-modal-datetime-picker' | ||
import DateTimePickerModal from 'react-native-modal-datetime-picker' | ||
|
||
import { Button, Pill, Text } from 'app/components/core' | ||
import { makeStyles } from 'app/styles' | ||
import { useThemeColors, useThemeVariant } from 'app/utils/theme' | ||
|
||
const isToday = (date: Date) => moment(date).isSame(moment(), 'day') | ||
|
||
const messages = { | ||
label: 'Release Date', | ||
today: 'Today' | ||
} | ||
|
||
const useStyles = makeStyles(({ spacing }) => ({ | ||
root: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
paddingHorizontal: spacing(2), | ||
paddingTop: spacing(2), | ||
paddingBottom: spacing(4) | ||
}, | ||
label: { | ||
marginTop: spacing(1) | ||
}, | ||
dateText: { | ||
marignTop: spacing(1), | ||
textTransform: 'uppercase' | ||
}, | ||
datePickerModal: { | ||
// Specific padding to hide the underlying "done" button with the "cancel" button | ||
paddingBottom: 37 | ||
} | ||
})) | ||
|
||
const ConfirmDateButton = (props: CustomConfirmButtonPropTypes) => { | ||
const { label, onPress } = props | ||
return ( | ||
<Button | ||
style={{ borderRadius: 0 }} | ||
variant='primary' | ||
size='large' | ||
title={label} | ||
fullWidth | ||
onPress={onPress} | ||
pressScale={1} | ||
/> | ||
) | ||
} | ||
|
||
const CancelDateButton = (props: CustomCancelButtonPropTypes) => { | ||
const { label, onPress } = props | ||
return ( | ||
<Button | ||
variant='commonAlt' | ||
size='large' | ||
title={label} | ||
fullWidth | ||
onPress={onPress} | ||
/> | ||
) | ||
} | ||
|
||
export const ReleaseDateField = () => { | ||
const styles = useStyles() | ||
const [{ value, onChange }] = useField<Nullable<string>>('release_date') | ||
const [isOpen, setIsOpen] = useState(false) | ||
const { primary } = useThemeColors() | ||
const theme = useThemeVariant() | ||
|
||
const releaseDate = useMemo( | ||
() => (value ? new Date(value) : new Date()), | ||
[value] | ||
) | ||
|
||
const handlePress = useCallback(() => { | ||
setIsOpen(true) | ||
}, []) | ||
|
||
const handleClose = useCallback(() => { | ||
setIsOpen(false) | ||
}, []) | ||
|
||
const handleChange = useCallback( | ||
(selectedDate: Date) => { | ||
const dateString = moment(selectedDate).toString() | ||
if (dateString) { | ||
onChange('release_date')(dateString) | ||
} | ||
handleClose() | ||
}, | ||
[onChange, handleClose] | ||
) | ||
|
||
return ( | ||
<> | ||
<TouchableOpacity style={styles.root} onPress={handlePress}> | ||
<Text fontSize='large' weight='demiBold' style={styles.label}> | ||
{messages.label} | ||
</Text> | ||
<Pill> | ||
<Text fontSize='small' weight='demiBold' style={styles.dateText}> | ||
{isToday(releaseDate) | ||
? messages.today | ||
: moment(releaseDate).format('MM/DD/YY')} | ||
</Text> | ||
</Pill> | ||
</TouchableOpacity> | ||
<DateTimePickerModal | ||
isVisible={isOpen} | ||
date={releaseDate} | ||
mode='date' | ||
onConfirm={handleChange} | ||
onCancel={handleClose} | ||
display='inline' | ||
themeVariant={theme === Theme.DEFAULT ? 'light' : 'dark'} | ||
isDarkModeEnabled={theme !== Theme.DEFAULT} | ||
accentColor={primary} | ||
maximumDate={new Date()} | ||
modalStyleIOS={styles.datePickerModal} | ||
customConfirmButtonIOS={ConfirmDateButton} | ||
customCancelButtonIOS={CancelDateButton} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
root
feels slightly misleadingmaybe best fixed by moving the divider up a level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good call