Skip to content

Commit

Permalink
[C-1750] Refactor top tags (#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers committed Apr 6, 2023
1 parent b5485bd commit 29117e7
Show file tree
Hide file tree
Showing 37 changed files with 437 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const ENDPOINT_MAP = {
associatedWalletUserId: '/users/id',
userChallenges: (userId: OpaqueID) => `/users/${userId}/challenges`,
userFavorites: (userId: OpaqueID) => `/users/${userId}/favorites`,
userTags: (userId: OpaqueID) => `/users/${userId}/tags`,
undisbursedUserChallenges: `/challenges/undisbursed`
}

Expand Down Expand Up @@ -1442,6 +1443,16 @@ export class AudiusAPIClient {
return challenges
}

getUserTags = async ({ userId }: { userId: ID }) => {
const encodedUserId = encodeHashId(userId)
return await this._getResponse<APIResponse<string[]>>(
ENDPOINT_MAP.userTags(encodedUserId),
undefined,
false,
PathType.VersionPath
)
}

getUndisbursedUserChallenges = async ({ userID }: { userID: ID }) => {
this._assertInitialized()
const encodedCurrentUserId = encodeHashId(userID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ export const audiusBackend = ({
validTypes?: string[]
}) {
await waitForLibsInit()
const account = audiusLibs.Account.getCurrentUser()
const account = audiusLibs.Account?.getCurrentUser()
if (!account)
return {
message: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const FETCH_FOLLOW_USERS_FAILED = 'PROFILE/FETCH_FOLLOW_USERS_FAILED'

export const DISMISS_PROFILE_METER = 'PROFILE/DISMISS_PROFILE_METER'

export const UPDATE_MOST_USED_TAGS = 'PROFILE/UPDATE_MOST_USED_TAGS'
export const FETCH_TOP_TAGS = 'PROFILE/FETCH_TOP_TAGS'
export const FETCH_TOP_TAGS_SUCCEEDED = 'PROFILE/FETCH_TOP_TAGS_SUCCEEDED'
export const FETCH_TOP_TAGS_FAILED = 'PROFILE/FETCH_TOP_TAGS_FAILED'
export const SET_NOTIFICATION_SUBSCRIPTION =
'PROFILE/SET_NOTIFICATION_SUBSCRIPTION'

Expand Down Expand Up @@ -142,10 +144,6 @@ export function profileMeterDismissed() {
return { type: DISMISS_PROFILE_METER }
}

export function updateMostUsedTags(mostUsedTags: string[]) {
return { type: UPDATE_MOST_USED_TAGS, mostUsedTags }
}

export function setNotificationSubscription(
userId: ID,
isSubscribed: boolean,
Expand Down Expand Up @@ -183,3 +181,26 @@ export function fetchCollectionsFailed(handle: string) {
handle
}
}

export function fetchTopTags(handle: string, userId: ID) {
return {
type: FETCH_TOP_TAGS,
handle,
userId
}
}

export function fetchTopTagsSucceeded(handle: string, topTags: string[]) {
return {
type: FETCH_TOP_TAGS_SUCCEEDED,
handle,
topTags
}
}

export function fetchTopTagsFailed(handle: string) {
return {
type: FETCH_TOP_TAGS_FAILED,
handle
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import {
FETCH_FOLLOW_USERS_SUCCEEDED,
FETCH_FOLLOW_USERS_FAILED,
DISMISS_PROFILE_METER,
UPDATE_MOST_USED_TAGS,
SET_NOTIFICATION_SUBSCRIPTION,
SET_CURRENT_USER,
FETCH_COLLECTIONS,
FETCH_COLLECTIONS_SUCCEEDED,
FETCH_COLLECTIONS_FAILED
FETCH_COLLECTIONS_FAILED,
FETCH_TOP_TAGS,
FETCH_TOP_TAGS_SUCCEEDED,
FETCH_TOP_TAGS_FAILED
} from './actions'
import { PREFIX as feedPrefix } from './lineups/feed/actions'
import { PREFIX as tracksPrefix } from './lineups/tracks/actions'
Expand All @@ -44,7 +46,8 @@ const initialProfileState = {
updating: false,
updateSuccess: false,
updateError: false,
mostUsedTags: [],
topTagsStatus: Status.IDLE,
topTags: [],
collectionStatus: Status.IDLE,

collectionSortMode: CollectionSortMode.TIMESTAMP,
Expand Down Expand Up @@ -192,10 +195,6 @@ const actionsMap = {
[FETCH_PROFILE_FAILED](state, action) {
return updateProfile(state, action, { status: Status.ERROR })
},
[UPDATE_MOST_USED_TAGS](state, action) {
const { mostUsedTags } = action
return updateProfile(state, action, { mostUsedTags })
},
[UPDATE_PROFILE](state, action) {
return updateProfile(state, action, {
updating: true,
Expand Down Expand Up @@ -237,6 +236,19 @@ const actionsMap = {
},
[FETCH_COLLECTIONS_FAILED](state, action) {
return updateProfile(state, action, { collectionStatus: Status.ERROR })
},
[FETCH_TOP_TAGS](state, action) {
return updateProfile(state, action, { topTagsStatus: Status.LOADING })
},
[FETCH_TOP_TAGS_SUCCEEDED](state, action) {
const { topTags } = action
return updateProfile(state, action, {
topTagsStatus: Status.SUCCESS,
topTags
})
},
[FETCH_TOP_TAGS_FAILED](state, action) {
return updateProfile(state, action, { topTagsStatus: Status.ERROR })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const getProfileUserId = (state: CommonState, handle?: string) =>
getProfile(state, handle)?.userId
export const getProfileUserHandle = (state: CommonState) =>
state.pages.profile.currentUser
export const getProfileMostUsedTags = (state: CommonState, handle?: string) =>
getProfile(state, handle)?.mostUsedTags ?? ([] as string[])
export const getProfileCollectionSortMode = (
state: CommonState,
handle: string
Expand Down Expand Up @@ -73,6 +71,12 @@ export const getProfileFeedLineup = (state: CommonState, handle?: string) =>
export const getProfileTracksLineup = (state: CommonState, handle?: string) =>
getProfile(state, handle)?.tracks ?? initialTracksState

export const getTopTagsStatus = (state: CommonState, handle: string) =>
getProfile(state, handle)?.topTagsStatus

export const getTopTags = (state: CommonState, handle: string) =>
getProfile(state, handle)?.topTags

export const getProfileCollections = createDeepEqualSelector(
[
(state: CommonState, handle: string) => getProfileUserId(state, handle),
Expand Down Expand Up @@ -120,7 +124,6 @@ export const makeGetProfile = () => {
getProfileCollectionSortMode,
getProfileFollowers,
getProfileFollowees,
getProfileMostUsedTags,
// External
getUsers,
getCollections
Expand All @@ -133,15 +136,13 @@ export const makeGetProfile = () => {
sortMode,
followers,
followees,
mostUsedTags,
users,
collections
) => {
const emptyState = {
profile: null,
playlists: null,
albums: null,
mostUsedTags: [],
isSubscribed: false,
status
}
Expand Down Expand Up @@ -209,7 +210,6 @@ export const makeGetProfile = () => {
users: followeesPopulated
}
},
mostUsedTags,
playlists,
albums,
status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export type ProfileState = {
updateError: boolean
collectionIds: number[]
collectionStatus: Status.IDLE
mustUsedTags: string[]
topTagsStatus: Status
topTags: string[]
collectionSortMode: CollectionSortMode
profileMeterDismissed: boolean
followers: ProfilePageFollow
Expand All @@ -41,7 +42,6 @@ export type ProfileState = {
tracks: LineupState<{ id: ID }>
isNotificationSubscribed: boolean
error?: string
mostUsedTags: string[]
}

export type ProfilePageState = {
Expand Down
Loading

0 comments on commit 29117e7

Please sign in to comment.