Skip to content

Commit a88ccec

Browse files
committed
refactor: wip
1 parent bec56fb commit a88ccec

File tree

15 files changed

+66
-517
lines changed

15 files changed

+66
-517
lines changed

package-lock.json

Lines changed: 2 additions & 466 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"scripts": {
66
"ng": "ng",
77
"config:secrets": "ts-node ./config/env.secrets.ts",
8-
"start":
9-
"npm run config:secrets && ng serve --proxy-config config/proxy.conf.json -o --host=0.0.0.0 --disable-host-check",
8+
"start": "npm run config:secrets && ng serve --proxy-config config/proxy.conf.json -o --host=0.0.0.0 --disable-host-check",
109
"build": "ng build",
1110
"build:prod": "ng build --prod",
1211
"test": "ng test",

src/app/ink.routing.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ const routes: Routes = [
1515
exports: [RouterModule]
1616
})
1717
export class RoutingModule {}
18-
19-
export const routedComponents = [HomePage];

src/app/library/components/bucket/bucket.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { children } from '@lib/operators';
1010

1111
@Component({
1212
selector: 'inkapp-bucket',
13-
templateUrl: './bucket.component.html',
14-
styles: []
13+
templateUrl: './bucket.component.html'
1514
})
1615
export class BucketComponent implements OnInit {
1716
@Input() index: number;

src/app/library/components/drop/drop.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ export class DropComponent implements OnInit, OnDestroy {
2222
constructor(private _store: Store, private _colorPickerService: InkColorPickerService, private _elRef: ElementRef) {}
2323

2424
ngOnInit() {
25-
console.log('drop');
2625
this._colorPickerService.configure(this._elRef);
2726
this.drop = this.data;
2827
}
2928
openColorPicker() {
30-
console.log('hsl');
3129
this.colorPickerRef = this._colorPickerService.getRef();
3230
if (this.data.meta.hsl) {
3331
this.colorPickerRef.instance.color = this.data.meta.hsl;
@@ -43,7 +41,6 @@ export class DropComponent implements OnInit, OnDestroy {
4341
});
4442
this._colorPickerService.backdropClick().subscribe(b => {
4543
if (this.drop.name !== this.data.name) {
46-
console.log('backdrop clocked update', this.data);
4744
this._store.dispatch(new UpdateDrop(this.drop));
4845
}
4946
});

src/app/library/components/header/header.component.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22
import { Store } from '@ngxs/store';
33
import { map, tap, filter } from 'rxjs/operators';
44
import { InkBucketsService } from '@lib/services';
@@ -9,12 +9,9 @@ import { BoardsState } from '@store/states';
99
selector: 'inkapp-header',
1010
templateUrl: './header.component.html'
1111
})
12-
export class HeaderComponent implements OnInit {
12+
export class HeaderComponent {
1313
currentBoardId: string;
1414
constructor(private _store: Store, private _bucketService: InkBucketsService) {}
15-
16-
ngOnInit() {}
17-
1815
newBucket() {
1916
const defaultBoardId = this._store.selectSnapshot(BoardsState.defaultBoard);
2017
this._store.dispatch(new CreateBucket({ name: 'Hello-123', boardId: defaultBoardId }));
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
import { Component, OnInit, EventEmitter } from '@angular/core';
2-
import { Store } from '@ngxs/store';
1+
import { Component, EventEmitter } from '@angular/core';
32
import { Subject } from 'rxjs';
4-
import { InkDropMeta } from '@lib/models';
53

64
@Component({
75
selector: 'inkapp-chrome-color-picker',
86
templateUrl: 'chrome-color-picker.template.html'
97
})
10-
export class ChromeColorPickerComponent implements OnInit {
11-
inkData: InkDropMeta;
12-
bucketId: InkDropMeta;
13-
private colorChanged: Subject<any> = new Subject();
14-
constructor(private store: Store) {}
15-
16-
ngOnInit() {}
8+
export class ChromeColorPickerComponent {
9+
colorChanged: Subject<any> = new Subject();
1710
onColorChange(color) {
18-
this.colorChanged.next(color);
1911
return this.colorChanged.asObservable();
2012
}
2113
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<color-chrome (onChange)="onColorChange($event)"></color-chrome>
1+
<color-chrome (onChange)="colorChanged.next($event)"></color-chrome>

src/app/library/services/gist.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ export class InkGistService {
5959
return this._http.get(`https://api.github.com/gists/${gist.id}`);
6060
}
6161
return of(null);
62-
})
62+
}),
63+
map(gist => {
64+
return gist.files['inkapp-database.json'].content;
65+
}),
66+
map(gist => JSON.parse(gist))
6367
);
6468
}
6569

