diff --git a/packages/common/src/models/CreativeCommons.ts b/packages/common/src/models/CreativeCommons.ts new file mode 100644 index 0000000000..f9529dffb7 --- /dev/null +++ b/packages/common/src/models/CreativeCommons.ts @@ -0,0 +1 @@ +export type { License } from '../utils/creativeCommons' diff --git a/packages/common/src/models/Track.ts b/packages/common/src/models/Track.ts index 2eab7dcfbf..4bc13affc6 100644 --- a/packages/common/src/models/Track.ts +++ b/packages/common/src/models/Track.ts @@ -1,7 +1,7 @@ -import { Chain } from 'models' - import { Nullable } from '../utils/typeUtils' +import { Chain } from './Chain' +import type { License } from './CreativeCommons' import { Favorite } from './Favorite' import { CID, ID, UID } from './Identifiers' import { CoverArtSizes } from './ImageSizes' @@ -94,7 +94,7 @@ export type TrackMetadata = { has_current_user_reposted: boolean has_current_user_saved: boolean download: Nullable - license: Nullable + license: Nullable mood: Nullable play_count: number owner_id: ID diff --git a/packages/common/src/models/index.ts b/packages/common/src/models/index.ts index 90bdefcf12..bf14ed42d5 100644 --- a/packages/common/src/models/index.ts +++ b/packages/common/src/models/index.ts @@ -32,3 +32,4 @@ export * from './Tipping' export * from './Track' export * from './User' export * from './Wallet' +export * from './CreativeCommons' diff --git a/packages/common/src/services/audius-api-client/types.ts b/packages/common/src/services/audius-api-client/types.ts index bf6c225e88..1bd98ee488 100644 --- a/packages/common/src/services/audius-api-client/types.ts +++ b/packages/common/src/services/audius-api-client/types.ts @@ -15,9 +15,10 @@ import { UserTip, PremiumConditions, PremiumContentSignature, - ID -} from 'models' -import { Nullable } from 'utils' + ID, + License +} from '../../models' +import { Nullable } from '../../utils' export type OpaqueID = string @@ -114,7 +115,7 @@ export type APITrack = { cover_art_sizes: string download: Download isrc: Nullable - license: Nullable + license: Nullable iswc: Nullable field_visibility: FieldVisibility followee_reposts: APIRepost[] diff --git a/packages/common/src/services/audius-backend/AudiusBackend.ts b/packages/common/src/services/audius-backend/AudiusBackend.ts index b262c0b11a..f2f2a89112 100644 --- a/packages/common/src/services/audius-backend/AudiusBackend.ts +++ b/packages/common/src/services/audius-backend/AudiusBackend.ts @@ -524,7 +524,7 @@ export const audiusBackend = ({ } } - function getTrackImages(track: TrackMetadata) { + function getTrackImages(track: TrackMetadata): Track { const coverArtSizes: CoverArtSizes = {} if (!track.cover_art_sizes && !track.cover_art) { coverArtSizes[DefaultSizes.OVERRIDE] = placeholderCoverArt as string diff --git a/packages/common/src/store/pages/track/selectors.ts b/packages/common/src/store/pages/track/selectors.ts index 5ac83a199c..3a9f74837c 100644 --- a/packages/common/src/store/pages/track/selectors.ts +++ b/packages/common/src/store/pages/track/selectors.ts @@ -6,7 +6,8 @@ import { getUser as getCachedUser } from 'store/cache/users/selectors' import { CommonState } from 'store/commonStore' import { PREFIX } from 'store/pages/track/lineup/actions' -import { ID } from '../../../models' +import { ID, Track, User } from '../../../models' +import { Nullable } from '../../../utils/typeUtils' export const getBaseState = (state: CommonState) => state.pages.track @@ -26,7 +27,9 @@ export const getTrack = (state: CommonState, params?: { id?: ID }) => { return getCachedTrack(state, { permalink }) } -export const getRemixParentTrack = (state: CommonState) => { +export const getRemixParentTrack = ( + state: CommonState +): Nullable => { const cachedTrack = getTrack(state) const parentTrackId = cachedTrack?.remix_of?.tracks?.[0].parent_track_id if (parentTrackId) { diff --git a/packages/web/src/utils/creativeCommons.ts b/packages/common/src/utils/creativeCommons.ts similarity index 98% rename from packages/web/src/utils/creativeCommons.ts rename to packages/common/src/utils/creativeCommons.ts index 1aba646d76..5ea83ced50 100644 --- a/packages/web/src/utils/creativeCommons.ts +++ b/packages/common/src/utils/creativeCommons.ts @@ -1,4 +1,4 @@ -import { Nullable } from '@audius/common' +import { Nullable } from './typeUtils' export const ALL_RIGHTS_RESERVED_TYPE = 'All rights reserved' const ALL_RIGHTS_RESERVED_DESC = '' @@ -53,7 +53,7 @@ const ALL_LICENSES = { [BY_SA_TYPE]: BY_SA_DESC } -type License = keyof typeof ALL_LICENSES +export type License = keyof typeof ALL_LICENSES /** * Computes the Create Commons License for provided attribution, commercial use, and derivative works flags. diff --git a/packages/common/src/utils/index.ts b/packages/common/src/utils/index.ts index af21cd7d24..bbe2f58f22 100644 --- a/packages/common/src/utils/index.ts +++ b/packages/common/src/utils/index.ts @@ -19,3 +19,5 @@ export * from './fileUtils' export * from './constants' export * from './paramsToQueryString' export * from './challenges' +export * as creativeCommons from './creativeCommons' +export { License } from './creativeCommons' diff --git a/packages/mobile/src/screens/edit-track-screen/EditTrackScreen.tsx b/packages/mobile/src/screens/edit-track-screen/EditTrackScreen.tsx index b7353590af..8809f36845 100644 --- a/packages/mobile/src/screens/edit-track-screen/EditTrackScreen.tsx +++ b/packages/mobile/src/screens/edit-track-screen/EditTrackScreen.tsx @@ -1,11 +1,13 @@ import { useCallback } from 'react' import type { UploadTrack } from '@audius/common' +import { creativeCommons } from '@audius/common' import { Formik } from 'formik' import * as Yup from 'yup' import { EditTrackNavigator } from './EditTrackNavigator' import type { FormValues, EditTrackScreenProps } from './types' +const { computeLicenseVariables, ALL_RIGHTS_RESERVED_TYPE } = creativeCommons const EditTrackSchema = Yup.object().shape({ title: Yup.string().required('Required'), @@ -29,11 +31,9 @@ export const EditTrackScreen = (props: EditTrackScreenProps) => { const initialValues: FormValues = { ...initialValuesProp, - licenseType: { - allowAttribution: false, - commercialUse: false, - derivativeWorks: false - } + licenseType: computeLicenseVariables( + initialValuesProp.license || ALL_RIGHTS_RESERVED_TYPE + ) } const handleSubmit = useCallback( diff --git a/packages/mobile/src/screens/edit-track-screen/screens/LicenseTypeScreen.tsx b/packages/mobile/src/screens/edit-track-screen/screens/LicenseTypeScreen.tsx index b1ecda7d6f..10f07804ce 100644 --- a/packages/mobile/src/screens/edit-track-screen/screens/LicenseTypeScreen.tsx +++ b/packages/mobile/src/screens/edit-track-screen/screens/LicenseTypeScreen.tsx @@ -1,9 +1,9 @@ import { useEffect } from 'react' import type { Nullable } from '@audius/common' +import { creativeCommons } from '@audius/common' import { useField } from 'formik' import { ScrollView, View } from 'react-native' -import { computeLicense } from 'utils/creativeCommons' import IconCreativeCommons from 'app/assets/images/creativeCommons/cc.svg' import type { TextProps } from 'app/components/core' @@ -14,6 +14,7 @@ import { useThemeColors } from 'app/utils/theme' import { FormScreen } from '../components' import { computeLicenseIcons } from '../utils/computeLicenseIcons' +const { computeLicense } = creativeCommons const messages = { title: 'License Type', diff --git a/packages/mobile/src/screens/edit-track-screen/types.ts b/packages/mobile/src/screens/edit-track-screen/types.ts index 75f6fc57d1..1b87cc7322 100644 --- a/packages/mobile/src/screens/edit-track-screen/types.ts +++ b/packages/mobile/src/screens/edit-track-screen/types.ts @@ -5,9 +5,9 @@ import type { ScreenProps } from 'app/components/core' export type FormValues = ExtendedTrackMetadata & { licenseType: { - allowAttribution: boolean - commercialUse: boolean - derivativeWorks: boolean + allowAttribution: Nullable + commercialUse: Nullable + derivativeWorks: Nullable } trackArtwork?: string } diff --git a/packages/web/src/common/store/cache/tracks/utils/reformat.ts b/packages/web/src/common/store/cache/tracks/utils/reformat.ts index 979d5e3a9d..b47084cc42 100644 --- a/packages/web/src/common/store/cache/tracks/utils/reformat.ts +++ b/packages/web/src/common/store/cache/tracks/utils/reformat.ts @@ -3,7 +3,6 @@ import { omit } from 'lodash' /** * Potentially add - * @param track */ const setIsCoSigned = (track: T) => { const { remix_of } = track diff --git a/packages/web/src/components/data-entry/FormTile.js b/packages/web/src/components/data-entry/FormTile.js index b536624b07..0eb5cb5c7f 100644 --- a/packages/web/src/components/data-entry/FormTile.js +++ b/packages/web/src/components/data-entry/FormTile.js @@ -4,7 +4,8 @@ import { GENRES, ELECTRONIC_PREFIX, getCanonicalName, - createRemixOfMetadata + createRemixOfMetadata, + creativeCommons } from '@audius/common' import { Button, ButtonType, IconDownload, IconIndent } from '@audius/stems' import cn from 'classnames' @@ -25,16 +26,16 @@ import Switch from 'components/switch/Switch' import UnlistedTrackModal from 'components/unlisted-track-modal/UnlistedTrackModal' import PreviewButton from 'components/upload/PreviewButton' import UploadArtwork from 'components/upload/UploadArtwork' -import { - ALL_RIGHTS_RESERVED_TYPE, - computeLicense, - computeLicenseVariables, - getDescriptionForType -} from 'utils/creativeCommons' import { resizeImage } from 'utils/imageProcessingUtil' import { moodMap } from 'utils/moods' import styles from './FormTile.module.css' +const { + ALL_RIGHTS_RESERVED_TYPE, + computeLicense, + computeLicenseVariables, + getDescriptionForType +} = creativeCommons const MOODS = Object.keys(moodMap).map((k) => ({ text: k, el: moodMap[k] }))