-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create multiple lists of ingredients (#369)
- Loading branch information
1 parent
1faf1af
commit e374345
Showing
28 changed files
with
466 additions
and
52 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
• Added support for multiple lists of ingredients |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<svg xmlns="http://www.w3.org/2000/svg" stroke="currentColor" viewBox="0 0 512 512"> | ||
<title>Arrow Forward</title> | ||
<path | ||
fill="none" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="48" | ||
d="M268 112l144 144-144 144M392 256H100" /> | ||
</svg> | ||
</template> |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type IngredientList = { | ||
id: number; | ||
name: string; | ||
ingredients: string[]; | ||
}; |
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
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
3 changes: 3 additions & 0 deletions
3
src/modules/ingredients/search-ingredients/search-ingredients.html
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
5 changes: 2 additions & 3 deletions
5
src/modules/ingredients/search-ingredients/search-ingredients.ts
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
9 changes: 9 additions & 0 deletions
9
src/modules/ingredients/selected-ingredients-list-component.html
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,9 @@ | ||
<template> | ||
<div if.bind="showSelectedIngredientList" class="my-4 mx-2 flex" data-cy="selected-bar-component"> | ||
<p class="text-sm"><span t="user.selected-ingredient-list"></span><span>:</span></p> | ||
|
||
<p click.delegate="navigateToUserPage()" class="ml-2 text-sm link link-info" data-cy="selected-bar-name"> | ||
${ingredientListName} | ||
</p> | ||
</div> | ||
</template> |
20 changes: 20 additions & 0 deletions
20
src/modules/ingredients/selected-ingredients-list-component.ts
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,20 @@ | ||
import { autoinject } from 'aurelia-framework'; | ||
import { Router } from 'aurelia-router'; | ||
import { LocalStorageService } from 'services/local-storage-service'; | ||
|
||
@autoinject | ||
export class SelectedIngredientsListComponent { | ||
public ingredientListName: string; | ||
public showSelectedIngredientList = false; | ||
|
||
constructor(private _localStorageService: LocalStorageService, private _router: Router) {} | ||
|
||
bind() { | ||
this.ingredientListName = this._localStorageService.getIngredientList().name; | ||
this.showSelectedIngredientList = this._localStorageService.getIngredientLists().length > 1; | ||
} | ||
|
||
navigateToUserPage() { | ||
this._router.navigateToRoute('user'); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/modules/user/ingredient-lists/ingredient-list-drawer.html
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,40 @@ | ||
<template> | ||
<ux-dialog class="au-animate cocktail-dialog" data-cy="user-ingredient-lists-drawer"> | ||
<div class="grid full-dynamic-height overflow-y-scroll"> | ||
<div class="min-h-8" click.trigger="cancel()"></div> | ||
<div class="menu p-3 bg-base-100 text-base-content w-full relative overflow-y-scroll"> | ||
<label class="btn btn-sm btn-circle absolute right-2 top-2" click.trigger="cancel()">✕</label> | ||
<h3 | ||
class="text-lg font-bold" | ||
t="${isNew ? 'user.create-ingredient-list' : 'user.edit-ingredient-list'}"></h3> | ||
|
||
<div class="form-control w-full" validation-errors.bind="nameErrors"> | ||
<label class="label"> | ||
<span class="label-text" t="name"></span> | ||
</label> | ||
<input | ||
type="text" | ||
value.bind="name & validate" | ||
class="input input-bordered w-full input-sm" | ||
class.bind="nameErrors.length ? 'input-error' : ''" | ||
data-cy="name-input" /> | ||
<ul style="list-style-position: inside"> | ||
<li repeat.for="errorInfo of nameErrors" class="text-xs">${errorInfo.error.message}</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="absolute bottom-4 flex w-full justify-between px-3 items-end"> | ||
<button | ||
if.bind="!isNew && canDelete" | ||
click.trigger="delete()" | ||
class="btn btn-square" | ||
data-cy="ingredient-list-delete"> | ||
<icon-trash class="h-6 w-6"></icon-trash> | ||
</button> | ||
<div else></div> | ||
|
||
<label class="btn btn-primary" click.trigger="ok()" t="save" data-cy="drawer-ok"></label> | ||
</div> | ||
</div> | ||
</ux-dialog> | ||
</template> |
70 changes: 70 additions & 0 deletions
70
src/modules/user/ingredient-lists/ingredient-list-drawer.ts
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,70 @@ | ||
import { inject, NewInstance } from 'aurelia-framework'; | ||
import { DialogController } from 'aurelia-dialog'; | ||
import { ValidationController, ValidationRules } from 'aurelia-validation'; | ||
import { LocalStorageService } from 'services/local-storage-service'; | ||
import { IngredientList } from 'domain/entities/ingredient-list'; | ||
|
||
@inject(DialogController, NewInstance.of(ValidationController), LocalStorageService) | ||
export class IngredientListDrawer { | ||
public name: string; | ||
public isNew: boolean = true; | ||
public canDelete: boolean = false; | ||
|
||
private ingredientList: IngredientList; | ||
|
||
constructor( | ||
private _dialogController: DialogController, | ||
private _validationController: ValidationController, | ||
private localStorageService: LocalStorageService | ||
) { | ||
ValidationRules.ensure('name').required().withMessage('Name is required').on(this); | ||
} | ||
|
||
activate(ingredientList: IngredientList) { | ||
if (ingredientList !== null) { | ||
this.ingredientList = ingredientList; | ||
this.name = ingredientList.name; | ||
this.isNew = false; | ||
if (this.ingredientList.id !== 0) { | ||
this.canDelete = true; | ||
} | ||
} | ||
} | ||
|
||
cancel() { | ||
this._dialogController.cancel(); | ||
} | ||
|
||
async ok() { | ||
const result = await this._validationController.validate(); | ||
|
||
if (!result.valid) { | ||
return; | ||
} | ||
|
||
if (this.isNew === true) { | ||
await this.localStorageService.createIngredientList(this.name); | ||
this._dialogController.ok(); | ||
return; | ||
} | ||
|
||
const ingredientListToUpdate: IngredientList = { | ||
id: this.ingredientList.id, | ||
name: this.name, | ||
ingredients: this.ingredientList.ingredients | ||
}; | ||
|
||
await this.localStorageService.updateIngredientList(ingredientListToUpdate); | ||
|
||
this._dialogController.ok(); | ||
} | ||
|
||
async delete() { | ||
if (this.isNew === true) { | ||
return; | ||
} | ||
|
||
await this.localStorageService.deleteIngredientList(this.ingredientList.id); | ||
this._dialogController.ok(); | ||
} | ||
} |
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,25 @@ | ||
<template> | ||
<div class="p-4 pt-0"> | ||
<div class="flex justify-end items-center mb-3"> | ||
<button | ||
click.delegate="openDialog(null)" | ||
class="btn btn-secondary" | ||
t="add" | ||
data-cy="add-ingredient-list"></button> | ||
</div> | ||
<div data-cy="created-ingredient-lists-container"> | ||
<div | ||
repeat.for="item of ingredientLists" | ||
click.delegate="openDialog(item)" | ||
class="flex justify-between items-center p-4 border-b border-base-content border-opacity-20"> | ||
<div> | ||
<p>${item.name}</p> | ||
<p class="text-xs font-light"> | ||
<span>${item.ingredients.length} </span> <span t="ingredients"></span> | ||
</p> | ||
</div> | ||
<icon-arrow-forward class="h-6 w-6"></icon-arrow-forward> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
Oops, something went wrong.