src/app/library/store/actions/settings.action.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,17 @@ export class DeleteSettingsItem {
1919
static readonly type = '[Settings] delete';
2020
constructor(public key: string) {}
2121
}
22+
23+
export class FetchRemoteGist {
24+
static readonly type = '[Settings] fetch remote gist';
25+
}
26+
27+
export class CreateRemoteGist {
28+
static readonly type = '[Settings] create remote gist';
29+
constructor(public gistData: object) {}
30+
}
31+
32+
export class UpdateRemoteGist {
33+
static readonly type = '[Settings] update remote gist';
34+
constructor(public gistId: string, public gistData: object) {}
35+
}

src/app/library/store/states/settings.state.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { State, Action, StateContext, Selector, NgxsOnInit } from '@ngxs/store';
22
import { InkAppSettingsItem, InkAppSettings } from '@lib/models';
3-
import { UpdateSettingsItem, PopulateSettings, MergeSettings } from '@store/actions';
3+
import {
4+
UpdateSettingsItem,
5+
PopulateSettings,
6+
MergeSettings,
7+
FetchRemoteGist,
8+
CreateRemoteGist,
9+
UpdateRemoteGist
10+
} from '@store/actions';
411
import { SelectMultipleControlValueAccessor } from '@angular/forms';
5-
import { InkSettingsService } from '@lib/services';
12+
import { InkSettingsService, InkGistService } from '@lib/services';
13+
import { tap } from 'rxjs/operators';
614

