-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…d modal (#3601)
- Loading branch information
1 parent
381cc0c
commit 3810b2f
Showing
21 changed files
with
419 additions
and
16 deletions.
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
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
22 changes: 22 additions & 0 deletions
22
apps/audius-client/packages/common/src/store/ui/duplicate-add-confirmation-modal/sagas.ts
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,22 @@ | ||
import { takeEvery } from 'redux-saga/effects' | ||
import { put } from 'typed-redux-saga' | ||
|
||
import { setVisibility } from '../modals/slice' | ||
|
||
import { open, OpenPayload, requestOpen } from './slice' | ||
|
||
function* handleRequestOpen(action: OpenPayload) { | ||
const { payload } = action | ||
yield* put(open(payload)) | ||
yield* put( | ||
setVisibility({ modal: 'DuplicateAddConfirmation', visible: true }) | ||
) | ||
} | ||
|
||
function* watchHandleRequestOpen() { | ||
yield takeEvery(requestOpen, handleRequestOpen) | ||
} | ||
|
||
export default function sagas() { | ||
return [watchHandleRequestOpen] | ||
} |
7 changes: 7 additions & 0 deletions
7
.../audius-client/packages/common/src/store/ui/duplicate-add-confirmation-modal/selectors.ts
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,7 @@ | ||
import { CommonState } from 'store/commonStore' | ||
|
||
export const getPlaylistId = (state: CommonState) => | ||
state.ui.duplicateAddConfirmationModal.playlistId | ||
|
||
export const getTrackId = (state: CommonState) => | ||
state.ui.duplicateAddConfirmationModal.trackId |
33 changes: 33 additions & 0 deletions
33
apps/audius-client/packages/common/src/store/ui/duplicate-add-confirmation-modal/slice.ts
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,33 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
|
||
import { Nullable } from 'utils/typeUtils' | ||
|
||
import { ID } from '../../../models/Identifiers' | ||
|
||
type DuplicateAddConfirmationState = { | ||
playlistId: Nullable<ID> | ||
trackId: Nullable<ID> | ||
} | ||
|
||
export type OpenPayload = PayloadAction<{ playlistId: ID; trackId: ID }> | ||
|
||
const initialState: DuplicateAddConfirmationState = { | ||
trackId: null, | ||
playlistId: null | ||
} | ||
|
||
const slice = createSlice({ | ||
name: 'applications/ui/duplicateAddConfirmation', | ||
initialState, | ||
reducers: { | ||
requestOpen: (_state, _action: OpenPayload) => {}, | ||
open: (state, action: OpenPayload) => { | ||
state.playlistId = action.payload.playlistId | ||
state.trackId = action.payload.trackId | ||
} | ||
} | ||
}) | ||
|
||
export const { open, requestOpen } = slice.actions | ||
export const actions = slice.actions | ||
export default slice.reducer |
7 changes: 7 additions & 0 deletions
7
apps/audius-client/packages/common/src/store/ui/duplicate-add-confirmation-modal/types.ts
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,7 @@ | ||
import { ID } from '../../../models/Identifiers' | ||
|
||
export type DuplicateAddConfirmationModalState = { | ||
isOpen: boolean | ||
playlistId: ID | null | ||
trackId: ID | null | ||
} |
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
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
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
114 changes: 114 additions & 0 deletions
114
...obile/src/components/duplicate-add-confirmation-drawer/DuplicateAddConfirmationDrawer.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,114 @@ | ||
import { useCallback } from 'react' | ||
|
||
import { | ||
cacheCollectionsActions, | ||
cacheCollectionsSelectors, | ||
duplicateAddConfirmationModalUISelectors, | ||
fillString | ||
} from '@audius/common' | ||
import { View } from 'react-native' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
|
||
import { Text, Button } from 'app/components/core' | ||
import { useToast } from 'app/hooks/useToast' | ||
import { makeStyles } from 'app/styles' | ||
|
||
import { useDrawerState } from '../drawer' | ||
import Drawer from '../drawer/Drawer' | ||
const { getPlaylistId, getTrackId } = duplicateAddConfirmationModalUISelectors | ||
const { addTrackToPlaylist } = cacheCollectionsActions | ||
const { getCollection } = cacheCollectionsSelectors | ||
|
||
const messages = { | ||
drawerTitle: 'Already Added', | ||
drawerBody: 'This is already in your%0 playlist.', | ||
buttonAddText: 'Add Anyway', | ||
buttonCancelText: "Don't Add", | ||
addedToast: 'Added To Playlist!' | ||
} | ||
|
||
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 DuplicateAddConfirmationDrawer = () => { | ||
const playlistId = useSelector(getPlaylistId) | ||
const trackId = useSelector(getTrackId) | ||
const playlist = useSelector((state) => | ||
getCollection(state, { id: playlistId }) | ||
) | ||
const dispatch = useDispatch() | ||
const styles = useStyles() | ||
const { toast } = useToast() | ||
const { isOpen, onClose } = useDrawerState('DuplicateAddConfirmation') | ||
|
||
const handleAdd = useCallback(() => { | ||
if (playlistId && trackId) { | ||
toast({ content: messages.addedToast }) | ||
dispatch(addTrackToPlaylist(trackId, playlistId)) | ||
} | ||
onClose() | ||
}, [playlistId, trackId, onClose, toast, dispatch]) | ||
|
||
return ( | ||
<Drawer isOpen={isOpen} onClose={onClose}> | ||
<View style={styles.container}> | ||
<View style={styles.title}> | ||
<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.buttonAddText} | ||
variant='common' | ||
size='large' | ||
fullWidth | ||
onPress={handleAdd} | ||
/> | ||
</View> | ||
</View> | ||
</Drawer> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
apps/audius-client/packages/mobile/src/components/duplicate-add-confirmation-drawer/index.ts
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 @@ | ||
export * from './DuplicateAddConfirmationDrawer' |
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
Oops, something went wrong.