-
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
…8268) Co-authored-by: sliptype <sliptype@gmail.com>
- Loading branch information
1 parent
7417a40
commit 909db7c
Showing
55 changed files
with
1,748 additions
and
95 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { full as FullSdk } from '@audius/sdk' | ||
// import type { full as FullSdk } from '@audius/sdk' | ||
|
||
export type SsrPageProps = { | ||
track?: FullSdk.TrackFull | ||
user?: FullSdk.UserFull | ||
collection?: FullSdk.PlaylistFull | ||
// track?: FullSdk.TrackFull | ||
// user?: FullSdk.UserFull | ||
// collection?: FullSdk.PlaylistFull | ||
track?: any | ||
user?: any | ||
collection?: any | ||
error?: { isErrorPageOpen: boolean } | ||
} |
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 @@ | ||
export * from './serverReducers' |
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,48 @@ | ||
import { History } from 'history' | ||
import { combineReducers } from 'redux' | ||
import type { Storage } from 'redux-persist' | ||
|
||
import account from '~/store/account/slice' | ||
import collectionsReducer from '~/store/cache/collections/reducer' | ||
import { asCache } from '~/store/cache/reducer' | ||
import tracksReducer from '~/store/cache/tracks/reducer' | ||
import usersReducer from '~/store/cache/users/reducer' | ||
// import collection from '~/store/pages/collection/reducer' | ||
// import profileReducer from '~/store/pages/profile/reducer' | ||
import track from '~/store/pages/track/reducer' | ||
import theme from '~/store/ui/theme/slice' | ||
|
||
import { Kind, SsrPageProps } from '../models' | ||
|
||
/** | ||
* A function that creates common reducers. | ||
* @returns an object of all reducers to be used with `combineReducers` | ||
*/ | ||
export const serverReducers = ( | ||
_storage: Storage, | ||
ssrPageProps?: SsrPageProps, | ||
_isServerSide?: boolean, | ||
_history?: History | ||
) => ({ | ||
account, | ||
|
||
// Cache | ||
// @ts-ignore | ||
collections: asCache(collectionsReducer(ssrPageProps), Kind.COLLECTIONS), | ||
// @ts-ignore | ||
tracks: asCache(tracksReducer(ssrPageProps), Kind.TRACKS), | ||
// @ts-ignore | ||
users: asCache(usersReducer(ssrPageProps), Kind.USERS), | ||
|
||
// UI | ||
ui: combineReducers({ | ||
theme | ||
}), | ||
|
||
// Pages | ||
pages: combineReducers({ | ||
// collection: collection(ssrPageProps), | ||
// profile: profileReducer(ssrPageProps), | ||
track: track(ssrPageProps) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './AudiusAPIClient' | ||
export * as responseAdapter from './ResponseAdapter' | ||
export { makeActivity } from './makeActivity' | ||
export * from './types' |
30 changes: 30 additions & 0 deletions
30
packages/common/src/services/audius-api-client/makeActivity.ts
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 { full } from '@audius/sdk' | ||
|
||
import { UserTrackMetadata, UserCollectionMetadata } from '~/models' | ||
|
||
import { makePlaylist, makeTrack } from './ResponseAdapter' | ||
import { APIActivity, APIActivityV2, isApiActivityV2 } from './types' | ||
|
||
export const makeActivity = ( | ||
activity: APIActivity | APIActivityV2 | ||
): UserTrackMetadata | UserCollectionMetadata | undefined => { | ||
if (isApiActivityV2(activity)) { | ||
if (!activity.item) { | ||
return undefined | ||
} | ||
if (activity.itemType === 'track') { | ||
return makeTrack(full.TrackFullToJSON(activity.item as full.TrackFull)) | ||
} else if (activity.itemType === 'playlist') { | ||
return makePlaylist( | ||
full.PlaylistFullWithoutTracksToJSON( | ||
activity.item as full.PlaylistFullWithoutTracks | ||
) | ||
) | ||
} | ||
return undefined | ||
} else { | ||
return activity.item_type === 'track' | ||
? makeTrack(activity.item) | ||
: makePlaylist(activity.item) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { EntityManager } from './EntityManager' | ||
export { EntityManagerService, Action as EntityManagerAction } from './types' | ||
export type { EntityManagerService } from './types' | ||
export { Action as EntityManagerAction } from './types' |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { Storage } from './Storage' | ||
export { StorageService } from './types' | ||
export type { StorageService } from './types' |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ import type Web3Type from 'web3' | |
|
||
declare global { | ||
interface Window { | ||
// @ts-ignore | ||
Web3: Web3 | ||
} | ||
} | ||
|
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,63 @@ | ||
import { ReactNode, useRef } from 'react' | ||
|
||
import { Provider } from 'react-redux' | ||
import { Persistor, persistStore } from 'redux-persist' | ||
import { PersistGate } from 'redux-persist/integration/react' | ||
import { PartialDeep } from 'type-fest' | ||
|
||
import { useIsMobile } from 'hooks/useIsMobile' | ||
import { configureStore } from 'store/configureServerStore' | ||
import { AppState } from 'store/types' | ||
import logger from 'utils/logger' | ||
|
||
import { useSsrContext } from '../ssr/SsrContext' | ||
|
||
import { useHistoryContext } from './HistoryProvider' | ||
|
||
export const ServerReduxProvider = ({ | ||
children, | ||
initialStoreState | ||
}: { | ||
children: ReactNode | ||
// Sets up an initial store state | ||
initialStoreState?: PartialDeep<AppState> | ||
}) => { | ||
const { pageProps, isServerSide } = useSsrContext() | ||
const { history } = useHistoryContext() | ||
const isMobile = useIsMobile() | ||
|
||
const storeRef = useRef<ReturnType<typeof configureStore>>() | ||
const persistorRef = useRef<Persistor>() | ||
|
||
if (!storeRef.current) { | ||
const store = configureStore( | ||
history, | ||
isMobile, | ||
pageProps, | ||
isServerSide, | ||
initialStoreState | ||
) | ||
storeRef.current = store | ||
const persistor = persistStore(store) | ||
persistorRef.current = persistor | ||
|
||
// Mount store to window for easy access | ||
if (typeof window !== 'undefined') { | ||
// @ts-ignore | ||
window.store = store | ||
} | ||
|
||
// Set up logger on store | ||
if (!isServerSide) { | ||
logger(store) | ||
} | ||
} | ||
|
||
return ( | ||
<Provider store={storeRef.current}> | ||
<PersistGate loading={null} persistor={persistorRef.current!}> | ||
{() => children} | ||
</PersistGate> | ||
</Provider> | ||
) | ||
} |
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
Oops, something went wrong.