diff --git a/my-app/src/lib/balance-utils.ts b/my-app/src/lib/balance-utils.ts index 0ea9600..1eb1d63 100644 --- a/my-app/src/lib/balance-utils.ts +++ b/my-app/src/lib/balance-utils.ts @@ -71,3 +71,9 @@ function computeTotal(objects: { category_id: Id; amount: number }[], categoryId function formatCategoryList(categoryList: { categoryName: string }[]): string { return categoryList.map(({ categoryName }) => `"${categoryName}"`).join(', '); } + +export function archivedCategoriesLast(categories: Category[]) { + const archived = categories.filter(({ is_archived }) => is_archived); + const active = categories.filter(({ is_archived }) => !is_archived); + return [...active, ...archived]; +} diff --git a/my-app/src/lib/components/CategoryFilter.svelte b/my-app/src/lib/components/CategoryFilter.svelte index 9672694..38a467b 100644 --- a/my-app/src/lib/components/CategoryFilter.svelte +++ b/my-app/src/lib/components/CategoryFilter.svelte @@ -1,5 +1,6 @@
Categorías: - {#each categories as category} + {#each sortedCategories as category} {@const active = filter.includes(category.id)} + {@const activeClass = !active ? 'outline' : ''} + {@const archivedClass = category.is_archived ? 'contrast' : ''}
diff --git a/my-app/src/lib/index.ts b/my-app/src/lib/index.ts index 85815cc..2b46673 100644 --- a/my-app/src/lib/index.ts +++ b/my-app/src/lib/index.ts @@ -50,7 +50,7 @@ export const routes = { groupMembers: (groupId: Id) => `/groups/${groupId}/members`, groupMovements: (groupId: Id) => `/groups/${groupId}/movements`, // categories - categoryDetails: '/categories/details', + categoryDetails: (categoryId?: Id) => `/categories/details${categoryId ? `/${categoryId}` : ''}`, // budgets budgetDetails: '/budgets/details', // spendings diff --git a/my-app/src/lib/server/api.ts b/my-app/src/lib/server/api.ts index ac09fe3..c210208 100644 --- a/my-app/src/lib/server/api.ts +++ b/my-app/src/lib/server/api.ts @@ -134,7 +134,9 @@ export const categoryService = { ? put(`category/${data.id}`, data, getAuthHeader(cookies)) : post('category', data, getAuthHeader(cookies)), get: (id: Id, cookies: Cookies) => get(`category/${id}`, getAuthHeader(cookies)), - list: (groupId: Id, cookies: Cookies) => get(`group/${groupId}/category`, getAuthHeader(cookies)) + list: (groupId: Id, cookies: Cookies) => get(`group/${groupId}/category`, getAuthHeader(cookies)), + archive: (id: Id, cookies: Cookies) => put(`category/${id}/is_archived`, { is_archived: true }, getAuthHeader(cookies)), + unarchive: (id: Id, cookies: Cookies) => put(`category/${id}/is_archived`, { is_archived: false }, getAuthHeader(cookies)) }; export const inviteService = { get: (token: string, cookies: Cookies) => get(`invite/${token}`, getAuthHeader(cookies)), diff --git a/my-app/src/routes/budgets/details/[[id=integer]]/+page.svelte b/my-app/src/routes/budgets/details/[[id=integer]]/+page.svelte index f0d7084..fb7de8b 100644 --- a/my-app/src/routes/budgets/details/[[id=integer]]/+page.svelte +++ b/my-app/src/routes/budgets/details/[[id=integer]]/+page.svelte @@ -33,6 +33,7 @@ try { const response = await fetch(`/api/categories?groupId=${groupId}`); categories = await response.json(); + categories = categories.filter((category) => !category.is_archived); return; } catch {} } diff --git a/my-app/src/routes/categories/details/[[id=integer]]/+page.server.ts b/my-app/src/routes/categories/details/[[id=integer]]/+page.server.ts index 438be75..4d678e6 100644 --- a/my-app/src/routes/categories/details/[[id=integer]]/+page.server.ts +++ b/my-app/src/routes/categories/details/[[id=integer]]/+page.server.ts @@ -15,7 +15,7 @@ export const load: PageServerLoad = async ({ params, url, cookies }) => { }; export const actions: Actions = { - default: async ({ cookies, request, params }) => { + update: async ({ cookies, request, params }) => { const id = Number(params.id) || 0; const data = await request.formData(); const name = data.get('name')?.toString(); @@ -37,5 +37,13 @@ export const actions: Actions = { await categoryService.save(category, cookies); redirect(302, routes.groupMovements(group_id)); + }, + archive: async ({ cookies, params }) => { + const id = Number(params.id) || 0; + await categoryService.archive(id, cookies); + }, + unarchive: async ({ cookies, params }) => { + const id = Number(params.id) || 0; + await categoryService.unarchive(id, cookies); } }; diff --git a/my-app/src/routes/categories/details/[[id=integer]]/+page.svelte b/my-app/src/routes/categories/details/[[id=integer]]/+page.svelte index 8b37db3..b7c0825 100644 --- a/my-app/src/routes/categories/details/[[id=integer]]/+page.svelte +++ b/my-app/src/routes/categories/details/[[id=integer]]/+page.svelte @@ -1,10 +1,13 @@ @@ -18,11 +21,11 @@

{#if edit}Editando{:else}Creando{/if} Categoría

-
+
diff --git a/my-app/src/routes/groups/+page.svelte b/my-app/src/routes/groups/+page.svelte index ba308be..ebbaa6e 100644 --- a/my-app/src/routes/groups/+page.svelte +++ b/my-app/src/routes/groups/+page.svelte @@ -30,7 +30,7 @@
  • Añadir grupo
  • Añadir gasto
  • Añadir presupuesto
  • -
  • Añadir categoría
  • +
  • Añadir categoría
  • diff --git a/my-app/src/routes/groups/[id=integer]/balance/+page.svelte b/my-app/src/routes/groups/[id=integer]/balance/+page.svelte index b26857c..3c715c3 100644 --- a/my-app/src/routes/groups/[id=integer]/balance/+page.svelte +++ b/my-app/src/routes/groups/[id=integer]/balance/+page.svelte @@ -94,9 +94,3 @@

    {/each} - - diff --git a/my-app/src/routes/groups/[id=integer]/budgets/+page.svelte b/my-app/src/routes/groups/[id=integer]/budgets/+page.svelte index 8ef6b5a..6be2ed3 100644 --- a/my-app/src/routes/groups/[id=integer]/budgets/+page.svelte +++ b/my-app/src/routes/groups/[id=integer]/budgets/+page.svelte @@ -1,4 +1,5 @@ @@ -16,12 +19,17 @@ -{#each data.categories as category} +{#each sortedCategories as category} {@const spendings = data.spendings.filter((s) => s.category_id === category.id)} {@const budgets = data.budgets.filter((b) => b.category_id === category.id)}

    + {#if category.is_archived} + + + + {/if} {category.name} - {category.description}

    diff --git a/my-app/src/routes/groups/[id=integer]/members/+page.svelte b/my-app/src/routes/groups/[id=integer]/members/+page.svelte index 235f65a..a19444a 100644 --- a/my-app/src/routes/groups/[id=integer]/members/+page.svelte +++ b/my-app/src/routes/groups/[id=integer]/members/+page.svelte @@ -3,6 +3,7 @@ import { confirmKickFromGroup, confirmLeaveGroup } from '$lib/client/alerts'; import Avatar from '$lib/components/Avatar.svelte'; import CssIcon from '$lib/components/CssIcon.svelte'; + import OwnerOnly from '$lib/components/OwnerOnly.svelte'; import type { PageData } from './$types'; export let data: PageData; @@ -20,10 +21,12 @@

    Miembros de {data.group.name}

    diff --git a/my-app/src/routes/groups/[id=integer]/movements/+page.svelte b/my-app/src/routes/groups/[id=integer]/movements/+page.svelte index 1f3e6b8..c077e26 100644 --- a/my-app/src/routes/groups/[id=integer]/movements/+page.svelte +++ b/my-app/src/routes/groups/[id=integer]/movements/+page.svelte @@ -62,7 +62,7 @@ diff --git a/my-app/src/routes/spendings/details/[[id=integer]]/+page.svelte b/my-app/src/routes/spendings/details/[[id=integer]]/+page.svelte index 2488ff9..dd04521 100644 --- a/my-app/src/routes/spendings/details/[[id=integer]]/+page.svelte +++ b/my-app/src/routes/spendings/details/[[id=integer]]/+page.svelte @@ -36,6 +36,7 @@ try { const response = await fetch(`${routes.apiCategories}?groupId=${groupId}`); categories = await response.json(); + categories = categories.filter((category) => !category.is_archived); return; } catch {} } diff --git a/my-app/src/types.d.ts b/my-app/src/types.d.ts index 1cf64bf..a3a09ed 100644 --- a/my-app/src/types.d.ts +++ b/my-app/src/types.d.ts @@ -27,6 +27,7 @@ declare global { group_id: Id; description: string; strategy: string; + is_archived: boolean; }; type Budget = { @@ -49,13 +50,13 @@ declare global { date: string; }; - interface UniqueSpending extends Spending {} + interface UniqueSpending extends Spending { } interface InstallmentSpending extends Spending { amount_of_installments: number; } - interface RecurringSpending extends Spending {} + interface RecurringSpending extends Spending { } type Payment = { id: Id; @@ -108,4 +109,4 @@ declare global { }; } -export {}; +export { }; diff --git a/my-app/static/styles.css b/my-app/static/styles.css index 9c4471a..acc323f 100644 --- a/my-app/static/styles.css +++ b/my-app/static/styles.css @@ -1,6 +1,7 @@ .mb { margin-bottom: 1em; } + .ml { margin-left: 1em; } @@ -29,6 +30,7 @@ .t-center { text-align: center; } + .t-right { text-align: right; } @@ -37,3 +39,7 @@ font-size: small; padding: 0.5em; } + +.no-underline { + border-bottom: 0px; +}