715
@State<Partial<InkAppSettings>>({
816
name: 'settings',
@@ -14,7 +22,7 @@ export class SettingsState implements NgxsOnInit {
1422
return state.filter(s => s.key === 'view')[0].value;
1523
}
1624

17-
constructor(private _service: InkSettingsService) {}
25+
constructor(private _service: InkSettingsService, private _gistService: InkGistService) {}
1826
ngxsOnInit(ctx: StateContext<InkAppSettings>) {
1927
return this._service.getAll().then(settings => {
2028
ctx.dispatch(new MergeSettings(settings));
@@ -44,4 +52,20 @@ export class SettingsState implements NgxsOnInit {
4452
const state = ctx.getState();
4553
ctx.setState([...state, ...action.settings]);
4654
}
55+
56+
@Action(FetchRemoteGist)
57+
fetchRemoteGist(ctx: StateContext<InkAppSettings>, action: FetchRemoteGist) {
58+
return this._gistService.get();
59+
}
60+
61+
// @Action(CreateRemoteGist)
62+
// createRemoteGist(ctx: StateContext<InkAppSettings>, action: CreateRemoteGist) {
63+
// const state = ctx.getState();
64+
// ctx.setState([...state, ...action.settings]);
65+
// }
66+
// @Action(UpdateRemoteGist)
67+
// updateRemoteGist(ctx: StateContext<InkAppSettings>, action: UpdateRemoteGist) {
68+
// const state = ctx.getState();
69+
// ctx.setState([...state, ...action.settings]);
70+
// }
4771
}

src/app/pages/home/home.page.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import { InkBoardMeta } from '@lib/models';
55
import { InkBoardsService, InkDatabaseService } from '@lib/services';
66
import { FetchAllBoards, FetchAllBuckets, FetchAllDrops, RemoveAllBuckets, RemoveAllDrops } from '@store/actions';
77
import { BoardsState } from '@store/states';
8+
import { Observable } from 'rxjs';
89

910
@Component({
1011
selector: 'inkapp-home-page',
1112
templateUrl: './home.page.html'
1213
})
1314
export class HomePage implements OnInit, OnDestroy {
14-
@Select(BoardsState) boards$: InkBoardMeta[];
15+
@Select(BoardsState) boards$: Observable<InkBoardMeta[]>;
1516
constructor(private _store: Store) {}
1617

1718
ngOnInit() {
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'inkapp-notfound-page',
55
template: 'Page not found'
66
})
7-
export class NotFoundPage implements OnInit {
8-
constructor() {}
9-
10-
ngOnInit() {}
11-
}
7+
export class NotFoundPage {}

src/app/pages/redirect/redirect.page.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Router, ActivatedRoute, Params } from '@angular/router';
33
import { InkGithubService } from '@lib/services';
4+
import { GITHUB_ACCESS_TOKEN_NAME } from '@root/ink.config';
45

56
@Component({
67
selector: 'inkapp-redirect-page',
@@ -21,7 +22,7 @@ export class RedirectPage implements OnInit {
2122
.split('&')
2223
.map(s => s.split('='))
2324
.map(d => ({ [d[0]]: d[1] }));
24-
localStorage.setItem('inkapp_access_token', data[0].access_token);
25+
localStorage.setItem(GITHUB_ACCESS_TOKEN_NAME, data[0].access_token);
2526
this._router.navigateByUrl('/settings');
2627
});
2728
}

src/app/pages/settings/settings.page.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import merge from 'deepmerge';
44
import { environment } from '../../../environments/environment';
55
import { InkAppSettingsItem, InkGist } from '@lib/models';
66
import { InkDatabaseService, InkSettingsService, InkGithubService, InkGistService } from '@lib/services';
7-
import { PopulateSettings, UpdateSettingsItem, MergeSettings } from '@store/actions';
7+
import { PopulateSettings, UpdateSettingsItem, MergeSettings, FetchRemoteGist } from '@store/actions';
88
import { GITHUB_ACCESS_TOKEN_NAME } from '../../ink.config';
99
import { Observable } from 'rxjs';
1010
import { SettingsState } from '@store/states';
@@ -35,10 +35,7 @@ export class SettingsPage implements OnInit {
3535
}
3636
this._store.dispatch(new MergeSettings(doc));
3737
});
38-
this.view$.subscribe(v => {
39-
console.log('fot this', v);
40-
this.currentView = v;
41-
});
38+
this.view$.subscribe(v => (this.currentView = v));
4239
this.connectedToGithub = !!localStorage.getItem(GITHUB_ACCESS_TOKEN_NAME);
4340
}
4441
disconnect() {}
@@ -54,7 +51,7 @@ export class SettingsPage implements OnInit {
5451
this._gistService.edit(gistData.id, data).subscribe(
5552
res => {
5653
this._settingsService.update('gist', JSON.stringify(res)).then(doc => {
57-
console.log('settings updatedw ith sync', doc);
54+
console.log('settings updated with sync', doc);
5855
});
5956
},
6057
err => {
@@ -71,13 +68,7 @@ export class SettingsPage implements OnInit {
7168
}
7269
async loadGists() {
7370
const db = await this._db.getDatabase();
74-
const data = await db.dump();
75-
this._gistService.get().subscribe(async (gist: any) => {
76-
if (!gist) {
77-
console.log('No gist!');
78-
return;
79-
}
80-
const gistData = JSON.parse(gist.files['inkapp-database.json'].content);
71+
this._store.dispatch(new FetchRemoteGist()).subscribe(async gistData => {
8172
await db.importDump(gistData);
8273
});
8374
}

0 commit comments

Comments
 (0)