-
-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: categories and category components * feat: add browse data access and render categories * feat: refactor loading spinner module * feat: categories loading spinner * feat: set up category playlists store * feat: set exact only for home route * feat: render category playlists
- Loading branch information
Showing
122 changed files
with
1,549 additions
and
196 deletions.
There are no files selected for viewing
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,5 +1,5 @@ | ||
{ | ||
"*.{js,ts,html}": [ | ||
"*.{ts,html}": [ | ||
"eslint --cache" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@nrwl/web/babel"] | ||
} |
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,21 @@ | ||
{ | ||
"extends": ["../../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"parserOptions": { | ||
"project": ["libs/web/browse/data-access/tsconfig.*?.json"] | ||
}, | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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,7 @@ | ||
# web-browse-data-access | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test web-browse-data-access` to execute the unit tests via [Jest](https://jestjs.io). |
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,14 @@ | ||
module.exports = { | ||
displayName: 'web-browse-data-access', | ||
preset: '../../../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.spec.json' | ||
} | ||
}, | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest' | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../../../coverage/libs/web/browse/data-access' | ||
}; |
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 './lib/store'; |
22 changes: 22 additions & 0 deletions
22
libs/web/browse/data-access/src/lib/store/categories/categories.action.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,22 @@ | ||
import { GenericStoreStatus } from '@angular-spotify/web/shared/data-access/models'; | ||
import { createAction, props } from '@ngrx/store'; | ||
|
||
export const loadCategories = createAction( | ||
'[Browse Page]/Load Categories', | ||
props<Record<string, string>>() | ||
); | ||
|
||
export const loadCategoriesSuccess = createAction( | ||
'[Browse Page/Load Categories Success', | ||
props<{ | ||
categories: SpotifyApi.PagingObject<SpotifyApi.CategoryObject>; | ||
}>() | ||
); | ||
|
||
export const setCategoriesState = createAction( | ||
'[Browse Page/Set Categories state status', | ||
props<{ | ||
status: GenericStoreStatus; | ||
}>() | ||
); | ||
// TODO: Skip load error action, to integrate with toApiResponse operator |
46 changes: 46 additions & 0 deletions
46
libs/web/browse/data-access/src/lib/store/categories/categories.effect.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,46 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { loadCategories, loadCategoriesSuccess, setCategoriesState } from './categories.action'; | ||
import { switchMap, map, withLatestFrom, filter, tap } from 'rxjs/operators'; | ||
import { BrowseApiService } from '@angular-spotify/web/shared/data-access/spotify-api'; | ||
import { AuthStore } from '@angular-spotify/web/auth/data-access'; | ||
import { getCategories } from './categories.selector'; | ||
import { select, Store } from '@ngrx/store'; | ||
|
||
@Injectable() | ||
export class CategoriesEffect { | ||
loadCategories$ = createEffect(() => | ||
this.actions$.pipe( | ||
ofType(loadCategories), | ||
withLatestFrom(this.store.pipe(select(getCategories))), | ||
tap(([, categories]) => { | ||
if (categories) { | ||
this.store.dispatch(setCategoriesState({ status: 'success' })); | ||
} | ||
}), | ||
filter(([, data]) => !data), | ||
withLatestFrom(this.authStore.country$), | ||
switchMap(([, country]) => | ||
this.browseApi | ||
.getAllCategories({ | ||
country, | ||
limit: 50 | ||
}) | ||
.pipe( | ||
map((response) => | ||
loadCategoriesSuccess({ | ||
categories: response | ||
}) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
|
||
constructor( | ||
private store: Store, | ||
private actions$: Actions, | ||
private browseApi: BrowseApiService, | ||
private authStore: AuthStore | ||
) {} | ||
} |
34 changes: 34 additions & 0 deletions
34
libs/web/browse/data-access/src/lib/store/categories/categories.reducer.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,34 @@ | ||
import { GenericState } from '@angular-spotify/web/shared/data-access/models'; | ||
import { createReducer, on } from '@ngrx/store'; | ||
import { loadCategories, loadCategoriesSuccess, setCategoriesState } from './categories.action'; | ||
export const categoriesFeatureKey = 'categories'; | ||
|
||
export interface CategoriesState | ||
extends GenericState<SpotifyApi.PagingObject<SpotifyApi.CategoryObject>> { | ||
map: Map<string, SpotifyApi.CategoryObject>; | ||
} | ||
|
||
const initialState: CategoriesState = { | ||
data: null, | ||
status: 'pending', | ||
error: null, | ||
map: new Map() | ||
}; | ||
|
||
export const categoriesReducer = createReducer( | ||
initialState, | ||
on(loadCategories, (state) => ({ ...state, status: 'loading' })), | ||
on(loadCategoriesSuccess, (state, { categories }) => { | ||
const { map } = state; | ||
categories.items.forEach((category) => { | ||
map.set(category.id, category); | ||
}); | ||
return { | ||
...state, | ||
status: 'success', | ||
data: categories, | ||
map: new Map(map) | ||
}; | ||
}), | ||
on(setCategoriesState, (state, { status }) => ({ ...state, status })) | ||
); |
Oops, something went wrong.