diff --git a/package-lock.json b/package-lock.json index e1d46624..6d1937ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -659,6 +659,22 @@ "webpack-sources": "^1.1.0" } }, + "@ngxs/storage-plugin": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@ngxs/storage-plugin/-/storage-plugin-3.2.0.tgz", + "integrity": "sha1-KXMKBohJKQAYuu7Qe0S/O0KEol8=", + "requires": { + "tslib": "^1.9.0" + } + }, + "@ngxs/store": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@ngxs/store/-/store-3.2.0.tgz", + "integrity": "sha1-Uzk5rLQalIo0iGlDMU0qDYZgRck=", + "requires": { + "tslib": "^1.9.0" + } + }, "@schematics/angular": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-0.7.1.tgz", diff --git a/package.json b/package.json index 618ba7d2..241e7374 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,8 @@ "@angular/platform-browser": "^6.1.0", "@angular/platform-browser-dynamic": "^6.1.0", "@angular/router": "^6.1.0", + "@ngxs/storage-plugin": "^3.2.0", + "@ngxs/store": "^3.2.0", "bootstrap": "^4.1.3", "core-js": "^2.5.4", "ngx-electron": "^1.0.4", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index c4819559..1f96b69b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,6 +6,9 @@ import { RouterModule, Routes } from "@angular/router"; import { NgxElectronModule } from "ngx-electron"; +import { NgxsModule } from '@ngxs/store'; +import { NgxsStoragePluginModule } from '@ngxs/storage-plugin'; + import { AppComponent } from "./app.component"; import { LeftSideBarComponent } from "./components/left-side-bar/left-side-bar.component"; import { StreamsMainDisplayComponent } from "./pages/streams-main-display/streams-main-display.component"; @@ -17,6 +20,7 @@ import { AuthService } from "./services/auth.service"; import { AccountsService } from "./services/accounts.service"; import { StreamsService } from "./services/streams.service"; import { StreamingService } from "./services/streaming.service"; +import { RegisteredAppsState } from "./stores/registered-apps.state"; const routes: Routes = [ { path: "", redirectTo: "home", pathMatch: "full" }, @@ -40,7 +44,12 @@ const routes: Routes = [ HttpModule, FormsModule, NgxElectronModule, - RouterModule.forRoot(routes) + RouterModule.forRoot(routes), + + NgxsModule.forRoot([ + RegisteredAppsState + ]), + NgxsStoragePluginModule.forRoot() ], providers: [AuthService, AccountsService, StreamsService, StreamingService, { provide: APP_INITIALIZER, useFactory: settingsServiceFactory, deps: [AccountsService], multi: true }], bootstrap: [AppComponent] diff --git a/src/app/pages/register-new-account/register-new-account.component.ts b/src/app/pages/register-new-account/register-new-account.component.ts index 27faf2f5..aaa4cf74 100644 --- a/src/app/pages/register-new-account/register-new-account.component.ts +++ b/src/app/pages/register-new-account/register-new-account.component.ts @@ -1,7 +1,11 @@ import { Component, OnInit, Input } from "@angular/core"; +import { Store, Select } from '@ngxs/store'; + import { AuthService } from "../../services/auth.service"; import { TokenData } from "../../services/models/mastodon.interfaces"; import { AccountsService } from "../../services/accounts.service"; +import { AddRegisteredApp, RegisteredAppsState, RegisteredAppsStateModel } from "../../stores/registered-apps.state"; +import { Observable } from "rxjs"; @Component({ selector: "app-register-new-account", @@ -13,35 +17,55 @@ export class RegisterNewAccountComponent implements OnInit { // @Input() email: string; // @Input() password: string; result: string; + + //@Select() registeredApps$: Observable; + registeredApps$: Observable; constructor( private readonly authService: AuthService, - private readonly accountsService: AccountsService) { } + private readonly accountsService: AccountsService, + private readonly store: Store) { + + this.registeredApps$ = this.store.select(state => state.registeredapps.registeredApps); + + } ngOnInit() { + this.registeredApps$.subscribe(x => { + console.error('registeredApps$') + console.warn(x); + }); + } onSubmit(): boolean { + + this.store + .dispatch(new AddRegisteredApp({ name: 'test', id: 15, client_id: 'dsqdqs', client_secret: 'dsqdqs', redirect_uri: 'dsqdqs' })) + .subscribe(res => { + console.error('dispatch'); + console.warn(res); + }); + - let fullHandle = this.mastodonFullHandle.split('@').filter(x => x != null && x !== ''); + - console.log(fullHandle[0]); - console.log(fullHandle[1]); - this.result = fullHandle[0] + '*' + fullHandle[1]; + // let fullHandle = this.mastodonFullHandle.split('@').filter(x => x != null && x !== ''); + + // console.log(fullHandle[0]); + // console.log(fullHandle[1]); - //register app + // this.result = fullHandle[0] + '*' + fullHandle[1]; - //redirect to oauth + // window.location.href = "https://google.com"; - - window.location.href = "https://google.com"; //register app //ask for getting token diff --git a/src/app/stores/registered-apps.state.ts b/src/app/stores/registered-apps.state.ts new file mode 100644 index 00000000..d358818f --- /dev/null +++ b/src/app/stores/registered-apps.state.ts @@ -0,0 +1,34 @@ +import { State, Action, StateContext } from '@ngxs/store'; +​ +export class AddRegisteredApp { + static readonly type = '[RegisteredApps] Add app'; + constructor(public app: AppInfo) { } +} + +export interface RegisteredAppsStateModel { + registeredApps: AppInfo[]; +} + +@State({ + name: 'registeredapps', + defaults: { + registeredApps: [] + } +}) +export class RegisteredAppsState { + @Action(AddRegisteredApp) + AddRegisteredApp(ctx: StateContext, action: AddRegisteredApp) { + const state = ctx.getState(); + ctx.setState({ + registeredApps: [...state.registeredApps, action.app] + }); + } +} + +export class AppInfo { + id: number; + name: string; + redirect_uri: string; + client_id: string; + client_secret: string; +} \ No newline at end of file