Skip to content

Commit 14b4f1a

Browse files
Finish fixing types
1 parent 8093409 commit 14b4f1a

4 files changed

Lines changed: 42 additions & 24 deletions

File tree

app/components/colors-list.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { fadeOut } from 'ember-animated/motions/opacity';
99
import type { Store } from 'ember-orbit';
1010

1111
import type { RecordOperationTerm } from '@orbit/records';
12+
import { TrackedArray } from 'tracked-built-ins';
1213

1314
import 'swach/components/color-row';
1415
import type ColorModel from 'swach/data-models/color';
@@ -31,9 +32,12 @@ export default class ColorsListComponent extends Component<ColorsListSignature>
3132

3233
if (!palette.$isDisconnected) {
3334
if (palette.isColorHistory) {
34-
return palette.colors.sortBy('createdAt').reverse();
35+
return palette.colors.sort(
36+
(a, b) =>
37+
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
38+
);
3539
} else {
36-
return palette.colorOrder.map((color: ColorModel) => {
40+
return palette.colorOrder.map((color: { type: string; id: string }) => {
3741
return palette.colors.find((c) => c.id === color.id);
3842
});
3943
}
@@ -73,14 +77,16 @@ export default class ColorsListComponent extends Component<ColorsListSignature>
7377
const { palette } = this.args;
7478

7579
if (color && palette && !palette.isLocked) {
76-
const colorsList = palette.colors.map((color) => {
77-
return { type: 'color', id: color.id };
78-
});
80+
const colorsList = new TrackedArray<{ type: string; id: string }>(
81+
palette.colors.map((color) => {
82+
return { type: 'color', id: color.id };
83+
}),
84+
);
7985

8086
const colorToRemove = colorsList.find((c) => c.id === color.id);
8187

8288
if (colorToRemove) {
83-
colorsList.removeObject(colorToRemove);
89+
colorsList.splice(colorsList.indexOf(colorToRemove), 1);
8490

8591
await this.store.update((t) => {
8692
const operations: RecordOperationTerm[] = [

app/components/kuler.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class KulerComponent extends Component<KulerSignature> {
8686
async (_event: unknown, color) => {
8787
await this._onColorChange(color);
8888
this.colorPicker.setColors(
89-
this.selectedPalette.colors.mapBy('hex'),
89+
this.selectedPalette.colors.map((color: ColorModel) => color.hex),
9090
this.selectedPalette.selectedColorIndex,
9191
);
9292
},
@@ -137,8 +137,9 @@ export default class KulerComponent extends Component<KulerSignature> {
137137

138138
@action
139139
setColorAsBase(): Promise<void> {
140-
this.baseColor =
141-
this.selectedPalette.colors[this.selectedPalette.selectedColorIndex];
140+
this.baseColor = this.selectedPalette.colors[
141+
this.selectedPalette.selectedColorIndex
142+
] as ColorModel;
142143

143144
return this.baseColorChanged(
144145
this.palettes.indexOf(this.selectedPalette),
@@ -165,7 +166,7 @@ export default class KulerComponent extends Component<KulerSignature> {
165166
@action
166167
setSelectedPalette(event: InputEvent): void {
167168
const paletteName = (<HTMLInputElement>event.target).value;
168-
const palette = this.palettes.findBy('name', paletteName);
169+
const palette = this.palettes.find((p: Palette) => p.name === paletteName);
169170

170171
if (palette) {
171172
this.selectedPalette = palette;
@@ -189,13 +190,15 @@ export default class KulerComponent extends Component<KulerSignature> {
189190
color instanceof iro.Color ? color.rgba : color,
190191
);
191192

192-
this.selectedPalette.colors.replace(selectedColorIndex, 1, [
193-
newColor.attributes,
194-
]);
193+
this.selectedPalette.colors.splice(
194+
selectedColorIndex,
195+
1,
196+
...[newColor.attributes as unknown as ColorModel],
197+
);
195198

196199
if (selectedColorIndex === 0) {
197200
this.baseColor =
198-
this.selectedPalette.colors[this.selectedPalette.selectedColorIndex];
201+
this.selectedPalette.colors[this.selectedPalette.selectedColorIndex] as ColorModel;
199202
await this.setColorAsBase();
200203
}
201204

@@ -219,7 +222,9 @@ export default class KulerComponent extends Component<KulerSignature> {
219222
this.colorPicker = (iro.ColorPicker as any)(
220223
'#kuler-color-picker-container',
221224
{
222-
colors: this.selectedPalette.colors.map((color: ColorModel) => color.hex),
225+
colors: this.selectedPalette.colors.map(
226+
(color: ColorModel) => color.hex,
227+
),
223228
layoutDirection: 'horizontal',
224229
layout: [
225230
{

app/components/palettes-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export default class PalettesListComponent extends Component<PalettesListSignatu
6363

6464
const movedItem = sourceList[sourceIndex] as PaletteModel;
6565

66-
sourceList.removeAt(sourceIndex);
67-
targetList.insertAt(targetIndex, movedItem);
66+
sourceList.splice(sourceIndex, 1);
67+
targetList.splice(targetIndex, 0, movedItem);
6868

6969
await this.store.update((t) => {
7070
const operations: RecordOperationTerm[] = [];

app/controllers/palettes.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export default class PalettesController extends Controller {
3434
if (colorHistory) {
3535
return colorHistory.colors
3636
.slice()
37-
.sortBy('createdAt')
38-
.reverse()
37+
.sort(
38+
(a, b) =>
39+
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
40+
)
3941
.slice(0, 16);
4042
} else {
4143
return [];
@@ -175,7 +177,7 @@ export default class PalettesController extends Controller {
175177
const colorToRemove = colorsList.find((c) => c.id === existingColor.id);
176178

177179
if (colorToRemove) {
178-
colorsList.removeObject(colorToRemove);
180+
colorsList.splice(colorsList.indexOf(colorToRemove), 1);
179181
}
180182
}
181183

@@ -215,7 +217,7 @@ export default class PalettesController extends Controller {
215217
const colorToMove = sourceColorList.find((c) => c.id === sourceColor.id);
216218

217219
if (colorToMove) {
218-
sourceColorList.removeObject(colorToMove);
220+
sourceColorList.splice(sourceColorList.indexOf(colorToMove), 1);
219221
sourceColorList.splice(targetIndex, 0, colorToMove);
220222

221223
await this.store.update((t) =>
@@ -235,11 +237,13 @@ export default class PalettesController extends Controller {
235237
targetIndex: number,
236238
targetPalette: PaletteModel,
237239
): Promise<void> {
238-
const sourceColorOrder = sourceList.map((c) => c.$identity);
240+
const sourceColorOrder = new TrackedArray(
241+
sourceList.map((c) => c.$identity),
242+
);
239243
const colorToRemove = sourceColorOrder.find((c) => c.id === sourceColor.id);
240244

241245
if (colorToRemove) {
242-
sourceColorOrder.removeObject(colorToRemove);
246+
sourceColorOrder.splice(sourceColorOrder.indexOf(colorToRemove), 1);
243247

244248
await this.store.update((t) => {
245249
const operations: RecordOperationTerm[] = [
@@ -271,7 +275,10 @@ export default class PalettesController extends Controller {
271275
insertIndex--;
272276
}
273277

274-
targetColorOrder.removeObject(colorToRemove);
278+
targetColorOrder.splice(
279+
targetColorOrder.indexOf(colorToRemove),
280+
1,
281+
);
275282
}
276283

277284
t.removeFromRelatedRecords(targetPalette, 'colors', existingColor);

0 commit comments

Comments
 (0)