import { createApi } from '@reduxjs/toolkit/query/react'; import { baseQueryWithReauth } from './baseQuery'; import { REHYDRATE_API, type RehydrateApiPayload } from './rehydrate'; export const api = createApi({ reducerPath: 'api', baseQuery: baseQueryWithReauth, tagTypes: [ 'Track', 'Album', 'Artist', 'Playlist', 'Download', 'Like', 'User', 'Storage', ], // Tier 2 offline: seed the cache from the persisted snapshot dispatched at // startup (see `store/rtkqPersist.ts`). Returning the saved queries/mutations // lets the last-seen library render before — or instead of — any network call. extractRehydrationInfo(action) { if (action.type === REHYDRATE_API) { // The api reducer reads `queries`/`mutations` off this and restores any // fulfilled entries; pending/rejected ones are ignored automatically. return action.payload as RehydrateApiPayload as never; } return undefined; }, endpoints: () => ({}), });