Skip to content

Commit

Permalink
[C-2542] Update delete playlist confirmation drawer to conform to new…
Browse files Browse the repository at this point in the history
… designs (#3303)
  • Loading branch information
Kyle-Shanks authored May 2, 2023
1 parent 1ac5ec2 commit 4b639ba
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 17 deletions.
4 changes: 4 additions & 0 deletions packages/mobile/src/assets/images/iconTrash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,39 +1,116 @@
import { useCallback, useMemo } from 'react'
import { useCallback } from 'react'

import {
cacheCollectionsActions,
deletePlaylistConfirmationModalUISelectors
cacheCollectionsSelectors,
deletePlaylistConfirmationModalUISelectors,
fillString
} from '@audius/common'
import { View } from 'react-native'
import { useDispatch, useSelector } from 'react-redux'

import ActionDrawer from 'app/components/action-drawer'
import IconTrash from 'app/assets/images/iconTrash.svg'
import { Text, Button } from 'app/components/core'
import { useNavigation } from 'app/hooks/useNavigation'
import { makeStyles } from 'app/styles'
import { useColor } from 'app/utils/theme'

import { useDrawerState } from '../drawer'
import Drawer from '../drawer/Drawer'
const { getPlaylistId } = deletePlaylistConfirmationModalUISelectors
const { deletePlaylist } = cacheCollectionsActions
const { getCollection } = cacheCollectionsSelectors

const messages = {
drawerTitle: 'Delete Playlist?',
drawerBody: 'Are you sure you want to delete your playlist%0?',
buttonConfirmText: 'Delete',
buttonCancelText: 'Cancel'
}

const useStyles = makeStyles(({ palette, spacing }) => ({
title: {
flexDirection: 'row',
justifyContent: 'center',
gap: spacing(2),
alignItems: 'center',
paddingVertical: spacing(6),
borderBottomColor: palette.neutralLight8,
borderBottomWidth: 1
},
titleText: {
textTransform: 'uppercase'
},
container: {
marginHorizontal: spacing(4)
},
body: {
margin: spacing(4),
lineHeight: spacing(6),
textAlign: 'center'
},
buttonContainer: {
gap: spacing(2),
marginBottom: spacing(8)
}
}))

export const DeletePlaylistConfirmationDrawer = () => {
const playlistId = useSelector(getPlaylistId)
const playlist = useSelector((state) =>
getCollection(state, { id: playlistId })
)
const neutral = useColor('neutral')
const dispatch = useDispatch()
const navigation = useNavigation()
const styles = useStyles()
const { isOpen, onClose } = useDrawerState('DeletePlaylistConfirmation')

const handleDelete = useCallback(() => {
if (playlistId) {
dispatch(deletePlaylist(playlistId))
navigation.goBack()
}
}, [dispatch, playlistId, navigation])

const rows = useMemo(
() => [
{
text: 'Delete',
isDestructive: true,
callback: handleDelete
},
{ text: 'Cancel' }
],
[handleDelete]
)
onClose()
}, [dispatch, playlistId, navigation, onClose])

return <ActionDrawer modalName='DeletePlaylistConfirmation' rows={rows} />
return (
<Drawer isOpen={isOpen} onClose={onClose}>
<View style={styles.container}>
<View style={styles.title}>
<IconTrash fill={neutral} width={24} height={24} />
<Text
weight='heavy'
color='neutral'
fontSize='xl'
style={styles.titleText}
>
{messages.drawerTitle}
</Text>
</View>
<Text style={styles.body} fontSize='large' weight='medium'>
{fillString(
messages.drawerBody,
playlist ? `, ${playlist.playlist_name}` : ''
)}
</Text>
<View style={styles.buttonContainer}>
<Button
title={messages.buttonCancelText}
variant='primary'
size='large'
fullWidth
onPress={onClose}
/>
<Button
title={messages.buttonConfirmText}
variant='common'
size='large'
fullWidth
onPress={handleDelete}
/>
</View>
</View>
</Drawer>
)
}

0 comments on commit 4b639ba

Please sign in to comment.