Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

[C-1452] Implement release-date field #2246

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions packages/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ PODS:
- React-Core
- RNCPushNotificationIOS (1.10.1):
- React-Core
- RNDateTimePicker (6.5.4):
- React-Core
- RNFBAnalytics (14.5.1):
- Firebase/Analytics (= 8.12.1)
- React-Core
Expand Down Expand Up @@ -557,6 +559,7 @@ DEPENDENCIES:
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
- "RNCMaskedView (from `../node_modules/@react-native-masked-view/masked-view`)"
- "RNCPushNotificationIOS (from `../node_modules/@react-native-community/push-notification-ios`)"
- "RNDateTimePicker (from `../node_modules/@react-native-community/datetimepicker`)"
- "RNFBAnalytics (from `../node_modules/@react-native-firebase/analytics`)"
- "RNFBApp (from `../node_modules/@react-native-firebase/app`)"
- "RNFBCrashlytics (from `../node_modules/@react-native-firebase/crashlytics`)"
Expand Down Expand Up @@ -710,6 +713,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-masked-view/masked-view"
RNCPushNotificationIOS:
:path: "../node_modules/@react-native-community/push-notification-ios"
RNDateTimePicker:
:path: "../node_modules/@react-native-community/datetimepicker"
RNFBAnalytics:
:path: "../node_modules/@react-native-firebase/analytics"
RNFBApp:
Expand Down Expand Up @@ -818,6 +823,7 @@ SPEC CHECKSUMS:
RNCClipboard: f49f3de56b40d0f4104680dabadc7a1f063f4fd4
RNCMaskedView: 1f6cd0cb5e38ec01960e12fd8f95ecad809f8fbb
RNCPushNotificationIOS: 089da3b657e1e3d464f38195fd2e3069608ef5af
RNDateTimePicker: 41bf71ec9c20cfe7762eb93b2c26ad2bdb4fc2e6
RNFBAnalytics: 74cd9c60531ed33e5347b2dccafa172ae1a851a4
RNFBApp: 5bae3002117e55f3c9aa0fb38175dd16c8046c90
RNFBCrashlytics: 33615211c6c6c4039ae71849091f6ac38ab65aba
Expand Down
18 changes: 17 additions & 1 deletion packages/mobile/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@react-native-async-storage/async-storage": "1.15.14",
"@react-native-clipboard/clipboard": "1.9.0",
"@react-native-community/blur": "3.6.0",
"@react-native-community/datetimepicker": "^6.5.4",
"@react-native-community/hooks": "2.8.1",
"@react-native-community/netinfo": "9.3.0",
"@react-native-community/push-notification-ios": "1.10.1",
Expand Down Expand Up @@ -102,6 +103,7 @@
"react-native-linear-gradient": "github:react-native-linear-gradient/react-native-linear-gradient.git#9aece37cdf7d33ed52a1747b36e9e84f3c7a49ef",
"react-native-markdown-display": "7.0.0-alpha.2",
"react-native-modal": "11.5.4",
"react-native-modal-datetime-picker": "^14.0.0",
"react-native-music-control": "1.4.0",
"react-native-pager-view": "5.4.6",
"react-native-permissions": "3.0.5",
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/src/components/core/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export type ButtonProps = Omit<RNButtonProps, 'title'> &
url?: string
corners?: 'rounded' | 'pill'
title: ReactNode
pressScale?: number
}

export const Button = (props: ButtonProps) => {
Expand All @@ -241,6 +242,7 @@ export const Button = (props: ButtonProps) => {
url,
corners = 'rounded',
disabled,
pressScale = 0.97,
...other
} = props
const [isPressing, setIsPressing] = useState(false)
Expand All @@ -254,7 +256,7 @@ export const Button = (props: ButtonProps) => {
scale,
handlePressIn: handlePressInScale,
handlePressOut: handlePressOutScale
} = usePressScaleAnimation(0.97, false)
} = usePressScaleAnimation(pressScale, false)

const { primaryDark1, neutralLight10, neutralLight7, accentRedDark1 } =
useThemeColors()
Expand Down
137 changes: 137 additions & 0 deletions packages/mobile/src/screens/upload-screen/fields/ReleaseDateField.tsx
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}>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: root feels slightly misleading

maybe best fixed by moving the divider up a level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good call

<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}
/>
</>
)
}
1 change: 1 addition & 0 deletions packages/mobile/src/screens/upload-screen/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './RemixSettingsField'
export * from './AdvancedOptionsField'
export * from './TrackVisibilityField'
export * from './SwitchField'
export * from './ReleaseDateField'
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { View } from 'react-native'

import IconIndent from 'app/assets/images/iconIndent.svg'
import { makeStyles } from 'app/styles'

import { UploadStackScreen } from '../UploadStackScreen'
import { SubmenuList, TrackVisibilityField } from '../fields'
import { ReleaseDateField, SubmenuList, TrackVisibilityField } from '../fields'

const useStyles = makeStyles(({ spacing }) => ({
content: {
Expand All @@ -24,9 +26,12 @@ export const AdvancedOptionsScreen = () => {
bottomSection={null}
variant='white'
>
<SubmenuList style={styles.content}>
<TrackVisibilityField />
</SubmenuList>
<View style={styles.content}>
<SubmenuList>
<TrackVisibilityField />
</SubmenuList>
<ReleaseDateField />
</View>
</UploadStackScreen>
)
}