Skip to content

Commit

Permalink
feat: remember last selected bar (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-gustafsson authored Oct 16, 2023
1 parent 571cc60 commit 7e87d0f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.moimob.drinkable"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 13901
versionName "1.39.1"
versionCode 14000
versionName "1.40.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/14000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
• Last selected bar will now load when restaring the app

• Updated swedish translations
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ <h6 if.bind="ingredientGroup.substituteNames" class="text-sm opacity-75">
<svg
if.bind="ingredientGroup.isInStorage"
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6 text-success"
class="w-6 h-6 text-success ${ingredientGroup.isChecked ? 'opacity-50' : ''}"
stroke="currentColor"
viewBox="0 0 512 512">
<title>Checkmark</title>
Expand Down
1 change: 1 addition & 0 deletions src/domain/entities/setting-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export class SettingEntity {
language?: string;
showMocktails: boolean;
exploreWidgetState?: number;
lastSelectedIngredientListId?: number;

constructor() {
this.showMocktails = false;
Expand Down
9 changes: 6 additions & 3 deletions src/modules/user/ingredient-lists/ingredient-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export class IngredientLists {
public ingredientLists: IngredientList[] = [];
public activeIngredientListId: number;

constructor(private _dialogService: DialogService, private localStorageService: LocalStorageService) {}
constructor(
private _dialogService: DialogService,
private localStorageService: LocalStorageService
) {}

bind() {
this.ingredientLists = this.localStorageService.getIngredientLists();
Expand All @@ -19,11 +22,11 @@ export class IngredientLists {
openDialog(ingredientList: IngredientList) {
this._dialogService
.open({ viewModel: IngredientListDrawer, model: ingredientList, lock: true })
.whenClosed(() => {
.whenClosed(async () => {
this.activeIngredientListId =
this.localStorageService.getIngredientLists().find(x => x.id === this.activeIngredientListId)?.id ??
0;
this.localStorageService.setActiveIngredientListId(this.activeIngredientListId);
await this.localStorageService.setActiveIngredientListId(this.activeIngredientListId);
this.bind();
});
}
Expand Down
9 changes: 6 additions & 3 deletions src/modules/user/user-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ export class UserPage {
@observable public selectedIngredientListId: number;
public ingredientLists: IngredientList[];

constructor(private _router: Router, private _localStorageService: LocalStorageService) {}
constructor(
private _router: Router,
private _localStorageService: LocalStorageService
) {}

activate() {
this.ingredientLists = this._localStorageService.getIngredientLists();
this.selectedIngredientListId = this._localStorageService.getActiveIngredientListId();
}

selectedIngredientListIdChanged(newValue: number, oldValue: number) {
async selectedIngredientListIdChanged(newValue: number, oldValue: number) {
if (oldValue === undefined) {
return;
}

this._localStorageService.setActiveIngredientListId(newValue);
await this._localStorageService.setActiveIngredientListId(newValue);
}

navigateToRoute(route: string) {
Expand Down
9 changes: 6 additions & 3 deletions src/services/local-storage-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export class LocalStorageService {
await this.addDefaultIngredientList([]);
}

this._activeIngredientListId = this._ingredientLists[0].id;

const messuarementSystem = await this.getFromLocalStorage(StorageKey.MessuarementSystem, false);
this._messuarementSystem = messuarementSystem !== null ? messuarementSystem : MessuarementSystem.Imperial;

Expand All @@ -48,6 +46,8 @@ export class LocalStorageService {
const settings = await this.getFromLocalStorage(StorageKey.Settings);
this._settings = settings !== null ? settings : new SettingEntity();

this._activeIngredientListId = this._settings.lastSelectedIngredientListId ?? this._ingredientLists[0].id;

const cocktailInformation = await this.getFromLocalStorage(StorageKey.CocktailInformation);
this._cocktailInformation = cocktailInformation !== null ? cocktailInformation : [];

Expand Down Expand Up @@ -247,7 +247,10 @@ export class LocalStorageService {
return this._shoppingLists;
}

public setActiveIngredientListId(id: number) {
public async setActiveIngredientListId(id: number) {
this._settings.lastSelectedIngredientListId = id;
await this.updateSettings(this._settings);

this._activeIngredientListId = id;
}

Expand Down

0 comments on commit 7e87d0f

Please sign in to comment.