better show filters
This commit is contained in:
@@ -13,3 +13,20 @@ export function filterSong(song: Song, filterValue: string): boolean {
|
||||
function normalize(input: string): string {
|
||||
return input?.toLowerCase().replace(/[\s?!.,']/g, '');
|
||||
}
|
||||
|
||||
export const onlyUnique = <T>(value: T, index: number, array: T[]) => array.indexOf(value) === index;
|
||||
|
||||
export function dynamicSort(property: string) {
|
||||
let sortOrder = 1;
|
||||
if (property[0] === '-') {
|
||||
sortOrder = -1;
|
||||
property = property.substr(1);
|
||||
}
|
||||
return function (a: unknown, b: unknown) {
|
||||
/* next line works with strings and numbers,
|
||||
* and you may want to customize it to your needs
|
||||
*/
|
||||
const result = a[property] < b[property] ? -1 : a[property] > b[property] ? 1 : 0;
|
||||
return result * sortOrder;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,18 +14,7 @@ export class UserService {
|
||||
private iUserId$ = new BehaviorSubject<string | null>(null);
|
||||
private iUser$ = new BehaviorSubject<User | null>(null);
|
||||
|
||||
public constructor(private afAuth: AngularFireAuth, private db: DbService, private router: Router) {
|
||||
this.afAuth.authState
|
||||
.pipe(
|
||||
filter(auth => !!auth),
|
||||
map(auth => auth?.uid ?? ''),
|
||||
tap(uid => this.iUserId$.next(uid)),
|
||||
switchMap(uid => this.readUser$(uid))
|
||||
)
|
||||
.subscribe(_ => this.iUser$.next(_));
|
||||
|
||||
this.db.col$<User>('users/').subscribe(_ => this.users$.next(_));
|
||||
}
|
||||
public users$ = new BehaviorSubject<User[]>([]);
|
||||
|
||||
public get userId$(): Observable<string | null> {
|
||||
return this.iUserId$.asObservable();
|
||||
@@ -37,7 +26,22 @@ export class UserService {
|
||||
|
||||
public currentUser = async (): Promise<User | null> => firstValueFrom(this.user$);
|
||||
|
||||
private users$ = new BehaviorSubject<User[]>([]);
|
||||
public constructor(
|
||||
private afAuth: AngularFireAuth,
|
||||
private db: DbService,
|
||||
private router: Router
|
||||
) {
|
||||
this.afAuth.authState
|
||||
.pipe(
|
||||
filter(auth => !!auth),
|
||||
map(auth => auth?.uid ?? ''),
|
||||
tap(uid => this.iUserId$.next(uid)),
|
||||
switchMap(uid => this.readUser$(uid))
|
||||
)
|
||||
.subscribe(_ => this.iUser$.next(_));
|
||||
|
||||
this.db.col$<User>('users/').subscribe(_ => this.users$.next(_));
|
||||
}
|
||||
public getUserbyId = (userId: string): Promise<User | null> => firstValueFrom(this.getUserbyId$(userId));
|
||||
public getUserbyId$ = (userId: string): Observable<User | null> => this.users$.pipe(map(_ => _.find(f => f.id === userId) || null));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user