Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Feb 4, 2025
1 parent 3c36378 commit 00d6f5d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 87 deletions.
52 changes: 26 additions & 26 deletions src/views/mobile/accounts/ListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -363,32 +363,6 @@ function setSortable(): void {
displayOrderModified.value = false;
}
function onSort(event: { el: { id: string }; from: number; to: number }): void {
if (!event || !event.el || !event.el.id) {
showToast('Unable to move account');
return;
}
const id = parseAccountIdFromDomId(event.el.id);
if (!id) {
showToast('Unable to move account');
return;
}
accountsStore.changeAccountDisplayOrder({
accountId: id,
from: event.from - 1, // first item in the list is title, so the index need minus one
to: event.to - 1,
updateListOrder: true,
updateGlobalListOrder: true
}).then(() => {
displayOrderModified.value = true;
}).catch(error => {
showToast(error.message || error);
});
}
function saveSortResult(): void {
if (!displayOrderModified.value) {
showHidden.value = false;
Expand Down Expand Up @@ -416,6 +390,32 @@ function saveSortResult(): void {
});
}
function onSort(event: { el: { id: string }; from: number; to: number }): void {
if (!event || !event.el || !event.el.id) {
showToast('Unable to move account');
return;
}
const id = parseAccountIdFromDomId(event.el.id);
if (!id) {
showToast('Unable to move account');
return;
}
accountsStore.changeAccountDisplayOrder({
accountId: id,
from: event.from - 1, // first item in the list is title, so the index need minus one
to: event.to - 1,
updateListOrder: true,
updateGlobalListOrder: true
}).then(() => {
displayOrderModified.value = true;
}).catch(error => {
showToast(error.message || error);
});
}
function onPageAfterIn(): void {
if (accountsStore.accountListStateInvalid && !loading.value) {
reload(null);
Expand Down
16 changes: 8 additions & 8 deletions src/views/mobile/categories/ListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,6 @@ function saveSortResult(): void {
});
}
function onPageAfterIn(): void {
if (transactionCategoriesStore.transactionCategoryListStateInvalid && !loading.value) {
reload(null);
}
routeBackOnError(props.f7router, loadingError);
}
function onSort(event: { el: { id: string }; from: number; to: number }): void {
if (!event || !event.el || !event.el.id) {
showToast('Unable to move category');
Expand All @@ -379,6 +371,14 @@ function onSort(event: { el: { id: string }; from: number; to: number }): void {
});
}
function onPageAfterIn(): void {
if (transactionCategoriesStore.transactionCategoryListStateInvalid && !loading.value) {
reload(null);
}
routeBackOnError(props.f7router, loadingError);
}
init();
</script>

Expand Down
116 changes: 63 additions & 53 deletions src/views/mobile/tags/ListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const props = defineProps<{
}>();
const { tt } = useI18n();
const { showToast, routeBackOnError } = useI18nUIComponents();
const { showAlert, showToast, routeBackOnError } = useI18nUIComponents();
const transactionTagsStore = useTransactionTagsStore();
Expand Down Expand Up @@ -207,7 +207,24 @@ function parseTagIdFromDomId(domId: string): string | null {
return domId.substring(4); // tag_
}
function reload(done?: () => void): void {
function init(): void {
loading.value = true;
transactionTagsStore.loadAllTags({
force: false
}).then(() => {
loading.value = false;
}).catch(error => {
if (error.processed) {
loading.value = false;
} else {
loadingError.value = error;
showToast(error.message || error);
}
});
}
function reload(done: (() => void) | null): void {
if (sortable.value || hasEditingTag.value) {
done?.();
return;
Expand Down Expand Up @@ -273,43 +290,6 @@ function cancelSave(tag: TransactionTag): void {
}
}
function setSortable(): void {
if (sortable.value || hasEditingTag.value) {
return;
}
showHidden.value = true;
sortable.value = true;
displayOrderModified.value = false;
}
function saveSortResult(): void {
if (!displayOrderModified.value) {
showHidden.value = false;
sortable.value = false;
return;
}
displayOrderSaving.value = true;
showLoading();
transactionTagsStore.updateTagDisplayOrders().then(() => {
displayOrderSaving.value = false;
hideLoading();
showHidden.value = false;
sortable.value = false;
displayOrderModified.value = false;
}).catch(error => {
displayOrderSaving.value = false;
hideLoading();
if (!error.processed) {
showToast(error.message || error);
}
});
}
function hide(tag: TransactionTag, hidden: boolean): void {
showLoading();
Expand All @@ -329,7 +309,7 @@ function hide(tag: TransactionTag, hidden: boolean): void {
function remove(tag: TransactionTag | null, confirm: boolean): void {
if (!tag) {
showToast('An error occurred');
showAlert('An error occurred');
return;
}
Expand Down Expand Up @@ -359,8 +339,41 @@ function remove(tag: TransactionTag | null, confirm: boolean): void {
});
}
function onPageAfterIn(): void {
routeBackOnError(props.f7router, loadingError);
function setSortable(): void {
if (sortable.value || hasEditingTag.value) {
return;
}
showHidden.value = true;
sortable.value = true;
displayOrderModified.value = false;
}
function saveSortResult(): void {
if (!displayOrderModified.value) {
showHidden.value = false;
sortable.value = false;
return;
}
displayOrderSaving.value = true;
showLoading();
transactionTagsStore.updateTagDisplayOrders().then(() => {
displayOrderSaving.value = false;
hideLoading();
showHidden.value = false;
sortable.value = false;
displayOrderModified.value = false;
}).catch(error => {
displayOrderSaving.value = false;
hideLoading();
if (!error.processed) {
showToast(error.message || error);
}
});
}
function onSort(event: { el: { id: string }, from: number, to: number }): void {
Expand All @@ -387,18 +400,15 @@ function onSort(event: { el: { id: string }, from: number, to: number }): void {
});
}
transactionTagsStore.loadAllTags({
force: false
}).then(() => {
loading.value = false;
}).catch(error => {
if (error.processed) {
loading.value = false;
} else {
loadingError.value = error;
showToast(error.message || error);
function onPageAfterIn(): void {
if (transactionTagsStore.transactionTagListStateInvalid && !loading.value) {
reload(null);
}
});
routeBackOnError(props.f7router, loadingError);
}
init();
</script>

<style>
Expand Down

0 comments on commit 00d6f5d

Please sign in to comment.