From 591033f533aa5b3a0dac768fc2935f00b1d71cd6 Mon Sep 17 00:00:00 2001 From: Dominik Schenk Date: Fri, 17 Sep 2021 00:03:42 +0200 Subject: [PATCH] feat: save commit message for later use fixes #32 --- src/app/core/services/store/store.service.ts | 2 +- .../repository-commit.component.ts | 5 +++-- src/app/shared/functions/index.ts | 1 + .../functions/localstorage.decorator.ts | 21 +++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/app/shared/functions/localstorage.decorator.ts diff --git a/src/app/core/services/store/store.service.ts b/src/app/core/services/store/store.service.ts index f262a78..7efcc19 100644 --- a/src/app/core/services/store/store.service.ts +++ b/src/app/core/services/store/store.service.ts @@ -68,7 +68,7 @@ export class StoreService { this.logger.warn(`Tring to create the settings folder ${e}`); this.createDir(path); } - catch (e2) { + catch (e2: any) { this.logger.error(e2); } } diff --git a/src/app/routes/repository/repository-commit/repository-commit.component.ts b/src/app/routes/repository/repository-commit/repository-commit.component.ts index 352b95e..4af9d68 100644 --- a/src/app/routes/repository/repository-commit/repository-commit.component.ts +++ b/src/app/routes/repository/repository-commit/repository-commit.component.ts @@ -8,7 +8,7 @@ import { RepositoryService } from '../repository.service'; import { filter, first } from 'rxjs/operators'; import { interval } from 'rxjs'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import { basename, sleep, LoadingState } from '@shared/functions'; +import { basename, sleep, LoadingState, LocalStorage } from '@shared/functions'; @UntilDestroy() @Component({ @@ -22,7 +22,8 @@ export class RepositoryCommitComponent implements OnInit { fileTree: GroupedChangedFiles = []; formDisabled = false; - commitMessage = ''; + + @LocalStorage('commitMessage') commitMessage: string; private hasStaged = false; isDiffLoading = false; isLoading: LoadingState = 'default'; diff --git a/src/app/shared/functions/index.ts b/src/app/shared/functions/index.ts index 06102d9..f76bcff 100644 --- a/src/app/shared/functions/index.ts +++ b/src/app/shared/functions/index.ts @@ -5,3 +5,4 @@ export * from './diff'; export * from './sleep'; export * from './group'; export * from './sort'; +export * from './localstorage.decorator'; diff --git a/src/app/shared/functions/localstorage.decorator.ts b/src/app/shared/functions/localstorage.decorator.ts new file mode 100644 index 0000000..9c1c023 --- /dev/null +++ b/src/app/shared/functions/localstorage.decorator.ts @@ -0,0 +1,21 @@ +export function LocalStorage(key: string) { + return function (target: any, propertyKey: string) { + if (!propertyKey) { + throw new Error('Property key is required'); + } + const key = propertyKey.toLocaleLowerCase(); + + const getter = function () { + return localStorage.getItem(key); + }; + + const setter = function (newVal: string) { + localStorage.setItem(key, newVal); + }; + + Object.defineProperty(target, propertyKey, { + get: getter, + set: setter + }); + } +}