mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
feat: add deletion
This commit is contained in:
parent
5dab153b1f
commit
4ab25183c7
3 changed files with 42 additions and 31 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import {Model} from '@nozbe/watermelondb';
|
||||
import {field} from '@nozbe/watermelondb/decorators';
|
||||
import {date, field} from '@nozbe/watermelondb/decorators';
|
||||
|
||||
export default class TaskMelon extends Model {
|
||||
static table = 'tasks';
|
||||
|
|
@ -16,8 +16,8 @@ export default class TaskMelon extends Model {
|
|||
// }
|
||||
|
||||
// tslint:disable-next-line
|
||||
@field('title') title;
|
||||
// @date('created') created;
|
||||
@field('title') title: string;
|
||||
@date('created') created;
|
||||
|
||||
// @action async createSpam() {
|
||||
// await this.update(post => {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import LokiJSAdapter from '@nozbe/watermelondb/adapters/lokijs';
|
|||
|
||||
import schema from './schema';
|
||||
import TaskMelon from './task';
|
||||
import {switchMap} from 'rxjs/operators';
|
||||
import {from, merge, Observable} from 'rxjs';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
// First, create the adapter to the underlying database:
|
||||
// const adapter = new SQLiteAdapter({
|
||||
|
|
@ -37,30 +36,34 @@ export class WatermelonService {
|
|||
|
||||
|
||||
private _createCollection(tableName: string) {
|
||||
const col = this.db.collections.get(tableName);
|
||||
console.log(col);
|
||||
const collection = this.db.collections.get(tableName);
|
||||
console.log(collection);
|
||||
return {
|
||||
query: () => col.query().fetch(),
|
||||
query$: (): Observable<any> => merge(
|
||||
from(col.query().fetch()),
|
||||
col.changes.pipe(
|
||||
switchMap(() => col.query().fetch())
|
||||
)
|
||||
),
|
||||
add: (item) => {
|
||||
this.db.action(async () => {
|
||||
await col.create(itemInner => {
|
||||
Object.keys(item).forEach((key) => {
|
||||
if (key !== 'id') {
|
||||
// NOTE: don't know who designed this, but this is how it works
|
||||
itemInner[key] = item[key];
|
||||
}
|
||||
});
|
||||
query: () => collection.query().fetch(),
|
||||
query$: (): Observable<any> => collection.query().observe(),
|
||||
add: (item): Promise<any> => this.db.action(async () => {
|
||||
await collection.create(itemInner => {
|
||||
Object.keys(item).forEach((key) => {
|
||||
if (key !== 'id') {
|
||||
// NOTE: don't know who designed this, but this is how it works
|
||||
itemInner[key] = item[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
update: (itemId: string, changes: any): Promise<any> => this.db.action(async () => {
|
||||
const item = await collection.find(itemId);
|
||||
await item.update(changes);
|
||||
}),
|
||||
remove: (itemId: string): Promise<any> => this.db.action(async () => {
|
||||
console.time('delete');
|
||||
const item = await collection.find(itemId);
|
||||
// await item.destroyPermanently();
|
||||
await item.markAsDeleted();
|
||||
|
||||
console.timeEnd('delete');
|
||||
}),
|
||||
collection,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ import {ProjectService} from '../project/project.service';
|
|||
import {RoundTimeOption} from '../project/project.model';
|
||||
import {Dictionary} from '@ngrx/entity';
|
||||
import {WatermelonService} from '../../core/watermelon/watermelon.service';
|
||||
import {calcTotalTimeSpent} from './util/calc-total-time-spent';
|
||||
|
||||
|
||||
@Injectable({
|
||||
|
|
@ -255,6 +256,7 @@ export class TaskService {
|
|||
private readonly _actions$: Actions,
|
||||
) {
|
||||
this.currentTaskId$.subscribe((val) => this.currentTaskId = val);
|
||||
this.undoneTasks$.subscribe((v) => console.log('undoneTasks$', v));
|
||||
|
||||
// time tracking
|
||||
this._timeTrackingService.tick$
|
||||
|
|
@ -300,7 +302,11 @@ export class TaskService {
|
|||
additionalFields?: Partial<Task>,
|
||||
isAddToBottom = false,
|
||||
) {
|
||||
this._watermelonService.task.add(this.createNewTaskWithDefaults(title, additionalFields));
|
||||
const task = this.createNewTaskWithDefaults(title, additionalFields);
|
||||
this._watermelonService.task.add({
|
||||
...task,
|
||||
timeSpent: calcTotalTimeSpent(task.timeSpentOnDay)
|
||||
});
|
||||
// this._store.dispatch(new AddTask({
|
||||
// task: this.createNewTaskWithDefaults(title, additionalFields),
|
||||
// isAddToBacklog,
|
||||
|
|
@ -326,14 +332,16 @@ export class TaskService {
|
|||
}
|
||||
|
||||
remove(task: TaskWithSubTasks) {
|
||||
this._store.dispatch(new DeleteTask({task}));
|
||||
this._watermelonService.task.remove(task.id);
|
||||
// this._store.dispatch(new DeleteTask({task}));
|
||||
}
|
||||
|
||||
|
||||
update(id: string, changedFields: Partial<Task>) {
|
||||
this._store.dispatch(new UpdateTask({
|
||||
task: {id, changes: this._shortSyntax(changedFields) as Partial<Task>}
|
||||
}));
|
||||
this._watermelonService.task.update(id, changedFields);
|
||||
// this._store.dispatch(new UpdateTask({
|
||||
// task: {id, changes: this._shortSyntax(changedFields) as Partial<Task>}
|
||||
// }));
|
||||
}
|
||||
|
||||
// NOTE: side effects are not executed!!!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue