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

Commit

Permalink
[C-1614] Move creativeCommons to common (#2346)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Dec 5, 2022
1 parent f475daa commit e7294dc
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 29 deletions.
1 change: 1 addition & 0 deletions packages/common/src/models/CreativeCommons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { License } from '../utils/creativeCommons'
6 changes: 3 additions & 3 deletions packages/common/src/models/Track.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -94,7 +94,7 @@ export type TrackMetadata = {
has_current_user_reposted: boolean
has_current_user_saved: boolean
download: Nullable<Download>
license: Nullable<string>
license: Nullable<License>
mood: Nullable<string>
play_count: number
owner_id: ID
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export * from './Tipping'
export * from './Track'
export * from './User'
export * from './Wallet'
export * from './CreativeCommons'
9 changes: 5 additions & 4 deletions packages/common/src/services/audius-api-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -114,7 +115,7 @@ export type APITrack = {
cover_art_sizes: string
download: Download
isrc: Nullable<string>
license: Nullable<string>
license: Nullable<License>
iswc: Nullable<string>
field_visibility: FieldVisibility
followee_reposts: APIRepost[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions packages/common/src/store/pages/track/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<Track & { user: User }> => {
const cachedTrack = getTrack(state)
const parentTrackId = cachedTrack?.remix_of?.tracks?.[0].parent_track_id
if (parentTrackId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions packages/mobile/src/screens/edit-track-screen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { ScreenProps } from 'app/components/core'

export type FormValues = ExtendedTrackMetadata & {
licenseType: {
allowAttribution: boolean
commercialUse: boolean
derivativeWorks: boolean
allowAttribution: Nullable<boolean>
commercialUse: Nullable<boolean>
derivativeWorks: Nullable<boolean>
}
trackArtwork?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { omit } from 'lodash'

/**
* Potentially add
* @param track
*/
const setIsCoSigned = <T extends TrackMetadata>(track: T) => {
const { remix_of } = track
Expand Down
15 changes: 8 additions & 7 deletions packages/web/src/components/data-entry/FormTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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] }))

Expand Down

0 comments on commit e7294dc

Please sign in to comment.