-
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: add ability to add or remove ingredients from within a cocktail…
… recipe (#408) * feat: add ability to add or remove ingredients from within a cocktail recipe * fix * fix
- Loading branch information
1 parent
ae81125
commit e29f233
Showing
20 changed files
with
246 additions
and
16 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
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,47 @@ | ||
describe('Manage Ingredient Row', () => { | ||
beforeEach(() => { | ||
window.localStorage.clear(); | ||
window.localStorage.setItem('CapacitorStorage.messuarement-system', 'Metric'); | ||
}); | ||
|
||
it('Add to Saved Ingredients', () => { | ||
cy.visit('#/cocktails'); | ||
|
||
cy.dataCy('cocktails-wrapper').children().first().click(); | ||
|
||
cy.dataCy(['ingredient-group-0', 'ingredient-group-checkmark']).should('not.exist'); | ||
|
||
cy.dataCy('ingredient-group-0').trigger('mousedown'); | ||
cy.dataCy('manage-ingredient-row-dialog').should('be.visible'); | ||
|
||
cy.dataCy('toggle-ingredient-storage-status-button').should('include.text', 'Add to Bar'); | ||
cy.dataCy('toggle-ingredient-storage-status-button').click(); | ||
|
||
cy.dataCy('manage-ingredient-row-dialog').should('not.exist'); | ||
|
||
cy.dataCy(['ingredient-group-0', 'ingredient-group-checkmark']).should('be.visible'); | ||
}); | ||
|
||
it('Remove from Saved Ingredients', () => { | ||
window.localStorage.setItem( | ||
'CapacitorStorage.ingredient-lists', | ||
JSON.stringify([{ id: 0, ingredients: ['1'], name: 'My Bar' }]) | ||
); | ||
|
||
cy.visit('#/cocktails'); | ||
|
||
cy.dataCy('cocktails-wrapper').children().first().click(); | ||
|
||
cy.dataCy(['ingredient-group-0', 'ingredient-group-checkmark']).should('be.visible'); | ||
|
||
cy.dataCy('ingredient-group-0').trigger('mousedown'); | ||
cy.dataCy('manage-ingredient-row-dialog').should('be.visible'); | ||
|
||
cy.dataCy('toggle-ingredient-storage-status-button').should('include.text', 'Remove from Bar'); | ||
cy.dataCy('toggle-ingredient-storage-status-button').click(); | ||
|
||
cy.dataCy('manage-ingredient-row-dialog').should('not.exist'); | ||
|
||
cy.dataCy(['ingredient-group-0', 'ingredient-group-checkmark']).should('not.exist'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
Cypress.Commands.add('dataCy', value => { | ||
return cy.get(`[data-cy=${value}]`); | ||
Cypress.Commands.add('dataCy', input => { | ||
if (typeof input === 'string') { | ||
return cy.get(`[data-cy=${input}]`); | ||
} | ||
|
||
const dataCySelectorArray = input.map(x => `[data-cy=${x}]`); | ||
const stringValue = dataCySelectorArray.join(' '); | ||
return cy.get(stringValue); | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
declare namespace Cypress { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/consistent-type-definitions | ||
interface Chainable<Subject> { | ||
dataCy(value: string): Chainable<unknown>; | ||
dataCy(value: string | string[]): Chainable<unknown>; | ||
} | ||
} |
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 @@ | ||
• You can now add or remove ingredients from selected bar within a cocktail recipe. A new menu will appear after a long press the ingredient | ||
• Added more ingredients | ||
|
||
• Updated swedish translations | ||
• Updated german translations |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
27 changes: 27 additions & 0 deletions
27
src/components/dialogs/cocktail-dialog/manage-ingredient-row.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,27 @@ | ||
<template> | ||
<ux-dialog class="small-dialog" data-cy="manage-ingredient-row-dialog"> | ||
<div click.delegate="cancel()"> | ||
<div click.delegate="$event.stopPropagation()" class="bg-base-100 modal-box relative m-auto p-4"> | ||
<label class="btn btn-sm btn-circle absolute right-2 top-2" click.trigger="cancel()">✕</label> | ||
<h3 class="text-lg font-bold">${name}</h3> | ||
<p if.bind="showBarName" class="text-sm text-base-content text-opacity-75">${selectedBarName}</p> | ||
|
||
<div class="divider mt-2"></div> | ||
|
||
<button | ||
click.delegate="toggleIngredientStorageStatus()" | ||
class="btn w-full" | ||
data-cy="toggle-ingredient-storage-status-button"> | ||
<p if.bind="isInStorage" t="remove-from-bar"></p> | ||
<p else t="add-to-bar"></p> | ||
</button> | ||
|
||
<button click.delegate="copyToClipboard()" class="btn w-full mt-4" data-cy="copy-to-clipboard-button"> | ||
<p if.bind="!textCopied" t="copy-ingredient-name-to-clipboard"></p> | ||
<p else class="text-success" t="copied-to-clipboard"></p> | ||
<icon-clipboard class="h-6 w-6 ${textCopied ? 'text-success' : ''}"></icon-clipboard> | ||
</button> | ||
</div> | ||
</div> | ||
</ux-dialog> | ||
</template> |
76 changes: 76 additions & 0 deletions
76
src/components/dialogs/cocktail-dialog/manage-ingredient-row.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,76 @@ | ||
import { DialogController } from 'aurelia-dialog'; | ||
import { autoinject } from 'aurelia-framework'; | ||
import { ExtendedIngredientGroup } from 'domain/entities/cocktail'; | ||
import { LocalStorageService } from 'services/local-storage-service'; | ||
import { Clipboard } from '@capacitor/clipboard'; | ||
|
||
@autoinject | ||
export class ManageIngredientRow { | ||
constructor( | ||
private dialogController: DialogController, | ||
private localStorageService: LocalStorageService | ||
) {} | ||
|
||
public name: string; | ||
public isInStorage: boolean; | ||
public selectedBarName: string; | ||
public showBarName: boolean; | ||
public textCopied = false; | ||
private _ingredientId: string; | ||
private _savedIngredientIds: string[] = []; | ||
|
||
activate(params: ExtendedIngredientGroup) { | ||
this.isInStorage = params.isInStorage; | ||
this.name = params.ingredient.name; | ||
|
||
const selectedBar = this.localStorageService.getIngredientList(); | ||
this.selectedBarName = selectedBar.name; | ||
this._savedIngredientIds = selectedBar.ingredients; | ||
|
||
this.showBarName = this.localStorageService.getIngredientLists().length > 1; | ||
|
||
this._ingredientId = params.ingredient.id; | ||
} | ||
|
||
cancel() { | ||
this.dialogController.cancel(); | ||
} | ||
|
||
async toggleIngredientStorageStatus() { | ||
this.isInStorage = !this.isInStorage; | ||
|
||
if (this.isInStorage === true) { | ||
this._savedIngredientIds.push(this._ingredientId); | ||
} else { | ||
this._savedIngredientIds = this._savedIngredientIds.filter(x => x !== this._ingredientId); | ||
} | ||
|
||
await this.localStorageService.updateSavedIngredients(this._savedIngredientIds); | ||
|
||
const response: ManageIngredientRowResponse = { | ||
isInStorage: this.isInStorage | ||
}; | ||
|
||
this.dialogController.ok(response); | ||
} | ||
|
||
async copyToClipboard() { | ||
if (this.textCopied === true) { | ||
return; | ||
} | ||
|
||
await Clipboard.write({ | ||
string: this.name | ||
}); | ||
|
||
this.textCopied = true; | ||
|
||
setTimeout(() => { | ||
this.textCopied = false; | ||
}, 3000); | ||
} | ||
} | ||
|
||
export type ManageIngredientRowResponse = { | ||
isInStorage: boolean; | ||
}; |
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,21 @@ | ||
<template> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> | ||
<path | ||
d="M336 64h32a48 48 0 0148 48v320a48 48 0 01-48 48H144a48 48 0 01-48-48V112a48 48 0 0148-48h32" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-linejoin="round" | ||
stroke-width="32" /> | ||
<rect | ||
x="176" | ||
y="32" | ||
width="160" | ||
height="64" | ||
rx="26.13" | ||
ry="26.13" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-linejoin="round" | ||
stroke-width="32" /> | ||
</svg> | ||
</template> |
Oops, something went wrong.