Make app work again
This commit is contained in:
parent
a9ad628488
commit
938f3def1f
1 changed files with 235 additions and 154 deletions
|
|
@ -3,44 +3,39 @@ import { lighten } from '../utils/color';
|
|||
import { Block } from './block';
|
||||
import { Serializable } from './serializable';
|
||||
import { hash } from '../utils/hash';
|
||||
import { Node } from '../storage/node';
|
||||
import { IColor } from '../interfaces/persistance/color';
|
||||
import { Node } from '../store/node';
|
||||
import { IColor } from '../interfaces/color';
|
||||
|
||||
export type ColoredBlock = Block & { color: IColor };
|
||||
|
||||
export class Tower extends Serializable implements ITower {
|
||||
constructor(parent: Node, props: ITower) {
|
||||
super(parent, props);
|
||||
|
||||
this.blocks.sort((a, b) => a.created.getTime() - b.created.getTime());
|
||||
this.calculateTagList();
|
||||
}
|
||||
|
||||
tags: string[];
|
||||
|
||||
// Only here to prevent ts warnings.
|
||||
name: string;
|
||||
type: 'Tower';
|
||||
|
||||
get blocks(): Array<Block> {
|
||||
return this.children as Array<Block>;
|
||||
}
|
||||
baseColor: IColor;
|
||||
|
||||
get coloredBlocks(): Array<Block & { color: IColor }> {
|
||||
return this.children.map(b => {
|
||||
const coloredBlock = b as Block & { color: IColor };
|
||||
coloredBlocks: Array<ColoredBlock>;
|
||||
|
||||
readonly baseColor: IColor;
|
||||
|
||||
constructor(parent: Node, props: ITower) {
|
||||
super(parent, props);
|
||||
this.onAfterClone();
|
||||
}
|
||||
|
||||
protected onAfterClone(): void {
|
||||
this.blocks.sort((a, b) => {
|
||||
return a.created.getTime() - b.created.getTime();
|
||||
});
|
||||
|
||||
this.coloredBlocks = this.blocks.map(b => {
|
||||
const coloredBlock = b as ColoredBlock;
|
||||
coloredBlock.color = lighten((hash(coloredBlock.tag) - 0.5) * 50, this.baseColor);
|
||||
return coloredBlock;
|
||||
});
|
||||
}
|
||||
|
||||
addBlock(props: { tag: string; description: string; isDone: boolean }) {
|
||||
new Block(this, {
|
||||
created: new Date(),
|
||||
...props,
|
||||
type: 'Block'
|
||||
});
|
||||
}
|
||||
|
||||
private calculateTagList() {
|
||||
this.tags = [];
|
||||
for (const block of this.blocks) {
|
||||
if (!this.tags.includes(block.tag)) {
|
||||
|
|
@ -48,4 +43,17 @@ export class Tower extends Serializable implements ITower {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
addBlock(props: { tag: string; description: string; isDone: boolean }) {
|
||||
new Block(this, {
|
||||
created: new Date(),
|
||||
...props
|
||||
});
|
||||
}
|
||||
|
||||
changeName(newName: string) {
|
||||
// For optimization purposes.
|
||||
this.name = newName;
|
||||
this.mutatedUpdate();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue