feat: adds authentication to ngrx store

This commit is contained in:
2023-01-05 18:05:43 +01:00
parent fb57344b1b
commit 9f09aae467
59 changed files with 1152 additions and 848 deletions

View File

@@ -1,7 +1,10 @@
import {Component, isDevMode} from '@angular/core';
import {Store} from "@ngrx/store";
import {MastodonApiActions} from "./shared/state/store/actions";
import {PersistentStore} from "./shared/state/persistent/persistent-store.service";
import {select, Store} from "@ngrx/store";
import {fromApplication, fromAuthorize, selectIsLoggedIn} from "./shared/state/store";
import {environment} from "../environments/environment";
// @ts-ignore
import packageJson from '../../../../package.json';
import {tap} from "rxjs";
@Component({
selector: 'app-root',
@@ -9,10 +12,11 @@ import {PersistentStore} from "./shared/state/persistent/persistent-store.servic
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'mastolists';
appName = environment.appName;
version = packageJson.version;
navigationItems = [
{title: 'Authorize', link: '/auth'},
{title: 'Authorize', link: '/authorize'},
{title: 'Stats', link: '/sync'},
{title: 'Edit Lists', link: '/lists'},
{title: 'List view', link: '/followings/list'},
@@ -20,10 +24,15 @@ export class AppComponent {
{title: 'Table View', link: '/followings/table'},
];
constructor(private store: Store, private persistentStore: PersistentStore) {
if (this.persistentStore.isAuthorized() && !isDevMode()) {
this.store.dispatch(MastodonApiActions.loadLists());
this.store.dispatch(MastodonApiActions.loadFollowings());
}
constructor(private store: Store) {
this.store.dispatch(fromAuthorize.loadLocalStorage());
this.store.pipe(
select(selectIsLoggedIn),
).subscribe((loggedIn) => {
if (loggedIn && !isDevMode()) {
this.store.dispatch(fromApplication.loadLists());
this.store.dispatch(fromApplication.loadFollowings());
}
});
}
}