Skip to content

Commit 8152f65

Browse files
committed
feat: added settings state and actions for test
1 parent 7929f75 commit 8152f65

File tree

7 files changed

+65
-27
lines changed

7 files changed

+65
-27
lines changed

src/app/components/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export { NavbarComponent } from './navbar/navbar.component';
2+
export { CollectionComponent } from './collection/collection.component';
3+
export { BucketComponent } from './bucket/bucket.component';
4+
export { PromptComponent } from './prompt/prompt.component';
5+
export { ColorPickerComponent } from './color-picker/color-picker.component';
6+
export { ColorFormComponent } from './color-form/color-form.component';
7+
export { InkComponent } from './ink/ink.component';

src/app/ink.component.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
2+
import { Store } from '@ngxs/store';
3+
import { ChangeView } from './store/actions/settings.action';
4+
import { InkAppView } from './ink.model';
5+
import { DBService } from './services/db.service';
26

37
@Component({
48
selector: 'inkapp-root',
5-
templateUrl: './ink.component.html'
9+
template: '<router-outlet></router-outlet>'
610
})
7-
export class InkApp {
8-
title = 'ink';
11+
export class InkApp implements OnInit {
12+
constructor(private store: Store, private db: DBService) {}
13+
ngOnInit() {
14+
this.store.dispatch(new ChangeView(InkAppView.ROUND));
15+
}
916
}

src/app/ink.config.ts

Whitespace-only changes.

src/app/ink.module.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
import { BrowserModule } from '@angular/platform-browser';
21
import { NgModule } from '@angular/core';
3-
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { NgxsModule } from '@ngxs/store';
4+
import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin';
5+
import {
6+
BucketComponent,
7+
CollectionComponent,
8+
ColorFormComponent,
9+
ColorPickerComponent,
10+
InkComponent,
11+
NavbarComponent,
12+
PromptComponent
13+
} from './components';
414
import { InkApp } from './ink.component';
5-
import { HomePage } from './pages/home/home.component';
615
import { RoutingModule } from './ink.routing';
7-
import { NavbarComponent } from './components/navbar/navbar.component';
8-
import { CollectionComponent } from './components/collection/collection.component';
9-
import { BucketComponent } from './components/bucket/bucket.component';
10-
import { SettingsComponent } from './pages/settings/settings.component';
11-
import { PromptComponent } from './components/prompt/prompt.component';
12-
import { ColorPickerComponent } from './components/color-picker/color-picker.component';
13-
import { ColorFormComponent } from './components/color-form/color-form.component';
14-
import { InkComponent } from './components/ink/ink.component';
16+
import { HomePage } from './pages/home/home.component';
17+
import { SettingsPage } from './pages/settings/settings.component';
18+
import { SettingsState } from './store/states/settings.state';
1519

16-
export const MODULES = [RoutingModule];
20+
export const MODULES = [RoutingModule, NgxsModule.forRoot([SettingsState]), NgxsReduxDevtoolsPluginModule.forRoot()];
1721
export const COMPONENTS = [
1822
InkApp,
19-
InkComponent,
2023
NavbarComponent,
2124
CollectionComponent,
2225
BucketComponent,
23-
SettingsComponent,
2426
PromptComponent,
2527
ColorPickerComponent,
26-
ColorFormComponent
28+
ColorFormComponent,
29+
InkComponent
2730
];
28-
export const PAGES = [HomePage];
31+
export const PAGES = [HomePage, SettingsPage];
2932

3033
@NgModule({
3134
declarations: [...COMPONENTS, ...PAGES],
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { Component, OnInit } from '@angular/core';
22

33
@Component({
4-
selector: 'inkapp-settings',
4+
selector: 'inkapp-settings-page',
55
templateUrl: './settings.component.html',
66
styles: []
77
})
8-
export class SettingsComponent implements OnInit {
9-
10-
constructor() { }
11-
12-
ngOnInit() {
13-
}
8+
export class SettingsPage implements OnInit {
9+
constructor() {}
1410

11+
ngOnInit() {}
1512
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { InkAppView } from '../../ink.model';
2+
3+
export class ChangeView {
4+
static readonly type = '[Settings] change view';
5+
constructor(public view: InkAppView) {}
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { State, Action, StateContext } from '@ngxs/store';
2+
import { InkAppSettings } from '../../ink.model';
3+
import { ChangeView } from '../actions/settings.action';
4+
5+
@State<Partial<InkAppSettings>>({
6+
name: 'settings',
7+
defaults: {}
8+
})
9+
export class SettingsState {
10+
@Action(ChangeView)
11+
changeView(ctx: StateContext<InkAppSettings>, action: ChangeView) {
12+
const state = ctx.getState();
13+
ctx.setState({
14+
...state,
15+
view: action.view
16+
});
17+
}
18+
}

0 commit comments

Comments
 (0)