Skip to content

Open source personal finance application

chore: checkpoint before bg semantics restructuring

Ilya Komichev3c131f729519
diff --git a/app/assets/css/theme.css b/app/assets/css/theme.css
index 9b24746f..d1704e0a 100644
--- a/app/assets/css/theme.css
+++ b/app/assets/css/theme.css
@@ -35,13 +35,13 @@
.dark {
color-scheme: dark;
- --item-1: rgb(19 19 19);
- --item-2: rgb(23 23 23);
- --item-3: #1c1c1c;
- --item-4: #232323;
- --item-5: #262626;
- --item-6: rgb(44 44 44);
- --item-7: #878787;
+ --item-1: color-mix(in oklch, var(--ui-color-neutral-950) 30%, var(--ui-color-neutral-900));
+ --item-2: var(--ui-color-neutral-900);
+ --item-3: color-mix(in oklch, var(--ui-color-neutral-900) 70%, var(--ui-color-neutral-800));
+ --item-4: var(--ui-color-neutral-800);
+ --item-5: color-mix(in oklch, var(--ui-color-neutral-800) 85%, var(--ui-color-neutral-700));
+ --item-6: color-mix(in oklch, var(--ui-color-neutral-800) 55%, var(--ui-color-neutral-700));
+ --item-7: color-mix(in oklch, var(--ui-color-neutral-500) 60%, var(--ui-color-neutral-400));
--overlay: #000000cc;
@@ -57,13 +57,13 @@
.light {
color-scheme: light;
- --item-1: rgb(255 255 255);
- --item-2: rgb(250 250 250);
- --item-3: #f5f5f5;
- --item-4: #f3eff2;
- --item-5: #f0edf0;
- --item-6: rgb(225 225 225);
- --item-7: #bebebe;
+ --item-1: white;
+ --item-2: var(--ui-color-neutral-50);
+ --item-3: var(--ui-color-neutral-100);
+ --item-4: color-mix(in oklch, var(--ui-color-neutral-100) 90%, var(--ui-color-neutral-200));
+ --item-5: color-mix(in oklch, var(--ui-color-neutral-100) 70%, var(--ui-color-neutral-200));
+ --item-6: var(--ui-color-neutral-200);
+ --item-7: color-mix(in oklch, var(--ui-color-neutral-300) 50%, var(--ui-color-neutral-400));
--overlay: #00000099;
diff --git a/app/components/categories/Item.vue b/app/components/categories/Item.vue
index 619e77b8..a623bfc4 100644
--- a/app/components/categories/Item.vue
+++ b/app/components/categories/Item.vue
@@ -10,6 +10,8 @@ export type CategoryItemProps = {
class?: string
contextMenuItems?: ContextMenuItem[][]
insideClasses?: string
+ isExpanded?: boolean
+ isShowChevron?: boolean
isShowParent?: boolean
lineWidth?: number
stacked?: boolean
@@ -21,6 +23,7 @@ const props = defineProps<CategoryItemProps>()
const emit = defineEmits<{
click: [e: Event]
filter: [categoryId: CategoryId]
+ toggle: []
}>()
</script>
@@ -33,11 +36,14 @@ const emit = defineEmits<{
:categoryId="props.categoryId"
:class="props.class"
:insideClasses="props.insideClasses"
+ :isExpanded="props.isExpanded"
+ :isShowChevron="props.isShowChevron"
:isShowParent="props.isShowParent"
:lineWidth="props.lineWidth"
:to="props.to"
@click="emit('click', $event)"
@filter="emit('filter', $event)"
+ @toggle="emit('toggle')"
/>
</UContextMenu>
@@ -49,10 +55,13 @@ const emit = defineEmits<{
:categoryId="props.categoryId"
:class="props.class"
:insideClasses="props.insideClasses"
+ :isExpanded="props.isExpanded"
+ :isShowChevron="props.isShowChevron"
:isShowParent="props.isShowParent"
:lineWidth="props.lineWidth"
:to="props.to"
@click="emit('click', $event)"
@filter="emit('filter', $event)"
+ @toggle="emit('toggle')"
/>
</template>
diff --git a/app/components/categories/ItemBody.vue b/app/components/categories/ItemBody.vue
index d1c604ec..a45c80aa 100644
--- a/app/components/categories/ItemBody.vue
+++ b/app/components/categories/ItemBody.vue
@@ -9,6 +9,8 @@ const props = defineProps<{
categoryId: CategoryId
class?: string
insideClasses?: string
+ isExpanded?: boolean
+ isShowChevron?: boolean
isShowParent?: boolean
lineWidth?: number
stacked?: boolean
@@ -18,12 +20,20 @@ const props = defineProps<{
const emit = defineEmits<{
click: [e: Event]
filter: [categoryId: CategoryId]
+ toggle: []
}>()
const categoriesStore = useCategoriesStore()
const childCategoriesIds = computed(() => categoriesStore.getChildrenIds(props.categoryId))
const parentCategory = computed(() => categoriesStore.items[props.category?.parentId])
+const hasChildren = computed(() => childCategoriesIds.value.length > 0)
+
+function onToggleClick(e: Event) {
+ e.stopPropagation()
+ e.preventDefault()
+ emit('toggle')
+}
</script>
<template>
@@ -50,9 +60,22 @@ const parentCategory = computed(() => categoriesStore.items[props.category?.pare
:stacked="props.stacked"
:category="props.category"
:parentCategory="parentCategory"
- :childrenCount="childCategoriesIds.length"
+ :childrenCount="props.isShowChevron ? undefined : childCategoriesIds.length"
:isShowParent="props.isShowParent"
/>
</div>
+
+ <button
+ v-if="props.isShowChevron && hasChildren"
+ type="button"
+ class="flex-center text-muted -mr-1 h-9 w-9 shrink-0 cursor-pointer rounded-sm hover:bg-(--item-3)"
+ :aria-label="$t('base.toggleExpand')"
+ @click="onToggleClick"
+ >
+ <Icon
+ :name="props.isExpanded ? 'lucide:chevron-down' : 'lucide:chevron-right'"
+ size="18"
+ />
+ </button>
</UiElement>
</template>
diff --git a/app/components/categories/List.vue b/app/components/categories/List.vue
index 48686a62..1fa59137 100644
--- a/app/components/categories/List.vue
+++ b/app/components/categories/List.vue
@@ -4,9 +4,15 @@ import type { CategoryId } from '~/components/categories/types'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
+export type CategoriesListExpanded = {
+ isExpanded: (id: CategoryId) => boolean
+ toggle: (id: CategoryId) => void
+}
+
const props = defineProps<{
activeItemId?: string | 0 | false | null
categoriesItemProps?: Partial<CategoryItemProps>
+ expanded?: CategoriesListExpanded
getContextMenuItems?: (categoryId: CategoryId) => any[][] | undefined
getTo?: (categoryId: CategoryId) => string
ids: CategoryId[]
@@ -18,22 +24,51 @@ const emit = defineEmits<{
}>()
const categoriesStore = useCategoriesStore()
+
+function getChildrenIds(categoryId: CategoryId) {
+ return categoriesStore.getChildrenIds(categoryId)
+}
</script>
<template>
<div class="pt-1">
- <CategoriesItem
+ <template
v-for="categoryId in ids"
:key="categoryId"
- :activeItemId="activeItemId"
- :category="categoriesStore.items[categoryId]!"
- :categoryId="categoryId"
- :contextMenuItems="props.getContextMenuItems?.(categoryId)"
- :insideClasses="props.insideClasses"
- :to="props.getTo?.(categoryId)"
- :lineWidth="1"
- v-bind="categoriesItemProps"
- @click="emit('click', categoryId)"
- />
+ >
+ <CategoriesItem
+ :activeItemId="activeItemId"
+ :category="categoriesStore.items[categoryId]!"
+ :categoryId="categoryId"
+ :contextMenuItems="props.getContextMenuItems?.(categoryId)"
+ :insideClasses="props.insideClasses"
+ :isExpanded="props.expanded?.isExpanded(categoryId)"
+ :isShowChevron="!!props.expanded && categoriesStore.hasChildren(categoryId)"
+ :to="props.getTo?.(categoryId)"
+ :lineWidth="1"
+ v-bind="categoriesItemProps"
+ @click="emit('click', categoryId)"
+ @toggle="props.expanded?.toggle(categoryId)"
+ />
+
+ <div
+ v-if="props.expanded?.isExpanded(categoryId) && categoriesStore.hasChildren(categoryId)"
+ class="-mt-px ml-5 pb-1 pl-3"
+ >
+ <CategoriesItem
+ v-for="childId in getChildrenIds(categoryId)"
+ :key="childId"
+ :activeItemId="activeItemId"
+ :category="categoriesStore.items[childId]!"
+ :categoryId="childId"
+ :contextMenuItems="props.getContextMenuItems?.(childId)"
+ :insideClasses="props.insideClasses"
+ :to="props.getTo?.(childId)"
+ :lineWidth="1"
+ v-bind="categoriesItemProps"
+ @click="emit('click', childId)"
+ />
+ </div>
+ </template>
</div>
</template>
diff --git a/app/components/categories/page/List.vue b/app/components/categories/page/List.vue
index ba406ff9..c51cbe5b 100644
--- a/app/components/categories/page/List.vue
+++ b/app/components/categories/page/List.vue
@@ -3,6 +3,7 @@ import { useStorage } from '@vueuse/core'
import type { CategoryId } from '~/components/categories/types'
+import { useCategoriesExpanded } from '~/components/categories/useCategoriesExpanded'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
import { useCategoryContextMenu } from '~/components/categories/useCategoryContextMenu'
import { useTrnsStore } from '~/components/trns/useTrnsStore'
@@ -12,6 +13,11 @@ const { t } = useI18n()
const categoriesStore = useCategoriesStore()
const trnsStore = useTrnsStore()
+const { folderIcon, isExpanded, toggle, toggleAll } = useCategoriesExpanded(
+ 'categoriesPage',
+ computed(() => categoriesStore.categoriesRootIds),
+)
+
useHead({ title: t('categories.title') })
const categoriesView = useStorage<'list' | 'grid'>('finapp.categoriesView', 'list', localStorage, {
@@ -77,6 +83,14 @@ const { getCategoryContextMenuItems } = useCategoryContextMenu({
<UiHeader>
<UiHeaderTitle>{{ t('categories.name') }}</UiHeaderTitle>
<template #actions>
+ <UiActionButton
+ v-if="categoriesView === 'list'"
+ :ariaLabel="$t('base.toggleFolders')"
+ @click="toggleAll"
+ >
+ <Icon :name="folderIcon" size="20" />
+ </UiActionButton>
+
<UiActionButton :ariaLabel="$t('base.toggleView')" @click="categoriesView = categoriesView === 'list' ? 'grid' : 'list'">
<Icon
:name="categoriesView === 'list' ? 'lucide:layout-grid' : 'lucide:list'"
@@ -121,6 +135,7 @@ const { getCategoryContextMenuItems } = useCategoryContextMenu({
:class="{
'grid gap-1.5 @sm:grid-cols-2 @2xl/page:grid-cols-3': categoriesView === 'grid',
}"
+ :expanded="categoriesView === 'list' ? { isExpanded, toggle } : undefined"
:getContextMenuItems="getCategoryContextMenuItems"
:insideClasses="categoriesView === 'grid' ? 'bg-item-2' : ''"
:getTo="(categoryId: CategoryId) => `/categories/${categoryId}`"
diff --git a/app/components/stat/categories/useCategoriesExpanded.ts b/app/components/categories/useCategoriesExpanded.ts
similarity index 50%
rename from app/components/stat/categories/useCategoriesExpanded.ts
rename to app/components/categories/useCategoriesExpanded.ts
index c109b21f..d9b8e580 100644
--- a/app/components/stat/categories/useCategoriesExpanded.ts
+++ b/app/components/categories/useCategoriesExpanded.ts
@@ -2,35 +2,27 @@ import type { ComputedRef } from 'vue'
import { useStorage } from '@vueuse/core'
-import type { Categories, CategoryId } from '~/components/categories/types'
-import type { CategoryWithData } from '~/components/stat/types'
+import type { CategoryId } from '~/components/categories/types'
type CategoryState = { show: boolean }
type CategoriesState = Record<CategoryId, CategoryState>
-function createInitialState(categories: Categories): CategoriesState {
- return Object.fromEntries(Object.keys(categories).map(id => [id, { show: false }]))
-}
-
export function useCategoriesExpanded(
storageKey: string,
- storeCategories: Categories,
- categoriesWithData: ComputedRef<CategoryWithData[]>,
+ currentIds: ComputedRef<CategoryId[]>,
) {
const expandedState = useStorage<CategoriesState>(
- `statCategoriesOpened1${storageKey}`,
- createInitialState(storeCategories),
+ `categoriesOpened:${storageKey}`,
+ {} as CategoriesState,
)
- const currentState = computed(() =>
- categoriesWithData.value.reduce((acc, cat) => {
- acc[cat.id] = { show: expandedState.value[cat.id]?.show ?? false }
- return acc
- }, {} as CategoriesState),
+ const isAllExpanded = computed(() =>
+ currentIds.value.length > 0
+ && currentIds.value.every(id => expandedState.value[id]?.show),
+ )
+ const isAnyExpanded = computed(() =>
+ currentIds.value.some(id => expandedState.value[id]?.show),
)
-
- const isAllExpanded = computed(() => Object.values(currentState.value).every(c => c.show))
- const isAnyExpanded = computed(() => Object.values(currentState.value).some(c => c.show))
const folderIcon = computed(() => {
if (isAllExpanded.value)
@@ -42,7 +34,7 @@ export function useCategoriesExpanded(
function toggleAll() {
const newShow = !isAnyExpanded.value
- for (const id of Object.keys(currentState.value))
+ for (const id of currentIds.value)
expandedState.value[id] = { show: newShow }
}
diff --git a/app/components/menu/Tabs.ts b/app/components/menu/Tabs.ts
new file mode 100644
index 00000000..2b09c356
--- /dev/null
+++ b/app/components/menu/Tabs.ts
@@ -0,0 +1,4 @@
+export const tabsNavUi = {
+ list: 'w-full grid grid-flow-col auto-cols-[minmax(max-content,1fr)]',
+ link: 'justify-center',
+}
diff --git a/app/components/stat/Menu.vue b/app/components/stat/Menu.vue
index 5a9d9279..c40aacaf 100644
--- a/app/components/stat/Menu.vue
+++ b/app/components/stat/Menu.vue
@@ -1,6 +1,10 @@
<script setup lang="ts">
+import type { NavigationMenuItem } from '@nuxt/ui'
+
import type { StatTabSlug } from '~/components/stat/types'
+import { tabsNavUi } from '~/components/menu/Tabs'
+
const props = defineProps<{
active: StatTabSlug
}>()
@@ -12,27 +16,22 @@ const emit = defineEmits<{
const { t } = useI18n()
const { width } = useWindowSize()
-const menu = computed(() => {
- const all: {
- id: StatTabSlug
- name: string
- }[] = [{
- id: 'summary',
- name: t('money.summary'),
- }, {
- id: 'expense',
- name: t('money.expense'),
- }, {
- id: 'income',
- name: t('money.income'),
- }]
+const menu = computed<NavigationMenuItem[]>(() => {
+ const make = (value: StatTabSlug, label: string): NavigationMenuItem => ({
+ active: props.active === value,
+ label,
+ onSelect: () => onClickStatMenu(value),
+ value,
+ })
+
+ const all = [
+ make('summary', t('money.summary')),
+ make('expense', t('money.expense')),
+ make('income', t('money.income')),
+ ]
- if (width.value > 766) {
- all.push({
- id: 'split',
- name: t('money.split'),
- })
- }
+ if (width.value > 766)
+ all.push(make('split', t('money.split')))
return all
})
@@ -43,24 +42,16 @@ function onClickStatMenu(tabName: StatTabSlug) {
}
watch(() => props.active, () => {
- if (!menu.value.some(i => i.id === props.active))
- onClickStatMenu(menu.value[0]!.id)
+ if (!menu.value.some(i => i.value === props.active))
+ onClickStatMenu(menu.value[0]!.value as StatTabSlug)
}, { immediate: true })
</script>
<template>
- <div class="-mb-px flex items-start gap-2">
- <div
- v-for="item in menu"
- :key="item.id"
- :class="[{
- '!border-(--ui-primary) pb-2.5': item.id === props.active,
- 'text-muted rounded-sm pb-1.5 hover:bg-(--item-5)': item.id !== props.active,
- }]"
- class="border-b border-transparent px-3 pt-1.5 text-xs tracking-wide text-nowrap lg:text-sm"
- @click="onClickStatMenu(item.id)"
- >
- {{ item.name }}
- </div>
- </div>
+ <UNavigationMenu
+ :items="menu"
+ highlight
+ class="w-full"
+ :ui="tabsNavUi"
+ />
</template>
diff --git a/app/components/stat/categories/DetailedSection.vue b/app/components/stat/categories/DetailedSection.vue
index 6f838047..ddebdf02 100644
--- a/app/components/stat/categories/DetailedSection.vue
+++ b/app/components/stat/categories/DetailedSection.vue
@@ -3,8 +3,7 @@ import type { CategoryId } from '~/components/categories/types'
import type { CategoryWithData, SeriesSlugSelected, StatTabSlug } from '~/components/stat/types'
import type { TrnId } from '~/components/trns/types'
-import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
-import { useCategoriesExpanded } from '~/components/stat/categories/useCategoriesExpanded'
+import { useCategoriesExpanded } from '~/components/categories/useCategoriesExpanded'
import { useStatCategories } from '~/components/stat/categories/useStatCategories'
import { statConfigKey } from '~/components/stat/injectionKeys'
import { resolveGrouped } from '~/components/stat/useStatConfig'
@@ -24,7 +23,6 @@ const emit = defineEmits<{
const { t } = useI18n()
const { computeCategoriesWithData } = useStatCategories()
-const categoriesStore = useCategoriesStore()
const statConfig = inject(statConfigKey)!
// Config
@@ -73,8 +71,7 @@ const {
toggleAll: toggleAllCategories,
} = useCategoriesExpanded(
props.storageKey,
- categoriesStore.items ?? {},
- categoriesWithData,
+ computed(() => categoriesWithData.value.map(c => c.id)),
)
function onParentClick(item: CategoryWithData) {
diff --git a/app/components/trns/List.vue b/app/components/trns/List.vue
index 6c6c3598..eb598314 100644
--- a/app/components/trns/List.vue
+++ b/app/components/trns/List.vue
@@ -277,7 +277,7 @@ function onOpenTrnForm(date: number) {
<div
v-for="(groupTrnsIds, date) in groupedTrns"
:key="date"
- class="_bg-item-2 _rounded-lg _border-b border-item-4 overflow-hidden pb-2 last:border-b-0 last:pb-px"
+ class="_rounded-lg _border-b border-item-4 overflow-hidden pb-2 last:border-b-0 last:pb-px"
>
<div
:class="{ 'border-item-4': isShowGroupSum && groupTrnsIds.length > 1 }"
diff --git a/app/components/wallets/page/List.vue b/app/components/wallets/page/List.vue
index 83fd974d..93079680 100644
--- a/app/components/wallets/page/List.vue
+++ b/app/components/wallets/page/List.vue
@@ -1,8 +1,12 @@
<script setup lang="ts">
+import type { NavigationMenuItem } from '@nuxt/ui'
+
import { useStorage } from '@vueuse/core'
import type { WalletsGroupedBy, WalletType } from '~/components/wallets/types'
+import { tabsNavUi } from '~/components/menu/Tabs'
+
import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'
import { WALLET_STORAGE_KEYS } from '~/components/wallets/constants'
import { useWalletDelete } from '~/components/wallets/useWalletDelete'
@@ -62,6 +66,17 @@ const {
function hasGroups(groups: Record<string, unknown> | undefined) {
return groups ? Object.keys(groups).length > 0 : false
}
+
+const groupNavItems = computed<NavigationMenuItem[]>(() =>
+ groupTabs.value.map(item => ({
+ active: item.id === groupedBy.value,
+ label: item.label,
+ onSelect: () => {
+ groupedBy.value = item.id
+ },
+ value: item.id,
+ })),
+)
</script>
<template>
@@ -168,17 +183,12 @@ function hasGroups(groups: Record<string, unknown> | undefined) {
<div class="@3xl/main:max-w-sm">
<div class="mb-2 flex min-h-12 items-center gap-2 md:pt-2 ">
- <UiTabsScroll>
- <UiTabsItemPill
- v-for="item in groupTabs"
- :key="item.id"
- variant="outline"
- :isActive="item.id === groupedBy"
- @click="groupedBy = item.id"
- >
- {{ item.label }}
- </UiTabsItemPill>
- </UiTabsScroll>
+ <UNavigationMenu
+ :items="groupNavItems"
+ highlight
+ class="w-full"
+ :ui="tabsNavUi"
+ />
<div
v-if="groupedBy !== 'none'"