Skip to content

Commit

Permalink
migrate transaction edit page to composition API and typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Feb 4, 2025
1 parent 3e7b329 commit 833e767
Show file tree
Hide file tree
Showing 12 changed files with 1,853 additions and 2,138 deletions.
6 changes: 0 additions & 6 deletions src/core/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type TemplateTypeName = 'Normal' | 'Schedule';
export class TemplateType implements TypeAndName {
private static readonly allInstances: TemplateType[] = [];
private static readonly allInstancesByType: Record<number, TemplateType> = {};
private static readonly allInstancesByTypeName: Record<string, TemplateType> = {};

public static readonly Normal = new TemplateType(1, 'Normal');
public static readonly Schedule = new TemplateType(2, 'Schedule');
Expand All @@ -19,17 +18,12 @@ export class TemplateType implements TypeAndName {

TemplateType.allInstances.push(this);
TemplateType.allInstancesByType[type] = this;
TemplateType.allInstancesByTypeName[name] = this;
}

public static values(): TemplateType[] {
return TemplateType.allInstances;
}

public static all(): Record<TemplateTypeName, TemplateType> {
return TemplateType.allInstancesByTypeName;
}

public static valueOf(type: number): TemplateType | undefined {
return TemplateType.allInstancesByType[type];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export default {
timeout: DEFAULT_IMPORT_API_TIMEOUT
} as ApiRequestConfig);
},
uploadTransactionPicture: ({ pictureFile, clientSessionId }: { pictureFile: File, clientSessionId: string }): ApiResponsePromise<TransactionPictureInfoBasicResponse> => {
uploadTransactionPicture: ({ pictureFile, clientSessionId }: { pictureFile: File, clientSessionId?: string }): ApiResponsePromise<TransactionPictureInfoBasicResponse> => {
return axios.postForm<ApiResponse<TransactionPictureInfoBasicResponse>>('v1/transaction/pictures/upload.json', {
picture: pictureFile,
clientSessionId: clientSessionId
Expand Down
16 changes: 8 additions & 8 deletions src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import {
} from './category.ts';

export interface SetTransactionOptions {
type: number;
categoryId: string;
accountId: string;
destinationAccountId: string;
amount: number;
destinationAmount: number;
tagIds: string;
comment: string;
type?: number;
categoryId?: string;
accountId?: string;
destinationAccountId?: string;
amount?: number;
destinationAmount?: number;
tagIds?: string;
comment?: string;
}

function getDisplayAmount(amount: number, currency: string, hideAmount: boolean, formatAmountWithCurrencyFunc: (value: number | string, currencyCode?: string) => string): string {
Expand Down
48 changes: 24 additions & 24 deletions src/lib/ui/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,6 @@ export function showAlert(message: string, confirmCallback: ((dialog: Dialog.Dia
});
}

export function showConfirm(message: string, confirmCallback: (dialog: Dialog.Dialog, e: Event) => void, cancelCallback: ((dialog: Dialog.Dialog, e: Event) => void) | undefined, translateFn: TranslateFunction): void {
f7ready((f7) => {
f7.dialog.create({
title: translateFn('global.app.title'),
text: translateFn(message),
animate: isEnableAnimate(),
buttons: [
{
text: translateFn('Cancel'),
onClick: cancelCallback
},
{
text: translateFn('OK'),
onClick: confirmCallback
}
]
}).open();
});
}

export function showToast(message: string, timeout: number | undefined, translateFn: TranslateFunction): void {
f7ready((f7) => {
f7.toast.create({
Expand Down Expand Up @@ -210,7 +190,7 @@ export function scrollToSelectedItem(parentEl: Framework7Dom, containerSelector:
}

export function useI18nUIComponents() {
const i18nGlobal = useVueI18n();
const { t } = useVueI18n();

function routeBackOnError<T>(f7router: Router.Router, errorRef: Ref<T>): void {
const unwatch = watch(errorRef, (newValue) => {
Expand All @@ -228,10 +208,30 @@ export function useI18nUIComponents() {
});
}

function showConfirm(message: string, confirmCallback?: (dialog: Dialog.Dialog, e: Event) => void, cancelCallback?: ((dialog: Dialog.Dialog, e: Event) => void) | undefined): void {
f7ready((f7) => {
f7.dialog.create({
title: t('global.app.title'),
text: t(message),
animate: isEnableAnimate(),
buttons: [
{
text: t('Cancel'),
onClick: cancelCallback
},
{
text: t('OK'),
onClick: confirmCallback
}
]
}).open();
});
}

return {
showAlert: (message: string, confirmCallback?: (dialog: Dialog.Dialog, e: Event) => void) => showAlert(message, confirmCallback, i18nGlobal.t),
showConfirm: (message: string, confirmCallback: (dialog: Dialog.Dialog, e: Event) => void, cancelCallback?: (dialog: Dialog.Dialog, e: Event) => void): void => showConfirm(message, confirmCallback, cancelCallback, i18nGlobal.t),
showToast: (message: string, timeout?: number): void => showToast(message, timeout, i18nGlobal.t),
showAlert: (message: string, confirmCallback?: (dialog: Dialog.Dialog, e: Event) => void) => showAlert(message, confirmCallback, t),
showConfirm: showConfirm,
showToast: (message: string, timeout?: number): void => showToast(message, timeout, t),
routeBackOnError
}
}
Loading

0 comments on commit 833e767

Please sign in to comment.