Skip to content

Commit

Permalink
feat(home): update last seeds list with count value and details dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
artaommahe committed Aug 31, 2024
1 parent 29dbef7 commit cd60e1f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/app/home/last-seeds-list/last-seeds-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';

import { BarnService } from '../../barn/barn.service';
import { SeedDetailsDialogComponent } from '../../planting/seed-details-dialog/seed-details-dialog.component';
import { type SeedDetailsSeed } from '../../planting/seed-details/seed-details.component';

@Component({
selector: 'app-last-seeds-list',
template: `
<section>
<h2 class="text-lg text-secondary">Last seeds</h2>
<ul class="columns-2 gap-4">
<ul class="flex flex-col gap-2">
@for (seed of lastAddedSeeds(); track seed.name) {
<li class="w-full truncate px-2 py-1">
{{ seed.name }}
<li>
<button class="flex w-full items-center gap-2 px-2 py-1 text-left" (click)="seedDetails.set(seed)">
<span class="grow truncate">{{ seed.name }}</span>
<span class="shrink-0">{{ seed.count }}</span>
</button>
</li>
}
</ul>
</section>
@if (seedDetails(); as seed) {
<app-seed-details-dialog [seed]="seed" (close)="seedDetails.set(null)" />
}
`,
imports: [],
imports: [SeedDetailsDialogComponent],
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand All @@ -30,6 +39,7 @@ export class LastSeedsListComponent {
?.toSorted((a, b) => b.lastAddedAt.localeCompare(a.lastAddedAt))
.slice(0, lastSeedsCount),
);
seedDetails = signal<SeedDetailsSeed | null>(null);
}

const lastSeedsCount = 10;

0 comments on commit cd60e1f

Please sign in to comment.