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

Commit

Permalink
[C-918] Move trending saga to common (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers committed Aug 29, 2022
1 parent 6f24724 commit c854f66
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ export class AudiusAPIClient {
retry = true
) {
const encodedTrackId = this._encodeOrThrow(id)
const encodedCurrentUserId = encodeHashId(currentUserId)
const encodedCurrentUserId = encodeHashId(currentUserId ?? null)

this._assertInitialized()

Expand Down
20 changes: 11 additions & 9 deletions packages/common/src/store/pages/collection/actions.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
// @ts-nocheck
// TODO(nkang) - convert to TS
import { ID, SmartCollectionVariant, UID } from '../../../models'

export const FETCH_COLLECTION = 'FETCH_COLLECTION'
export const FETCH_COLLECTION_SUCCEEDED = 'FETCH_COLLECTION_SUCCEEDED'
export const FETCH_COLLECTION_FAILED = 'FETCH_COLLECTION_FAILED'
export const RESET_COLLECTION = 'RESET_COLLECTION'
export const SET_SMART_COLLECTION = 'SET_SMART_COLLECTION'

export const fetchCollection = (handle, id) => ({
export const fetchCollection = (handle: string | null, id: number) => ({
type: FETCH_COLLECTION,
handle,
id
})

export const fetchCollectionSucceeded = (
collectionId,
collectionUid,
userUid
collectionId: ID,
collectionUid: string,
userUid: string
) => ({
type: FETCH_COLLECTION_SUCCEEDED,
collectionId,
collectionUid,
userUid
})

export const fetchCollectionFailed = (userUid) => ({
export const fetchCollectionFailed = (userUid: UID) => ({
type: FETCH_COLLECTION_FAILED,
userUid
})

export const resetCollection = (collectionUid, userUid) => ({
export const resetCollection = (collectionUid: UID, userUid: UID) => ({
type: RESET_COLLECTION,
collectionUid,
userUid
})

export const setSmartCollection = (smartCollectionVariant) => ({
export const setSmartCollection = (
smartCollectionVariant: SmartCollectionVariant
) => ({
type: SET_SMART_COLLECTION,
smartCollectionVariant
})
5 changes: 4 additions & 1 deletion packages/common/src/utils/hashIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export const decodeHashId = (id: string): Nullable<number> => {
}
}

export const encodeHashId = (id: number | null = null): Nullable<string> => {
export function encodeHashId(id: null): null
export function encodeHashId(id: number): string
export function encodeHashId(id: Nullable<number>): Nullable<string>
export function encodeHashId(id: Nullable<number>): Nullable<string> {
try {
if (id === null) return null
const encodedId = hashids.encode(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { call, put, select } from 'redux-saga/effects'

import { processAndCacheTracks } from 'common/store/cache/tracks/utils'
import { remoteConfigInstance } from 'services/remote-config/remote-config-instance'
import { AppState } from 'store/types'
const { getLastFetchedTrendingGenre, getTrendingGenre } = trendingPageSelectors
const { setLastFetchedTrendingGenre } = trendingPageActions
Expand All @@ -38,6 +37,11 @@ export function* retrieveTrending({
currentUserId
}: RetrieveTrendingArgs): Generator<any, Track[], any> {
const apiClient = yield* getContext('apiClient')
const remoteConfigInstance = yield* getContext('remoteConfigInstance')
const audiusBackendInstance = yield* getContext('audiusBackendInstance')
const audiusLibs = yield call(audiusBackendInstance.getAudiusLibs)
const web3 = audiusLibs.web3Manager.getWeb3()

yield call(remoteConfigInstance.waitForRemoteConfig)
const TF = new Set(
remoteConfigInstance.getRemoteVar(StringKeys.TF)?.split(',') ?? []
Expand Down Expand Up @@ -67,9 +71,10 @@ export function* retrieveTrending({
currentUserId,
timeRange
})

if (TF.size > 0) {
apiTracks = apiTracks.filter((t) => {
const shaId = window.Web3.utils.sha3(t.track_id.toString())
const shaId = web3.utils.sha3(t.track_id.toString())
return !TF.has(shaId)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import { select } from 'redux-saga/effects'

import { LineupSagas } from 'common/store/lineup/sagas'
import { retrieveTrending } from 'pages/track-page/store/retrieveTrending'

import { retrieveTrending } from './retrieveTrending'
const { getTrendingGenre } = trendingPageSelectors
const {
TRENDING_WEEK_PREFIX,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import trendingSagas from './lineups/trending/sagas.js'
import trendingSagas from './lineups/trending/sagas'

export default function sagas() {
return [...trendingSagas()]
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/store/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import exploreCollectionsPageSagas from 'common/store/pages/explore/exploreColle
import explorePageSagas from 'common/store/pages/explore/sagas'
import feedPageSagas from 'common/store/pages/feed/sagas'
import signOnSaga from 'common/store/pages/signon/sagas'
import trendingPageSagas from 'common/store/pages/trending/sagas'
import playerSagas from 'common/store/player/sagas'
import mobileQueueSagas from 'common/store/queue/mobileSagas'
import queueSagas from 'common/store/queue/sagas'
Expand Down Expand Up @@ -58,7 +59,6 @@ import smartCollectionPageSagas from 'pages/smart-collection/store/sagas'
import supportingPageSagas from 'pages/supporting-page/sagas'
import topSupportersPageSagas from 'pages/top-supporters-page/sagas'
import trackSagas from 'pages/track-page/store/sagas'
import trendingPageSagas from 'pages/trending-page/store/sagas'
import trendingPlaylistSagas from 'pages/trending-playlists/store/sagas'
import trendingUndergroundSagas from 'pages/trending-underground/store/sagas'
import uploadSagas from 'pages/upload-page/store/sagas'
Expand Down

0 comments on commit c854f66

Please sign in to comment.