-
Notifications
You must be signed in to change notification settings - Fork 106
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
- Loading branch information
1 parent
1c7ec6f
commit bae86c3
Showing
16 changed files
with
488 additions
and
48 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
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,13 @@ | ||
import { Switch, SwitchProps } from '@audius/stems' | ||
import { useField } from 'formik' | ||
|
||
type SwitchFieldProps = SwitchProps & { | ||
name: string | ||
} | ||
|
||
export const SwitchField = (props: SwitchFieldProps) => { | ||
const { name, ...other } = props | ||
const [field] = useField({ name, type: 'checkbox' }) | ||
|
||
return <Switch {...field} {...other} /> | ||
} |
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
27 changes: 27 additions & 0 deletions
27
packages/web/src/pages/upload-page/fields/SelectGenreField.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,27 @@ | ||
import { GENRES } from '@audius/common' | ||
|
||
import { DropdownField, DropdownFieldProps } from 'components/form-fields' | ||
|
||
const messages = { | ||
genre: 'Pick a Genre' | ||
} | ||
|
||
type SelectGenreFieldProps = Partial<DropdownFieldProps> & { | ||
name: string | ||
} | ||
|
||
const menu = { items: GENRES } | ||
|
||
export const SelectGenreField = (props: SelectGenreFieldProps) => { | ||
return ( | ||
<DropdownField | ||
aria-label={messages.genre} | ||
placeholder={messages.genre} | ||
mount='parent' | ||
// TODO: Use correct value for Genres based on label (see `convertGenreLabelToValue`) | ||
menu={menu} | ||
size='large' | ||
{...props} | ||
/> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/web/src/pages/upload-page/fields/SelectMoodField.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,30 @@ | ||
import { DropdownField, DropdownFieldProps } from 'components/form-fields' | ||
import { moodMap } from 'utils/Moods' | ||
|
||
const MOODS = Object.keys(moodMap).map((k) => ({ | ||
text: k, | ||
el: moodMap[k] | ||
})) | ||
|
||
const menu = { items: MOODS } | ||
|
||
const messages = { | ||
mood: 'Pick a Mood' | ||
} | ||
|
||
type SelectMoodFieldProps = Partial<DropdownFieldProps> & { | ||
name: string | ||
} | ||
|
||
export const SelectMoodField = (props: SelectMoodFieldProps) => { | ||
return ( | ||
<DropdownField | ||
aria-label={messages.mood} | ||
placeholder={messages.mood} | ||
mount='parent' | ||
menu={menu} | ||
size='large' | ||
{...props} | ||
/> | ||
) | ||
} |
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
15 changes: 15 additions & 0 deletions
15
packages/web/src/pages/upload-page/fields/TrackNameField.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,15 @@ | ||
import { TextField, TextFieldProps } from 'components/form-fields' | ||
|
||
const messages = { | ||
trackName: 'Track Name' | ||
} | ||
|
||
type TrackNameFieldProps = Partial<TextFieldProps> & { | ||
name: string | ||
} | ||
|
||
export const TrackNameField = (props: TrackNameFieldProps) => { | ||
return ( | ||
<TextField label={messages.trackName} maxLength={64} required {...props} /> | ||
) | ||
} |
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
111 changes: 111 additions & 0 deletions
111
packages/web/src/pages/upload-page/pages/CollectionTrackField.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,111 @@ | ||
import { useCallback, useEffect } from 'react' | ||
|
||
import { | ||
HarmonyButton, | ||
HarmonyButtonSize, | ||
HarmonyButtonType, | ||
IconDrag, | ||
IconPlay, | ||
IconTrash | ||
} from '@audius/stems' | ||
import { useField } from 'formik' | ||
|
||
import { Icon } from 'components/Icon' | ||
import { TagField } from 'components/form-fields' | ||
import { SwitchField } from 'components/form-fields/SwitchField' | ||
import { Tile } from 'components/tile' | ||
import { Text } from 'components/typography' | ||
|
||
import { SelectGenreField } from '../fields/SelectGenreField' | ||
import { SelectMoodField } from '../fields/SelectMoodField' | ||
import { TrackNameField } from '../fields/TrackNameField' | ||
import { CollectionTrackForUpload } from '../types' | ||
|
||
import styles from './UploadCollectionForm.module.css' | ||
|
||
const messages = { | ||
overrideLabel: 'Override details for this track', | ||
preview: 'Preview', | ||
delete: 'Delete' | ||
} | ||
|
||
type CollectionTrackFieldProps = { | ||
index: number | ||
remove: (index: number) => void | ||
} | ||
|
||
export const CollectionTrackField = (props: CollectionTrackFieldProps) => { | ||
const { index, remove } = props | ||
const [{ value: track }] = useField<CollectionTrackForUpload>( | ||
`tracks.${index}` | ||
) | ||
|
||
const [{ value: metadata }, , { setValue }] = useField< | ||
CollectionTrackForUpload['metadata'] | ||
>(`tracks.${index}.metadata`) | ||
|
||
const [{ value }] = useField('trackDetails') | ||
|
||
const { override } = track | ||
|
||
useEffect(() => { | ||
if (override) { | ||
setValue({ ...metadata, ...value }) | ||
} else { | ||
setValue({ ...metadata, genre: '', mood: null, tags: null }) | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [override]) | ||
|
||
const handleRemove = useCallback(() => { | ||
remove(index) | ||
}, [remove, index]) | ||
|
||
return ( | ||
<Tile | ||
className={styles.trackField} | ||
key={track.metadata.track_id} | ||
elevation='mid' | ||
> | ||
<div className={styles.trackNameRow}> | ||
<span className={styles.iconDrag}> | ||
<Icon icon={IconDrag} size='large' /> | ||
</span> | ||
<Text size='small' className={styles.trackindex}> | ||
{index} | ||
</Text> | ||
<TrackNameField name={`tracks.${index}.metadata.title`} /> | ||
</div> | ||
{override ? ( | ||
<div className={styles.trackInformation}> | ||
<div className={styles.genreMood}> | ||
<SelectGenreField name={`tracks.${index}.metadata.genre`} /> | ||
<SelectMoodField name={`tracks.${index}.metadata.mood`} /> | ||
</div> | ||
<TagField name={`tracks.${index}.metadata.tags`} /> | ||
</div> | ||
) : null} | ||
<div className={styles.overrideRow}> | ||
<div className={styles.overrideSwitch}> | ||
<SwitchField name={`tracks.${index}.override`} /> | ||
<Text>{messages.overrideLabel}</Text> | ||
</div> | ||
<div className={styles.actions}> | ||
<HarmonyButton | ||
variant={HarmonyButtonType.GHOST} | ||
size={HarmonyButtonSize.SMALL} | ||
text={messages.preview} | ||
iconLeft={IconPlay} | ||
/> | ||
<HarmonyButton | ||
variant={HarmonyButtonType.GHOST} | ||
size={HarmonyButtonSize.SMALL} | ||
text={messages.delete} | ||
iconLeft={IconTrash} | ||
onClick={handleRemove} | ||
/> | ||
</div> | ||
</div> | ||
</Tile> | ||
) | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/web/src/pages/upload-page/pages/CollectionTrackFieldArray.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,49 @@ | ||
import { FieldArray, useField } from 'formik' | ||
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd' | ||
|
||
import { CollectionTrackForUpload } from '../types' | ||
|
||
import { CollectionTrackField } from './CollectionTrackField' | ||
|
||
export const CollectionTrackFieldArray = () => { | ||
const [{ value: tracks }] = useField<CollectionTrackForUpload[]>('tracks') | ||
|
||
return ( | ||
<FieldArray name='tracks'> | ||
{({ move, remove }) => ( | ||
<DragDropContext | ||
onDragEnd={(result) => { | ||
if (!result.destination) { | ||
return | ||
} | ||
move(result.source.index, result.destination.index) | ||
}} | ||
> | ||
<Droppable droppableId='tracks'> | ||
{(provided, snapshot) => ( | ||
<div {...provided.droppableProps} ref={provided.innerRef}> | ||
{tracks.map((track, index) => ( | ||
<Draggable | ||
key={track.metadata.title} | ||
draggableId={track.metadata.title} | ||
index={index} | ||
> | ||
{(provided, snapshot) => ( | ||
<div | ||
ref={provided.innerRef} | ||
{...provided.draggableProps} | ||
{...provided.dragHandleProps} | ||
> | ||
<CollectionTrackField index={index} remove={remove} /> | ||
</div> | ||
)} | ||
</Draggable> | ||
))} | ||
</div> | ||
)} | ||
</Droppable> | ||
</DragDropContext> | ||
)} | ||
</FieldArray> | ||
) | ||
} |
Oops, something went wrong.