Skip to content

Commit

Permalink
chore: fix GenericStoreStatus type
Browse files Browse the repository at this point in the history
  • Loading branch information
trungvose committed Mar 29, 2024
1 parent 5d89964 commit fcb2296
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ export const albumsReducer = createReducer(
initialState,
on(loadAlbums, (state) => ({
...state,
status: 'loading',
status: 'loading' as const,
error: null
})),
on(loadAlbumsSuccess, (state, { albums }) => ({
...state,
data: albums,
status: 'success',
status: 'success' as const,
error: null
})),
on(loadAlbumsError, (state, { error }) => ({
...state,
status: 'error',
status: 'error' as const,
error
}))
);
4 changes: 2 additions & 2 deletions libs/web/album/feature/detail/src/lib/album.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TracksLoadingComponent } from '@angular-spotify/web/shared/ui/tracks-lo
import { MediaSummaryModule } from '@angular-spotify/web/shared/ui/media-summary';
import { PlayButtonModule } from '@angular-spotify/web/shared/ui/play-button';
import { MediaTableModule } from '@angular-spotify/web/shared/ui/media-table';
import { SvgIconsModule } from '@ngneat/svg-icon';
import { SvgIconComponent } from '@ngneat/svg-icon';
import { AlbumTrackModule } from '@angular-spotify/web/album/ui/album-track';
@NgModule({
imports: [
Expand All @@ -15,7 +15,7 @@ import { AlbumTrackModule } from '@angular-spotify/web/album/ui/album-track';
MediaSummaryModule,
PlayButtonModule,
MediaTableModule,
SvgIconsModule,
SvgIconComponent,
AlbumTrackModule,
RouterModule.forChild([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ const initialState: CategoriesState = {

export const categoriesReducer = createReducer(
initialState,
on(loadCategories, (state) => ({ ...state, status: 'loading' })),
on(loadCategories, (state) => ({ ...state, status: 'loading' as const })),
on(loadCategoriesSuccess, (state, { categories }) => {
const { map } = state;
categories.items.forEach((category) => {
map.set(category.id, category);
});
return {
...state,
status: 'success',
status: 'success' as const,
data: categories,
map: new Map(map)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export const categoryPlaylistsReducer = createReducer(
initialState,
on(loadCategoryPlaylists, (state) => ({
...state,
status: 'loading'
status: 'loading' as const
})),
on(loadCategoryPlaylistsSuccess, (state, { categoryId, playlists }) => {
const { data: map } = state;
map?.set(categoryId, playlists);
return {
...state,
data: new Map(map!),
status: 'success'
status: 'success' as const
};
}),
on(setCategoryPlaylistsState, (state, { status }) => ({ ...state, status }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export const featuredPlaylistsFeatureKey = 'feature-playlists';

export const featuredPlaylistsReducer = createReducer(
initialState,
on(loadFeaturedPlaylists, (state) => ({ ...state, status: 'loading' })),
on(loadFeaturedPlaylists, (state) => ({ ...state, status: 'loading' as const })),
on(loadFeaturedPlaylistsSuccess, (state, { response }) => ({
...state,
data: response,
status: 'success',
status: 'success' as const,
error: null
})),
on(loadFeaturedPlaylistsError, (state, { error }) => ({
...state,
error,
status: 'error'
status: 'error' as const
}))
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export const recentFeatureTracksFeatureKey = 'recentTracks';

export const recentPlayedTracksReducer = createReducer(
initialState,
on(loadRecentTracks, (state) => ({ ...state, status: 'loading' })),
on(loadRecentTracks, (state) => ({ ...state, status: 'loading' as const })),
on(loadRecentTracksSuccess, (state, { response }) => ({
...state,
data: response,
status: 'success',
status: 'success' as const,
error: null
})),
on(loadRecentTracksError, (state, { error }) => ({
...state,
error,
status: 'error'
status: 'error' as const
}))
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ const initialState: PlaylistTracksState = {

export const playlistTracksReducer = createReducer(
initialState,
on(loadPlaylistTracks, (state) => ({ ...state, status: 'loading' })),
on(loadPlaylistTracks, (state) => ({ ...state, status: 'loading' as const })),
on(loadPlaylistTracksSuccess, (state, { playlistId, playlistTracks }) => {
const { data: map } = state;
map?.set(playlistId, playlistTracks);
return { ...state, data: map, status: 'success' };
return { ...state, data: map, status: 'success' as const };
}),
on(loadPlaylistTracksError, (state, { error }) => ({ ...state, error, status: 'error' })),
on(loadPlaylistTracksError, (state, { error }) => ({
...state,
error,
status: 'error' as const
})),
on(setPlaylistTracksStateStatus, (state, { status }) => ({ ...state, status }))
);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const initialState: PlaylistsState = {

export const playlistsReducer = createReducer(
initialState,
on(loadPlaylists, (state) => ({ ...state, status: 'loading' })),
on(loadPlaylists, (state) => ({ ...state, status: 'loading' as const })),
on(loadPlaylistsSuccess, (state, { playlists }) => {
const { items } = playlists;
const map = new Map<string, SpotifyApi.PlaylistObjectSimplified>();
Expand All @@ -31,14 +31,14 @@ export const playlistsReducer = createReducer(
...state,
map: map,
data: playlists,
status: 'success',
status: 'success' as const,
error: null
};
}),
on(loadPlaylistsError, (state, { error }) => ({
...state,
error,
status: 'error'
status: 'error' as const
})),
on(loadPlaylistSuccess, (state, { playlist }) => {
state.map?.set(playlist.id, playlist);
Expand Down

0 comments on commit fcb2296

Please sign in to comment.