Skip to content

Commit

Permalink
Changing to onPush for bean-information which makes it much more "per…
Browse files Browse the repository at this point in the history
…formant"
  • Loading branch information
graphefruit committed Nov 23, 2024
1 parent 292a1e9 commit 429b074
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/components/bean-information/bean-information.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
Expand Down Expand Up @@ -47,6 +48,7 @@ import { BEAN_FUNCTION_PIPE_ENUM } from '../../enums/beans/beanFunctionPipe';
selector: 'bean-information',
templateUrl: './bean-information.component.html',
styleUrls: ['./bean-information.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BeanInformationComponent implements OnInit {
@Input() public bean: Bean;
Expand Down Expand Up @@ -90,7 +92,7 @@ export class BeanInformationComponent implements OnInit {
private readonly platform: Platform,
private readonly uiBrewHelper: UIBrewHelper,
private actionSheetCtrl: ActionSheetController,
private readonly currencyService: CurrencyService
private readonly currencyService: CurrencyService,
) {
this.settings = this.uiSettingsStorage.getSettings();
}
Expand Down Expand Up @@ -127,7 +129,7 @@ export class BeanInformationComponent implements OnInit {

public getBrewCounts(): number {
const relatedBrews: Array<Brew> = this.uiBeanHelper.getAllBrewsForThisBean(
this.bean.config.uuid
this.bean.config.uuid,
);
return relatedBrews.length;
}
Expand All @@ -149,7 +151,7 @@ export class BeanInformationComponent implements OnInit {
public getUsedWeightCount(): number {
let usedWeightCount: number = 0;
const relatedBrews: Array<Brew> = this.uiBeanHelper.getAllBrewsForThisBean(
this.bean.config.uuid
this.bean.config.uuid,
);
for (const brew of relatedBrews) {
if (brew.bean_weight_in > 0) {
Expand Down Expand Up @@ -185,7 +187,7 @@ export class BeanInformationComponent implements OnInit {
event.stopImmediatePropagation();
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.POPOVER_ACTIONS
BEAN_TRACKING.ACTIONS.POPOVER_ACTIONS,
);
const popover = await this.modalController.create({
component: BeanPopoverActionsComponent,
Expand Down Expand Up @@ -276,7 +278,7 @@ export class BeanInformationComponent implements OnInit {
private async viewPhotos() {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.PHOTO_VIEW
BEAN_TRACKING.ACTIONS.PHOTO_VIEW,
);
await this.uiImage.viewPhotos(this.bean);
}
Expand All @@ -294,7 +296,7 @@ export class BeanInformationComponent implements OnInit {
public async unarchiveBean() {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.UNARCHIVE
BEAN_TRACKING.ACTIONS.UNARCHIVE,
);
this.bean.finished = false;
await this.uiBeanStorage.update(this.bean);
Expand All @@ -319,14 +321,14 @@ export class BeanInformationComponent implements OnInit {
if (!this.bean.favourite) {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.ADD_FAVOURITE
BEAN_TRACKING.ACTIONS.ADD_FAVOURITE,
);
this.uiToast.showInfoToast('TOAST_BEAN_FAVOURITE_ADDED');
this.bean.favourite = true;
} else {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.REMOVE_FAVOURITE
BEAN_TRACKING.ACTIONS.REMOVE_FAVOURITE,
);
this.bean.favourite = false;
this.uiToast.showInfoToast('TOAST_BEAN_FAVOURITE_REMOVED');
Expand Down Expand Up @@ -358,7 +360,7 @@ export class BeanInformationComponent implements OnInit {
public async shareBeanImage() {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.SHARE_IMAGE
BEAN_TRACKING.ACTIONS.SHARE_IMAGE,
);
await this.uiAlert.showLoadingSpinner();
if (this.platform.is('ios')) {
Expand Down Expand Up @@ -405,13 +407,13 @@ export class BeanInformationComponent implements OnInit {

public async repeatLastOrBestBrew() {
let associatedBrews: Array<Brew> = this.uiBeanHelper.getAllBrewsForThisBean(
this.bean.config.uuid
this.bean.config.uuid,
);
associatedBrews = associatedBrews.filter(
(e) =>
e.getBean().finished === false &&
e.getMill().finished === false &&
e.getPreparation().finished === false
e.getPreparation().finished === false,
);
let hasBestBrews: boolean = false;
if (associatedBrews.length > 0) {
Expand All @@ -436,7 +438,7 @@ export class BeanInformationComponent implements OnInit {
text: this.translate.instant('REPEAT_BEST_BREW'),
handler: async () => {
const bestBrew = associatedBrews.filter(
(b) => b.best_brew === true
(b) => b.best_brew === true,
)[0];
await this.uiBrewHelper.repeatBrew(bestBrew);
},
Expand All @@ -460,20 +462,19 @@ export class BeanInformationComponent implements OnInit {
try {
const _scannedQRBean: ServerBean =
await this.serverCommunicationService.getBeanInformation(
this.bean.qr_code
this.bean.qr_code,
);
if (_scannedQRBean.error === null) {
this.uiAnalytics.trackEvent(
QR_TRACKING.TITLE,
QR_TRACKING.ACTIONS.REFRESH_SUCCESSFULLY
QR_TRACKING.ACTIONS.REFRESH_SUCCESSFULLY,
);
this.uiToast.showInfoToast('QR.BEAN_SUCCESSFULLY_REFRESHED');
await this.uiAlert.showLoadingSpinner();
// Get the new bean from server, just save the uuid, all other information will be overwritten
const newMapper = new BeanMapper();
const newBean: Bean = await newMapper.mapServerToClientBean(
_scannedQRBean
);
const newBean: Bean =
await newMapper.mapServerToClientBean(_scannedQRBean);
const savedUUID = this.bean.config.uuid;
this.bean = newBean;
this.bean.config.uuid = savedUUID;
Expand All @@ -490,11 +491,11 @@ export class BeanInformationComponent implements OnInit {
'QR.SERVER.ERROR_OCCURED',
'ERROR_OCCURED',
undefined,
true
true,
);
}
},
() => {}
() => {},
);
}

Expand All @@ -508,7 +509,7 @@ export class BeanInformationComponent implements OnInit {
// Yes
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.DELETE
BEAN_TRACKING.ACTIONS.DELETE,
);
await this.__deleteBean();
this.uiToast.showInfoToast('TOAST_BEAN_DELETED_SUCCESSFULLY');
Expand All @@ -518,7 +519,7 @@ export class BeanInformationComponent implements OnInit {
() => {
// No
reject();
}
},
);
});
}
Expand All @@ -532,7 +533,7 @@ export class BeanInformationComponent implements OnInit {
public async repeatBean() {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.REPEAT
BEAN_TRACKING.ACTIONS.REPEAT,
);
await this.uiBeanHelper.repeatBean(this.bean);
}
Expand All @@ -548,7 +549,7 @@ export class BeanInformationComponent implements OnInit {
}
for (let i = deletingBrewIndex.length; i--; ) {
await this.uiBrewStorage.removeByUUID(
brews[deletingBrewIndex[i]].config.uuid
brews[deletingBrewIndex[i]].config.uuid,
);
}

Expand Down

0 comments on commit 429b074

Please sign in to comment.