Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9baf41e
commit 33e3597
Showing
9 changed files
with
1,066 additions
and
142 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
|
||
import { TaskModule } from './components/task.module'; | ||
import { NgxsModule } from '@ngxs/store'; | ||
import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin'; | ||
import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; | ||
|
||
import { environment } from '../environments/environment'; | ||
import { AppComponent } from './app.component'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
declarations: [AppComponent], | ||
imports: [ | ||
BrowserModule | ||
BrowserModule, | ||
TaskModule, | ||
NgxsModule.forRoot([], { | ||
developmentMode: !environment.production, | ||
}), | ||
NgxsReduxDevtoolsPluginModule.forRoot(), | ||
NgxsLoggerPluginModule.forRoot({ | ||
disabled: environment.production, | ||
}), | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule { } | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Component, Input, Output, EventEmitter } from '@angular/core'; | ||
|
||
import { Task } from '../models/task.model'; | ||
|
||
@Component({ | ||
selector: 'app-pure-task-list', | ||
template: ` | ||
<div class="list-items"> | ||
<app-task | ||
*ngFor="let task of tasksInOrder" | ||
[task]="task" | ||
(onArchiveTask)="onArchiveTask.emit($event)" | ||
(onPinTask)="onPinTask.emit($event)" | ||
> | ||
</app-task> | ||
<div | ||
*ngIf="tasksInOrder.length === 0 && !loading" | ||
class="wrapper-message" | ||
> | ||
<span class="icon-check"></span> | ||
<p class="title-message">You have no tasks</p> | ||
<p class="subtitle-message">Sit back and relax</p> | ||
</div> | ||
<div *ngIf="loading"> | ||
<div *ngFor="let i of [1, 2, 3, 4, 5, 6]" class="loading-item"> | ||
<span class="glow-checkbox"></span> | ||
<span class="glow-text"> | ||
<span>Loading</span> <span>cool</span> <span>state</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
}) | ||
export default class PureTaskListComponent { | ||
/** | ||
* @ignore | ||
* Component property to define ordering of tasks | ||
*/ | ||
tasksInOrder: Task[] = []; | ||
|
||
/** Checks if it's in loading state */ | ||
@Input() loading = false; | ||
|
||
/** Event to change the task to pinned */ | ||
// tslint:disable-next-line: no-output-on-prefix | ||
@Output() | ||
onPinTask = new EventEmitter<Event>(); | ||
|
||
/** Event to change the task to archived */ | ||
// tslint:disable-next-line: no-output-on-prefix | ||
@Output() | ||
onArchiveTask = new EventEmitter<Event>(); | ||
|
||
@Input() | ||
set tasks(arr: Task[]) { | ||
const initialTasks = [ | ||
...arr.filter((t) => t.state === 'TASK_PINNED'), | ||
...arr.filter((t) => t.state !== 'TASK_PINNED'), | ||
]; | ||
const filteredTasks = initialTasks.filter( | ||
(t) => t.state === 'TASK_INBOX' || t.state === 'TASK_PINNED' | ||
); | ||
this.tasksInOrder = filteredTasks.filter( | ||
(t) => t.state === 'TASK_INBOX' || t.state === 'TASK_PINNED' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,36 @@ | ||
import { Component, Input, Output, EventEmitter } from '@angular/core'; | ||
|
||
import { Task } from '../models/task.model'; | ||
import { Component } from '@angular/core'; | ||
import { Store } from '@ngxs/store'; | ||
import { ArchiveTask, PinTask } from '../state/task.state'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-task-list', | ||
template: ` | ||
<div class="list-items"> | ||
<app-task | ||
*ngFor="let task of tasksInOrder" | ||
[task]="task" | ||
(onArchiveTask)="onArchiveTask.emit($event)" | ||
(onPinTask)="onPinTask.emit($event)" | ||
> | ||
</app-task> | ||
<div | ||
*ngIf="tasksInOrder.length === 0 && !loading" | ||
class="wrapper-message" | ||
> | ||
<span class="icon-check"></span> | ||
<p class="title-message">You have no tasks</p> | ||
<p class="subtitle-message">Sit back and relax</p> | ||
</div> | ||
<div *ngIf="loading"> | ||
<div *ngFor="let i of [1, 2, 3, 4, 5, 6]" class="loading-item"> | ||
<span class="glow-checkbox"></span> | ||
<span class="glow-text"> | ||
<span>Loading</span> <span>cool</span> <span>state</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<app-pure-task-list | ||
[tasks]="tasks$ | async" | ||
(onArchiveTask)="archiveTask($event)" | ||
(onPinTask)="pinTask($event)" | ||
></app-pure-task-list> | ||
`, | ||
}) | ||
export default class TaskListComponent { | ||
/** | ||
* @ignore | ||
* Component property to define ordering of tasks | ||
*/ | ||
tasksInOrder: Task[] = []; | ||
tasks$?: Observable<any>; | ||
|
||
/** Checks if it's in loading state */ | ||
@Input() loading = false; | ||
|
||
/** Event to change the task to pinned */ | ||
// tslint:disable-next-line: no-output-on-prefix | ||
@Output() | ||
onPinTask = new EventEmitter<Event>(); | ||
constructor(private store: Store) { | ||
this.tasks$ = store.select((state) => state.taskbox.tasks); | ||
} | ||
|
||
/** Event to change the task to archived */ | ||
// tslint:disable-next-line: no-output-on-prefix | ||
@Output() | ||
onArchiveTask = new EventEmitter<Event>(); | ||
/** | ||
* Component method to trigger the archiveTask event | ||
*/ | ||
archiveTask(id: string) { | ||
this.store.dispatch(new ArchiveTask(id)); | ||
} | ||
|
||
@Input() | ||
set tasks(arr: Task[]) { | ||
const initialTasks = [ | ||
...arr.filter((t) => t.state === 'TASK_PINNED'), | ||
...arr.filter((t) => t.state !== 'TASK_PINNED'), | ||
]; | ||
const filteredTasks = initialTasks.filter( | ||
(t) => t.state === 'TASK_INBOX' || t.state === 'TASK_PINNED' | ||
); | ||
this.tasksInOrder = filteredTasks.filter( | ||
(t) => t.state === 'TASK_INBOX' || t.state === 'TASK_PINNED' | ||
); | ||
/** | ||
* Component method to trigger the pinTask event | ||
*/ | ||
pinTask(id: string) { | ||
this.store.dispatch(new PinTask(id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { NgxsModule } from '@ngxs/store'; | ||
|
||
import TaskComponent from './task.component'; | ||
import TaskListComponent from './task-list.component'; | ||
import { TasksState } from '../state/task.state'; | ||
import PureTaskListComponent from './pure-task-list.component'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, NgxsModule.forFeature([TasksState])], | ||
exports: [TaskComponent, TaskListComponent], | ||
declarations: [TaskComponent, TaskListComponent, PureTaskListComponent], | ||
providers: [], | ||
}) | ||
export class TaskModule {} |
Oops, something went wrong.