Skip to content

Open source personal finance application

feat(categories): redesign selector with search, modals and quick toggles

Ilya Komichev68c2a5c9c251
diff --git a/app/app/components/categories/CommandPalette.vue b/app/app/components/categories/CommandPalette.vue
deleted file mode 100644
index 23a7c5de..00000000
--- a/app/app/components/categories/CommandPalette.vue
+++ /dev/null
@@ -1,163 +0,0 @@
-<script setup lang="ts">
-import type { CommandPaletteItem } from '@nuxt/ui'
-
-import { useStorage } from '@vueuse/core'
-
-import type { CategoryId, CategoryItemWithId } from '~/components/categories/types'
-
-import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
-
-type CategoryCommandPaletteItem = CommandPaletteItem & CategoryItemWithId
-type CategoryFilter = 'all' | 'favorites'
-
-const props = defineProps<{
- activeItemId?: CategoryId
- hide?: () => void
-}>()
-
-const emit = defineEmits<{
- selected: [id: CategoryId]
-}>()
-
-const { t } = useI18n()
-const categoriesStore = useCategoriesStore()
-
-const filter = useStorage<CategoryFilter>('finapp-categories-selector-filter', 'all')
-
-const hasFavorites = computed(() => categoriesStore.favoriteCategoriesIds.length > 0)
-const hasRecent = computed(() => categoriesStore.recentCategoriesIds.length > 0)
-const isShowTabs = computed(() => hasFavorites.value || hasRecent.value)
-
-watch(isShowTabs, (show) => {
- if (!show && filter.value !== 'all')
- filter.value = 'all'
-}, { immediate: true })
-
-watch([hasFavorites, hasRecent], () => {
- if (filter.value === 'favorites' && !hasFavorites.value && !hasRecent.value)
- filter.value = 'all'
-}, { immediate: true })
-
-const allCats = computed(() => {
- const adjustmentCategory = categoriesStore.items.adjustment!
- const adjustmentGroup = {
- ...adjustmentCategory,
- id: 'adjustment',
- items: [{
- id: 'adjustment',
- ...adjustmentCategory,
- suffix: adjustmentCategory.name,
- }],
- slot: 'category',
- }
-
- const rootGroups = categoriesStore.categoriesRootIds.map((id) => {
- const category = categoriesStore.items[id]!
- const children = categoriesStore.getChildrenIds(id)
- const items = children.length
- ? children.map(childId => ({
- id: childId,
- ...categoriesStore.items[childId],
- suffix: category.name,
- }))
- : [{
- id,
- ...category,
- suffix: category.name,
- }]
-
- return {
- ...category,
- id,
- items,
- slot: 'category',
- }
- })
-
- return [adjustmentGroup, ...rootGroups]
-})
-
-function onSelect(item: CategoryCommandPaletteItem) {
- emit('selected', item.id)
- if (props.hide)
- props.hide()
-}
-
-function selectId(id: CategoryId) {
- emit('selected', id)
- if (props.hide)
- props.hide()
-}
-</script>
-
-<template>
- <div class="relative flex h-full min-h-0 flex-col overflow-hidden">
- <!-- @vue-ignore -->
- <UCommandPalette
- v-if="filter === 'all'"
- :placeholder="t('categories.search.placeholder')"
- :groups="allCats"
- labelKey="name"
- :ui="{ root: '-mt-3 h-full', viewport: isShowTabs ? 'pb-16' : '' }"
- @update:modelValue="onSelect"
- >
- <template #category="{ item: rawItem }">
- <div
- class="flex w-full items-center gap-3"
- :class="{ 'text-primary': (rawItem as CategoryCommandPaletteItem).id === props.activeItemId }"
- >
- <UiIconBase
- :color="(rawItem as CategoryCommandPaletteItem).color"
- :name="(rawItem as CategoryCommandPaletteItem).icon"
- invert
- />
- <CategoriesName
- :category="(rawItem as CategoryCommandPaletteItem)"
- />
- </div>
- </template>
- </UCommandPalette>
-
- <div
- v-else
- class="scrollerBlock grid h-full content-start gap-4 overflow-y-auto pt-px pb-16"
- >
- <CategoriesSelectorGrid
- v-if="hasFavorites"
- :activeItemId="props.activeItemId"
- :ids="categoriesStore.favoriteCategoriesIds"
- @selected="selectId"
- />
- <div v-if="hasRecent">
- <div class="font-tertiary sticky top-0 z-20 pt-5 pb-4 text-lg leading-none font-semibold">
- {{ t('categories.recentCategories') }}
- </div>
- <CategoriesSelectorGrid
- :activeItemId="props.activeItemId"
- :ids="categoriesStore.recentCategoriesIds"
- class="pt-px"
- @selected="selectId"
- />
- </div>
- </div>
-
- <template v-if="isShowTabs">
- <div
- class="pointer-events-none absolute bottom-0 left-0 z-10 h-12 w-full"
- style="background: linear-gradient(to bottom, transparent, var(--ui-bg))"
- />
- <div class="pointer-events-none absolute bottom-2 left-0 z-20 w-full px-2">
- <div class="border-default/80 bg-default/20 pointer-events-auto rounded-2xl border p-1 shadow-lg backdrop-blur-xl dark:bg-neutral-800/50">
- <UiTabsScroll class="flex gap-1">
- <UiTabsItemFill :isActive="filter === 'all'" @click="filter = 'all'">
- {{ t('common.all') }}
- </UiTabsItemFill>
- <UiTabsItemFill :isActive="filter === 'favorites'" @click="filter = 'favorites'">
- {{ t('categories.favorite') }}
- </UiTabsItemFill>
- </UiTabsScroll>
- </div>
- </div>
- </template>
- </div>
-</template>
diff --git a/app/app/components/categories/EditModal.vue b/app/app/components/categories/EditModal.vue
new file mode 100644
index 00000000..4fa5c65d
--- /dev/null
+++ b/app/app/components/categories/EditModal.vue
@@ -0,0 +1,39 @@
+<script setup lang="ts">
+import type { CategoryId, CategoryItem } from '~/components/categories/types'
+
+import { categoryFormSchema } from '~/components/categories/types'
+import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
+
+const props = defineProps<{
+ categoryId?: CategoryId
+}>()
+
+const emit = defineEmits<{
+ closed: []
+}>()
+
+const { t } = useI18n()
+const categoriesStore = useCategoriesStore()
+
+const category = computed(() =>
+ props.categoryId ? categoriesStore.items[props.categoryId] : undefined,
+)
+const categoryForm = ref(categoryFormSchema.parse(category.value ?? {}))
+</script>
+
+<template>
+ <BottomSheetModal @closed="emit('closed')">
+ <template #default="{ close }">
+ <UiTitleModal>
+ {{ category?.name || t('categories.createNewTitle') }}
+ </UiTitleModal>
+
+ <CategoriesForm
+ :categoryId="props.categoryId"
+ :categoryForm="categoryForm"
+ @update="(key: string, value: CategoryItem[keyof CategoryItem]) => (categoryForm as Record<string, any>)[key] = value"
+ @afterSave="close"
+ />
+ </template>
+ </BottomSheetModal>
+</template>
diff --git a/app/app/components/categories/Item.vue b/app/app/components/categories/Item.vue
index 92f5ceb1..79172464 100644
--- a/app/app/components/categories/Item.vue
+++ b/app/app/components/categories/Item.vue
@@ -8,6 +8,7 @@ export type CategoryItemProps = {
categoryId: CategoryId
class?: string
contextMenuItems?: ContextMenuItem[][]
+ hideLeftMenuButton?: boolean
insideClasses?: string
isExpanded?: boolean
isShowChevron?: boolean
@@ -39,6 +40,7 @@ const emit = defineEmits<{
:isExpanded="props.isExpanded"
:isShowChevron="props.isShowChevron"
:isShowParent="props.isShowParent"
+ :hideLeftMenuButton="props.hideLeftMenuButton"
:leftMenuButton="props.leftMenuButton"
:leftMenuItems="props.contextMenuItems"
:lineWidth="props.lineWidth"
diff --git a/app/app/components/categories/ItemBody.vue b/app/app/components/categories/ItemBody.vue
index 48e7c2ed..c89395ed 100644
--- a/app/app/components/categories/ItemBody.vue
+++ b/app/app/components/categories/ItemBody.vue
@@ -9,6 +9,7 @@ const props = defineProps<{
category: CategoryItem
categoryId: CategoryId
class?: string
+ hideLeftMenuButton?: boolean
insideClasses?: string
isExpanded?: boolean
isShowChevron?: boolean
@@ -92,7 +93,7 @@ function onRowClick(e: Event) {
</div>
<UDropdownMenu
- v-if="props.leftMenuItems"
+ v-if="props.leftMenuItems && !props.hideLeftMenuButton"
:items="props.leftMenuItems"
:content="{ align: 'start', side: 'bottom' }"
>
diff --git a/app/app/components/categories/RoundLink.vue b/app/app/components/categories/RoundLink.vue
index a082b15e..ac9dcf73 100644
--- a/app/app/components/categories/RoundLink.vue
+++ b/app/app/components/categories/RoundLink.vue
@@ -5,6 +5,7 @@ import type { CategoryId } from '~/components/categories/types'
const props = defineProps<{
categoryId: CategoryId
contextMenuItems?: ContextMenuItem[][]
+ isActive?: boolean
to?: string
}>()
@@ -20,7 +21,7 @@ const emit = defineEmits<{
class="text-inherit no-underline"
@click="emit('click')"
>
- <CategoriesRoundPill :categoryId="props.categoryId" />
+ <CategoriesRoundPill :categoryId="props.categoryId" :isActive="props.isActive" />
</NuxtLink>
</UContextMenu>
diff --git a/app/app/components/categories/RoundPill.vue b/app/app/components/categories/RoundPill.vue
index cb17c7fe..58722aa4 100644
--- a/app/app/components/categories/RoundPill.vue
+++ b/app/app/components/categories/RoundPill.vue
@@ -5,6 +5,7 @@ import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
const props = defineProps<{
categoryId: CategoryId
+ isActive?: boolean
isIconBg?: boolean
isShowParent?: boolean
}>()
@@ -20,8 +21,11 @@ const parentCategory = computed(() => {
<template>
<div
v-if="category"
- class="bg-elevated/10 hover:bg-elevated/30 relative flex items-center overflow-hidden rounded-2xl border border-transparent p-1 pr-3"
- :class="props.isIconBg ? 'gap-2' : 'gap-1'"
+ class="bg-elevated/10 hover:bg-elevated/30 relative flex items-center overflow-hidden rounded-2xl border p-1 pr-3"
+ :class="[
+ props.isIconBg ? 'gap-2' : 'gap-1',
+ props.isActive ? 'border-primary/60 bg-elevated/30' : 'border-transparent',
+ ]"
>
<div
:style="{ backgroundColor: category.color }"
diff --git a/app/app/components/categories/SelectorGrid.vue b/app/app/components/categories/SelectorGrid.vue
index c783380e..679611cc 100644
--- a/app/app/components/categories/SelectorGrid.vue
+++ b/app/app/components/categories/SelectorGrid.vue
@@ -1,17 +1,21 @@
<script setup lang="ts">
+import type { ContextMenuItem } from '#ui/components/ContextMenu.vue'
import type { CategoryId } from '~/components/categories/types'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
const props = defineProps<{
activeItemId?: CategoryId
+ getContextMenuItems?: (categoryId: CategoryId) => ContextMenuItem[][] | undefined
ids: CategoryId[]
+ onNew?: () => void
}>()
const emit = defineEmits<{
selected: [id: CategoryId]
}>()
+const { t } = useI18n()
const categoriesStore = useCategoriesStore()
const itemClasses = 'bg-elevated/30 rounded-sm'
@@ -32,9 +36,23 @@ function select(id: CategoryId) {
:categoryId="categoryId"
:class="itemClasses"
:category="categoriesStore.items[categoryId]!"
+ :contextMenuItems="props.getContextMenuItems?.(categoryId)"
isShowParent
stacked
@click="select(categoryId)"
/>
+
+ <button
+ v-if="props.onNew"
+ type="button"
+ :class="cn('interactive flex min-h-[46px] items-center gap-3 px-2 py-1.5 -my-[1px]', itemClasses)"
+ :aria-label="t('categories.new')"
+ @click="props.onNew"
+ >
+ <div class="flex-center text-icon-primary bg-elevated/60 size-8 shrink-0 rounded-full">
+ <Icon name="lucide:plus" size="18" />
+ </div>
+ <span class="text-muted text-sm">{{ t('categories.new') }}</span>
+ </button>
</div>
</template>
diff --git a/app/app/components/categories/SelectorModal.vue b/app/app/components/categories/SelectorModal.vue
new file mode 100644
index 00000000..79117dd0
--- /dev/null
+++ b/app/app/components/categories/SelectorModal.vue
@@ -0,0 +1,391 @@
+<script setup lang="ts">
+import { useStorage, useWindowSize } 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'
+import { showErrorToast, showSuccessToast } from '~/composables/useStoreSync'
+
+type CategoryFilter = 'all' | 'favorites'
+
+const props = defineProps<{
+ activeItemId?: CategoryId
+ hide?: () => void
+}>()
+
+const emit = defineEmits<{
+ selected: [id: CategoryId]
+}>()
+
+const { t } = useI18n()
+const router = useRouter()
+const categoriesStore = useCategoriesStore()
+const trnsStore = useTrnsStore()
+
+const { width } = useWindowSize()
+const { pointerType } = usePointer()
+const isLaptop = computed(() => width.value >= 766 && pointerType.value === 'mouse')
+
+const search = ref('')
+const searchInput = useTemplateRef<HTMLInputElement>('searchInput')
+
+const filter = useStorage<CategoryFilter>('finapp-categories-selector-filter', 'all')
+const view = useStorage<'list' | 'grid'>('finapp.categoriesSelectorView', 'list')
+
+const editingCategoryId = ref<CategoryId | null>(null)
+const isCreatingNewCategory = ref(false)
+const deleteCategoryId = ref<CategoryId | null>(null)
+
+const hasFavorites = computed(() => categoriesStore.favoriteCategoriesIds.length > 0)
+const hasRecent = computed(() => categoriesStore.recentCategoriesIds.length > 0)
+const hasFavoritesOrRecent = computed(() => hasFavorites.value || hasRecent.value)
+
+watch(hasFavoritesOrRecent, (any) => {
+ if (!any && filter.value !== 'all')
+ filter.value = 'all'
+}, { immediate: true })
+
+function toggleFavoritesFilter() {
+ filter.value = filter.value === 'favorites' ? 'all' : 'favorites'
+}
+
+const allRootIds = computed<CategoryId[]>(() => {
+ const items = categoriesStore.items
+ const ids = [...categoriesStore.categoriesRootIds]
+ if (items.adjustment)
+ ids.push('adjustment')
+ return ids.sort((a, b) =>
+ (items[a]?.name ?? '').localeCompare(items[b]?.name ?? ''),
+ )
+})
+
+const {
+ folderIcon,
+ isExpanded,
+ toggle,
+ toggleAll,
+} = useCategoriesExpanded('categoriesSelector', allRootIds)
+
+function nameMatches(id: CategoryId, q: string) {
+ const cat = categoriesStore.items[id]
+ if (!cat)
+ return false
+ return cat.name.toLowerCase().includes(q)
+}
+
+const searchQuery = computed(() => search.value.trim().toLowerCase())
+
+const filteredAllRootIds = computed<CategoryId[]>(() => {
+ const q = searchQuery.value
+ if (!q)
+ return allRootIds.value
+ return allRootIds.value.filter((rootId) => {
+ if (nameMatches(rootId, q))
+ return true
+ return categoriesStore.getChildrenIds(rootId).some(cid => nameMatches(cid, q))
+ })
+})
+
+function visibleChildrenIds(rootId: CategoryId): CategoryId[] {
+ const all = categoriesStore.getChildrenIds(rootId)
+ const q = searchQuery.value
+ if (!q)
+ return all
+ if (nameMatches(rootId, q))
+ return all
+ return all.filter(cid => nameMatches(cid, q))
+}
+
+function isRootExpanded(rootId: CategoryId) {
+ if (searchQuery.value)
+ return visibleChildrenIds(rootId).length > 0
+ return isExpanded(rootId)
+}
+
+const filteredFavorites = computed<CategoryId[]>(() => {
+ const q = searchQuery.value
+ if (!q)
+ return categoriesStore.favoriteCategoriesIds
+ return categoriesStore.favoriteCategoriesIds.filter(id => nameMatches(id, q))
+})
+
+const filteredRecent = computed<CategoryId[]>(() => {
+ const q = searchQuery.value
+ if (!q)
+ return categoriesStore.recentCategoriesIds
+ return categoriesStore.recentCategoriesIds.filter(id => nameMatches(id, q))
+})
+
+const hasNoMatches = computed(() => {
+ if (!searchQuery.value)
+ return false
+ if (filter.value === 'all')
+ return filteredAllRootIds.value.length === 0
+ return filteredFavorites.value.length === 0 && filteredRecent.value.length === 0
+})
+
+function onClickNew() {
+ if (isLaptop.value)
+ router.push('/categories/new?returnBack=1')
+ else
+ isCreatingNewCategory.value = true
+}
+
+const deleteTrnsCount = computed(() => {
+ if (!deleteCategoryId.value)
+ return 0
+ return trnsStore.getStoreTrnsIds({
+ categoriesIds: categoriesStore.getChildrenIdsOrParent(deleteCategoryId.value),
+ }).length
+})
+
+const deleteDescText = computed(() =>
+ deleteTrnsCount.value > 0 ? t('categories.form.delete.alertWithTrns') : undefined,
+)
+
+const deleteHighlight = computed(() =>
+ deleteTrnsCount.value > 0 ? t('trns.plural', deleteTrnsCount.value) : undefined,
+)
+
+function onClickDelete(categoryId: CategoryId) {
+ for (const id of Object.keys(categoriesStore.items)) {
+ if (categoriesStore.items[id]?.parentId === categoryId) {
+ showErrorToast('categories.form.delete.errorChildren')
+ return
+ }
+ }
+ deleteCategoryId.value = categoryId
+}
+
+async function onDeleteConfirm() {
+ if (!deleteCategoryId.value)
+ return
+
+ const categoryId = deleteCategoryId.value
+ const trnsIds = [...trnsStore.getStoreTrnsIds({
+ categoriesIds: categoriesStore.getChildrenIdsOrParent(categoryId),
+ })]
+
+ deleteCategoryId.value = null
+ await categoriesStore.deleteCategory(categoryId, trnsIds)
+
+ setTimeout(() => {
+ showSuccessToast(trnsIds.length > 0
+ ? 'categories.form.delete.okWithTrns'
+ : 'categories.form.delete.okWithoutTrns', trnsIds.length > 0
+ ? { length: trnsIds.length, trns: t('trns.plural', trnsIds.length) }
+ : undefined)
+ }, 300)
+}
+
+const { getCategoryContextMenuItems: getLaptopMenuItems } = useCategoryContextMenu({
+ excludeOpen: true,
+ onDelete: onClickDelete,
+ returnBackOnSave: true,
+ withQuickToggles: true,
+})
+
+const { getCategoryContextMenuItems: getMobileMenuItems } = useCategoryContextMenu({
+ excludeOpen: true,
+ onDelete: onClickDelete,
+ onEdit: (id) => {
+ editingCategoryId.value = id
+ },
+ withQuickToggles: true,
+})
+
+function getCategoryContextMenuItems(categoryId: CategoryId) {
+ return isLaptop.value
+ ? getLaptopMenuItems(categoryId)
+ : getMobileMenuItems(categoryId)
+}
+
+function onSelect(id: CategoryId) {
+ emit('selected', id)
+ props.hide?.()
+}
+
+function onRootClick(rootId: CategoryId) {
+ if (!categoriesStore.hasChildren(rootId)) {
+ onSelect(rootId)
+ return
+ }
+ toggle(rootId)
+}
+
+onMounted(async () => {
+ await nextTick()
+ searchInput.value?.focus()
+})
+</script>
+
+<template>
+ <div class="relative flex h-full min-h-0 flex-col overflow-hidden">
+ <div class="bg-default sticky top-0 z-20 flex items-center gap-2 px-3 pt-2 pb-2">
+ <input
+ ref="searchInput"
+ v-model="search"
+ type="text"
+ class="bg-elevated/30 placeholder:text-muted hover:bg-elevated/50 focus:bg-elevated/50 focus:border-primary m-0 min-h-[42px] flex-1 rounded-md border border-transparent px-4 py-2 text-base font-normal outline-none"
+ :placeholder="t('categories.search.placeholder')"
+ >
+ <div class="flex items-center">
+ <UiActionButton
+ v-if="filter === 'all'"
+ :ariaLabel="$t('base.toggleView')"
+ @click="view = view === 'list' ? 'grid' : 'list'"
+ >
+ <Icon
+ :name="view === 'list' ? 'lucide:layout-grid' : 'lucide:list'"
+ size="20"
+ />
+ </UiActionButton>
+
+ <UiActionButton
+ v-if="filter === 'all'"
+ :ariaLabel="$t('base.toggleFolders')"
+ @click="toggleAll"
+ >
+ <Icon :name="folderIcon" size="20" />
+ </UiActionButton>
+
+ <UiActionButton
+ v-if="hasFavoritesOrRecent"
+ :ariaLabel="$t('categories.favorite')"
+ :isActive="filter === 'favorites'"
+ @click="toggleFavoritesFilter"
+ >
+ <Icon
+ name="lucide:star"
+ :class="filter === 'favorites' ? 'text-primary' : ''"
+ size="20"
+ />
+ </UiActionButton>
+
+ <UiActionButton
+ :ariaLabel="$t('categories.new')"
+ @click="onClickNew"
+ >
+ <Icon name="lucide:plus" size="20" />
+ </UiActionButton>
+ </div>
+ </div>
+
+ <div class="scrollerBlock h-full overflow-y-auto px-3 pt-1 pb-4">
+ <template v-if="filter === 'all'">
+ <div
+ v-if="hasNoMatches"
+ class="text-muted p-4 text-center"
+ >
+ {{ t('categories.form.children.noMatches') }}
+ </div>
+
+ <template v-else>
+ <template
+ v-for="rootId in filteredAllRootIds"
+ :key="rootId"
+ >
+ <CategoriesItem
+ :activeItemId="props.activeItemId"
+ :category="categoriesStore.items[rootId]!"
+ :categoryId="rootId"
+ :contextMenuItems="getCategoryContextMenuItems(rootId)"
+ :isExpanded="isRootExpanded(rootId)"
+ :isShowChevron="categoriesStore.hasChildren(rootId)"
+ :hideLeftMenuButton="true"
+ :leftMenuButton="true"
+ :lineWidth="isRootExpanded(rootId) && categoriesStore.hasChildren(rootId) ? 0 : 1"
+ class="group"
+ @click="onRootClick(rootId)"
+ @toggle="toggle(rootId)"
+ />
+
+ <div
+ v-if="isRootExpanded(rootId) && categoriesStore.hasChildren(rootId)"
+ :class="view === 'grid'
+ ? 'ml-2 pr-2 pb-4 pl-3'
+ : '-mt-px ml-5 pb-1 pl-3'"
+ >
+ <template v-if="view === 'list'">
+ <CategoriesItem
+ v-for="childId in visibleChildrenIds(rootId)"
+ :key="childId"
+ :activeItemId="props.activeItemId"
+ :category="categoriesStore.items[childId]!"
+ :categoryId="childId"
+ :contextMenuItems="getCategoryContextMenuItems(childId)"
+ :hideLeftMenuButton="true"
+ :leftMenuButton="true"
+ :lineWidth="1"
+ class="group"
+ @click="onSelect(childId)"
+ />
+ </template>
+
+ <div v-else class="flex flex-wrap gap-1">
+ <CategoriesRoundLink
+ v-for="childId in visibleChildrenIds(rootId)"
+ :key="childId"
+ :categoryId="childId"
+ :contextMenuItems="getCategoryContextMenuItems(childId)"
+ :isActive="props.activeItemId === childId"
+ @click="onSelect(childId)"
+ />
+ </div>
+ </div>
+ </template>
+ </template>
+ </template>
+
+ <template v-else>
+ <div
+ v-if="hasNoMatches"
+ class="text-muted p-4 text-center"
+ >
+ {{ t('categories.form.children.noMatches') }}
+ </div>
+
+ <template v-else>
+ <CategoriesSelectorGrid
+ v-if="filteredFavorites.length > 0"
+ :activeItemId="props.activeItemId"
+ :getContextMenuItems="getCategoryContextMenuItems"
+ :ids="filteredFavorites"
+ @selected="onSelect"
+ />
+
+ <div v-if="filteredRecent.length > 0">
+ <div class="font-tertiary sticky top-0 z-10 pt-5 pb-4 text-lg leading-none font-semibold">
+ {{ t('categories.recentCategories') }}
+ </div>
+ <CategoriesSelectorGrid
+ :activeItemId="props.activeItemId"
+ :getContextMenuItems="getCategoryContextMenuItems"
+ :ids="filteredRecent"
+ class="pt-px"
+ @selected="onSelect"
+ />
+ </div>
+ </template>
+ </template>
+ </div>
+
+ <CategoriesEditModal
+ v-if="(editingCategoryId || isCreatingNewCategory) && !isLaptop"
+ :categoryId="editingCategoryId ?? undefined"
+ @closed="editingCategoryId = null; isCreatingNewCategory = false"
+ />
+
+ <LayoutConfirmModal
+ v-if="deleteCategoryId"
+ :title="t('categories.form.delete.title')"
+ :description="deleteDescText"
+ :highlight="deleteHighlight"
+ @closed="deleteCategoryId = null"
+ @confirm="onDeleteConfirm"
+ />
+ </div>
+</template>
diff --git a/app/app/components/categories/SelectorTree.vue b/app/app/components/categories/SelectorTree.vue
index bef7a4c6..18dbe7a4 100644
--- a/app/app/components/categories/SelectorTree.vue
+++ b/app/app/components/categories/SelectorTree.vue
@@ -1,6 +1,9 @@
<script setup lang="ts">
+import { useStorage } from '@vueuse/core'
+
import type { CategoryId } from '~/components/categories/types'
+import { useCategoriesExpanded } from '~/components/categories/useCategoriesExpanded'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
const props = defineProps<{
@@ -12,89 +15,191 @@ const emit = defineEmits<{
setCategories: [ids: CategoryId[]]
}>()
+const { t } = useI18n()
const categoriesStore = useCategoriesStore()
-const opened = ref<CategoryId[]>([])
-const childrenMap = computed(() => {
- const map = new Map<CategoryId, CategoryId[]>()
- for (const id of categoriesStore.categoriesRootIds)
- map.set(id, categoriesStore.getChildrenIds(id))
- return map
+const search = ref('')
+const searchInput = useTemplateRef<HTMLInputElement>('searchInput')
+const view = useStorage<'list' | 'grid'>('finapp.categoriesFilterView', 'list')
+
+const allRootIds = computed<CategoryId[]>(() => {
+ const items = categoriesStore.items
+ return [...categoriesStore.categoriesRootIds].sort((a, b) =>
+ (items[a]?.name ?? '').localeCompare(items[b]?.name ?? ''),
+ )
})
-function select(categoryId: CategoryId, isForce: boolean) {
- if (!isForce && categoriesStore.hasChildren(categoryId)) {
- if (opened.value.includes(categoryId)) {
- opened.value = opened.value.filter(id => id !== categoryId)
- }
- else {
- opened.value.push(categoryId)
- }
- return
- }
+const {
+ folderIcon,
+ isExpanded,
+ toggle,
+ toggleAll,
+} = useCategoriesExpanded('categoriesFilter', allRootIds)
- emit('selected', categoryId)
+function nameMatches(id: CategoryId, q: string) {
+ const cat = categoriesStore.items[id]
+ if (!cat)
+ return false
+ return cat.name.toLowerCase().includes(q)
}
-function onFilter(id: CategoryId) {
- emit('setCategories', childrenMap.value.get(id) ?? [])
+const searchQuery = computed(() => search.value.trim().toLowerCase())
+
+const filteredRootIds = computed<CategoryId[]>(() => {
+ const q = searchQuery.value
+ if (!q)
+ return allRootIds.value
+ return allRootIds.value.filter((rootId) => {
+ if (nameMatches(rootId, q))
+ return true
+ return categoriesStore.getChildrenIds(rootId).some(cid => nameMatches(cid, q))
+ })
+})
+
+function visibleChildrenIds(rootId: CategoryId): CategoryId[] {
+ const all = categoriesStore.getChildrenIds(rootId)
+ const q = searchQuery.value
+ if (!q)
+ return all
+ if (nameMatches(rootId, q))
+ return all
+ return all.filter(cid => nameMatches(cid, q))
}
-function isChildsSelected(categoryId: CategoryId) {
- return (childrenMap.value.get(categoryId) ?? []).some(id => props.selectedIds?.includes(id))
+function isRootExpanded(rootId: CategoryId) {
+ if (searchQuery.value)
+ return visibleChildrenIds(rootId).length > 0
+ return isExpanded(rootId)
}
-function isEveryChildsSelected(categoryId: CategoryId) {
- const children = childrenMap.value.get(categoryId) ?? []
+const hasNoMatches = computed(() =>
+ !!searchQuery.value && filteredRootIds.value.length === 0,
+)
+
+function isAllChildrenSelected(rootId: CategoryId) {
+ const children = categoriesStore.getChildrenIds(rootId)
if (!children.length)
return false
-
return children.every(id => props.selectedIds?.includes(id))
}
-onMounted(() => {
- props.selectedIds?.forEach((id) => {
- if (categoriesStore.items[id]?.parentId)
- opened.value.push(categoriesStore.items[id]?.parentId)
- })
+function rootActiveId(rootId: CategoryId): CategoryId | null {
+ if (props.selectedIds?.includes(rootId))
+ return rootId
+ if (isAllChildrenSelected(rootId))
+ return rootId
+ return null
+}
+
+function onRootClick(rootId: CategoryId) {
+ if (categoriesStore.hasChildren(rootId)) {
+ toggle(rootId)
+ return
+ }
+ emit('selected', rootId)
+}
+
+function onRootFilter(rootId: CategoryId) {
+ emit('setCategories', categoriesStore.getChildrenIds(rootId))
+}
+
+onMounted(async () => {
+ await nextTick()
+ searchInput.value?.focus()
})
</script>
<template>
- <div>
- <div
- v-for="categoryId in categoriesStore.categoriesRootIds"
- :key="categoryId"
- class="group/item"
- :class="{
- 'bg-elevated relative mb-2 rounded-md': opened.includes(categoryId),
- 'bg-elevated rounded-md': isChildsSelected(categoryId),
- '!border-primary/60 border': isEveryChildsSelected(categoryId),
- }"
- >
- <CategoriesItem
- :categoryId
- :lineWidth="4"
- :category="categoriesStore.items[categoryId]!"
- :activeItemId="props.selectedIds?.includes(categoryId) ? categoryId : null"
- @click="select(categoryId, false)"
- @filter.stop="onFilter(categoryId)"
- />
+ <div class="relative flex h-full min-h-0 flex-col overflow-hidden">
+ <div class="bg-default sticky top-0 z-20 flex items-center gap-2 px-3 pt-2 pb-2">
+ <input
+ ref="searchInput"
+ v-model="search"
+ type="text"
+ class="bg-elevated/30 placeholder:text-muted hover:bg-elevated/50 focus:bg-elevated/50 focus:border-primary m-0 min-h-[42px] flex-1 rounded-md border border-transparent px-4 py-2 text-base font-normal outline-none"
+ :placeholder="t('categories.search.placeholder')"
+ >
+ <div class="flex items-center">
+ <UiActionButton
+ :ariaLabel="$t('base.toggleView')"
+ @click="view = view === 'list' ? 'grid' : 'list'"
+ >
+ <Icon
+ :name="view === 'list' ? 'lucide:layout-grid' : 'lucide:list'"
+ size="20"
+ />
+ </UiActionButton>
+ <UiActionButton
+ :ariaLabel="$t('base.toggleFolders')"
+ @click="toggleAll"
+ >
+ <Icon :name="folderIcon" size="20" />
+ </UiActionButton>
+ </div>
+ </div>
+
+ <div class="scrollerBlock h-full overflow-y-auto px-3 pt-1 pb-4">
<div
- v-if="opened.includes(categoryId) && categoriesStore.hasChildren(categoryId)"
- class="pr-2 pb-2 pl-4"
+ v-if="hasNoMatches"
+ class="text-muted p-4 text-center"
>
- <CategoriesItem
- v-for="childCategoryId in childrenMap.get(categoryId)"
- :key="childCategoryId"
- :activeItemId="props.selectedIds?.includes(childCategoryId) ? childCategoryId : null"
- :category="categoriesStore.items[childCategoryId]!"
- :categoryId="childCategoryId"
- @click.stop="select(childCategoryId, true)"
- @filter.stop="onFilter(childCategoryId)"
- />
+ {{ t('categories.form.children.noMatches') }}
</div>
+
+ <template v-else>
+ <template
+ v-for="rootId in filteredRootIds"
+ :key="rootId"
+ >
+ <CategoriesItem
+ :activeItemId="rootActiveId(rootId)"
+ :category="categoriesStore.items[rootId]!"
+ :categoryId="rootId"
+ :isExpanded="isRootExpanded(rootId)"
+ :isShowChevron="categoriesStore.hasChildren(rootId)"
+ :leftMenuButton="true"
+ :hideLeftMenuButton="true"
+ :lineWidth="isRootExpanded(rootId) && categoriesStore.hasChildren(rootId) ? 0 : 1"
+ class="group"
+ @click="onRootClick(rootId)"
+ @toggle="toggle(rootId)"
+ @filter="onRootFilter(rootId)"
+ />
+
+ <div
+ v-if="isRootExpanded(rootId) && categoriesStore.hasChildren(rootId)"
+ :class="view === 'grid'
+ ? 'ml-2 pr-2 pb-4 pl-3'
+ : '-mt-px ml-5 pb-1 pl-3'"
+ >
+ <template v-if="view === 'list'">
+ <CategoriesItem
+ v-for="childId in visibleChildrenIds(rootId)"
+ :key="childId"
+ :activeItemId="props.selectedIds?.includes(childId) ? childId : null"
+ :category="categoriesStore.items[childId]!"
+ :categoryId="childId"
+ :leftMenuButton="true"
+ :hideLeftMenuButton="true"
+ :lineWidth="1"
+ class="group"
+ @click="emit('selected', childId)"
+ />
+ </template>
+
+ <div v-else class="flex flex-wrap gap-1">
+ <CategoriesRoundLink
+ v-for="childId in visibleChildrenIds(rootId)"
+ :key="childId"
+ :categoryId="childId"
+ :isActive="props.selectedIds?.includes(childId)"
+ @click="emit('selected', childId)"
+ />
+ </div>
+ </div>
+ </template>
+ </template>
</div>
</div>
</template>
diff --git a/app/app/components/categories/page/New.vue b/app/app/components/categories/page/New.vue
index 5ef037fa..6db085d8 100644
--- a/app/app/components/categories/page/New.vue
+++ b/app/app/components/categories/page/New.vue
@@ -2,6 +2,7 @@
import type { CategoryItem } from '~/components/categories/types'
import { categoryFormSchema } from '~/components/categories/types'
+import { canGoBack } from '~/composables/useNavigationHistory'
const { t } = useI18n()
const route = useRoute()
@@ -13,6 +14,14 @@ const isOnboarding = computed(() => 'onboarding' in route.query)
useHead({
title: `${t('base.add')}: ${categoryForm.value.name ? categoryForm.value.name : t('categories.form.name.label')}`,
})
+
+function onAfterSave(id: string) {
+ if (route.query.returnBack === '1' && canGoBack.value) {
+ router.back()
+ return
+ }
+ router.replace(isOnboarding.value ? '/dashboard' : `/categories/${id}`)
+}
</script>
<template>
@@ -37,7 +46,7 @@ useHead({
<CategoriesForm
:categoryForm="categoryForm"
@update="(key: string, value: CategoryItem[keyof CategoryItem]) => (categoryForm as Record<string, any>)[key] = value"
- @afterSave="(id: string) => router.replace(isOnboarding ? '/dashboard' : `/categories/${id}`)"
+ @afterSave="onAfterSave"
/>
</UiPage>
</template>
diff --git a/app/app/components/categories/page/id/Edit.vue b/app/app/components/categories/page/id/Edit.vue
index a48e16a9..8bce2a41 100644
--- a/app/app/components/categories/page/id/Edit.vue
+++ b/app/app/components/categories/page/id/Edit.vue
@@ -3,7 +3,7 @@ import type { CategoryId, CategoryItem } from '~/components/categories/types'
import { categoryFormSchema } from '~/components/categories/types'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
-import { navigateAfterSave } from '~/composables/useNavigationHistory'
+import { canGoBack, navigateAfterSave } from '~/composables/useNavigationHistory'
const { t } = useI18n()
const router = useRouter()
@@ -17,6 +17,13 @@ const categoryForm = ref(categoryFormSchema.parse(category.value))
useHead({
title: `${t('base.edit')}: ${categoryForm.value?.name || t('categories.form.name.label')}`,
})
+
+function onAfterSave() {
+ if (route.query.returnBack === '1' && canGoBack.value)
+ router.back()
+ else
+ navigateAfterSave(router, `/categories/${categoryId.value}`)
+}
</script>
<template>
@@ -32,7 +39,7 @@ useHead({
:categoryId="categoryId"
:categoryForm="categoryForm"
@update="(key: string, value: CategoryItem[keyof CategoryItem]) => (categoryForm as Record<string, any>)[key] = value"
- @afterSave="() => navigateAfterSave(router, `/categories/${categoryId}`)"
+ @afterSave="onAfterSave"
/>
</UiPage>
</template>
diff --git a/app/app/components/categories/useCategoryContextMenu.ts b/app/app/components/categories/useCategoryContextMenu.ts
index 6cfbbc54..08c7c4a1 100644
--- a/app/app/components/categories/useCategoryContextMenu.ts
+++ b/app/app/components/categories/useCategoryContextMenu.ts
@@ -3,42 +3,95 @@ import type { CategoryId } from '~/components/categories/types'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
export function useCategoryContextMenu(options?: {
+ excludeOpen?: boolean
onDelete?: (categoryId: CategoryId) => void
+ onEdit?: (categoryId: CategoryId) => void
+ returnBackOnSave?: boolean
+ withQuickToggles?: boolean
}) {
const { t } = useI18n()
const router = useRouter()
const categoriesStore = useCategoriesStore()
+ function toggleFlag(categoryId: CategoryId, key: 'showInLastUsed' | 'showInQuickSelector') {
+ const cat = categoriesStore.items[categoryId]
+ if (!cat)
+ return
+ categoriesStore.saveCategory({
+ id: categoryId,
+ isUpdateChildCategoriesColor: false,
+ values: { ...cat, [key]: !cat[key] },
+ })
+ }
+
function getCategoryContextMenuItems(categoryId: CategoryId) {
- if (categoryId === 'transfer')
+ if (categoryId === 'transfer' || categoryId === 'adjustment')
+ return undefined
+
+ const cat = categoriesStore.items[categoryId]
+ if (!cat)
return undefined
- const isChild = categoriesStore.items[categoryId]?.parentId !== 0
+ const isChild = cat.parentId !== 0
+ const hasChildren = categoriesStore.hasChildren(categoryId)
+ const editPath = options?.returnBackOnSave
+ ? `/categories/${categoryId}/edit?returnBack=1`
+ : `/categories/${categoryId}/edit`
const editGroup = [
- ...(isChild
- ? []
- : [{
+ ...(!options?.excludeOpen && !isChild
+ ? [{
icon: 'lucide:square-arrow-out-up-right',
label: t('base.open'),
onSelect: () => router.push(`/categories/${categoryId}`),
- }]),
+ }]
+ : []),
{
icon: 'lucide:pencil',
label: t('base.edit'),
- onSelect: () => router.push(`/categories/${categoryId}/edit`),
+ onSelect: () => options?.onEdit
+ ? options.onEdit(categoryId)
+ : router.push(editPath),
},
]
- if (!options?.onDelete)
- return [editGroup]
+ const groups: any[][] = [editGroup]
+
+ // Quick toggles only for leaf categories (those selectable in trnForm).
+ // Recent toggle is hidden when category is already a favorite — favorites
+ // supersede recents in the UI, so the recent flag is moot.
+ if (options?.withQuickToggles && !hasChildren) {
+ const toggles: any[] = [{
+ icon: 'lucide:star',
+ label: cat.showInQuickSelector
+ ? t('categories.actions.removeFromFavorites')
+ : t('categories.actions.addToFavorites'),
+ onSelect: () => toggleFlag(categoryId, 'showInQuickSelector'),
+ }]
+
+ if (!cat.showInQuickSelector) {
+ toggles.push({
+ icon: 'lucide:clock',
+ label: cat.showInLastUsed
+ ? t('categories.actions.removeFromRecent')
+ : t('categories.actions.addToRecent'),
+ onSelect: () => toggleFlag(categoryId, 'showInLastUsed'),
+ })
+ }
+
+ groups.push(toggles)
+ }
+
+ if (options?.onDelete) {
+ groups.push([{
+ color: 'error' as const,
+ icon: 'lucide:trash-2',
+ label: t('base.delete'),
+ onSelect: () => options.onDelete!(categoryId),
+ }])
+ }
- return [editGroup, [{
- color: 'error' as const,
- icon: 'lucide:trash-2',
- label: t('base.delete'),
- onSelect: () => options.onDelete!(categoryId),
- }]]
+ return groups
}
return { getCategoryContextMenuItems }
diff --git a/app/app/components/stat/filter/Selector.vue b/app/app/components/stat/filter/Selector.vue
index 09e94a15..3ecd6264 100644
--- a/app/app/components/stat/filter/Selector.vue
+++ b/app/app/components/stat/filter/Selector.vue
@@ -27,7 +27,7 @@ const isLaptop = computed(() => width.value >= 766 && pointerType.value === 'mou
<WalletsSelector
:filterAtTop="isLaptop"
:selectedIds="filter?.walletsIds.value"
- class="min-w-80 px-3"
+ class="min-w-80 px-2"
@selected="filter.toggleWalletId"
/>
</StatFilterSelectorItem>
@@ -39,14 +39,12 @@ const isLaptop = computed(() => width.value >= 766 && pointerType.value === 'mou
:title="t('categories.filter')"
icon="hugeicons:folder-library"
>
- <div class="scrollerBlock overflow-y-auto">
- <CategoriesSelectorTree
- :selectedIds="filter?.categoriesIds.value"
- class="min-w-80 px-3"
- @selected="filter.toggleCategoryId"
- @setCategories="filter.setCategories"
- />
- </div>
+ <CategoriesSelectorTree
+ :selectedIds="filter?.categoriesIds.value"
+ class="min-w-80"
+ @selected="filter.toggleCategoryId"
+ @setCategories="filter.setCategories"
+ />
</StatFilterSelectorItem>
</div>
</template>
diff --git a/app/app/components/trnForm/SelectionCategoriesFast.vue b/app/app/components/trnForm/SelectionCategoriesFast.vue
index 456ed627..271431cd 100644
--- a/app/app/components/trnForm/SelectionCategoriesFast.vue
+++ b/app/app/components/trnForm/SelectionCategoriesFast.vue
@@ -1,27 +1,120 @@
<script setup lang="ts">
+import { useWindowSize } from '@vueuse/core'
+
import type { CategoryId } from '~/components/categories/types'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
+import { useCategoryContextMenu } from '~/components/categories/useCategoryContextMenu'
import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'
+import { useTrnsStore } from '~/components/trns/useTrnsStore'
+import { showErrorToast, showSuccessToast } from '~/composables/useStoreSync'
const emit = defineEmits<{
selectCategory: [id: CategoryId]
}>()
const { t } = useI18n()
+const router = useRouter()
const categoriesStore = useCategoriesStore()
const trnsFormStore = useTrnsFormStore()
+const trnsStore = useTrnsStore()
+
+const { width } = useWindowSize()
+const { pointerType } = usePointer()
+const isLaptop = computed(() => width.value >= 766 && pointerType.value === 'mouse')
+
+const editingCategoryId = ref<CategoryId | null>(null)
+const isCreatingNewCategory = ref(false)
+const deleteCategoryId = ref<CategoryId | null>(null)
+
+function onClickNew() {
+ if (isLaptop.value)
+ router.push('/categories/new?returnBack=1')
+ else
+ isCreatingNewCategory.value = true
+}
+
+const deleteTrnsCount = computed(() => {
+ if (!deleteCategoryId.value)
+ return 0
+ return trnsStore.getStoreTrnsIds({
+ categoriesIds: categoriesStore.getChildrenIdsOrParent(deleteCategoryId.value),
+ }).length
+})
+
+const deleteDescText = computed(() =>
+ deleteTrnsCount.value > 0 ? t('categories.form.delete.alertWithTrns') : undefined,
+)
+
+const deleteHighlight = computed(() =>
+ deleteTrnsCount.value > 0 ? t('trns.plural', deleteTrnsCount.value) : undefined,
+)
+
+function onClickDelete(categoryId: CategoryId) {
+ for (const id of Object.keys(categoriesStore.items)) {
+ if (categoriesStore.items[id]?.parentId === categoryId) {
+ showErrorToast('categories.form.delete.errorChildren')
+ return
+ }
+ }
+ deleteCategoryId.value = categoryId
+}
+async function onDeleteConfirm() {
+ if (!deleteCategoryId.value)
+ return
+
+ const categoryId = deleteCategoryId.value
+ const trnsIds = [...trnsStore.getStoreTrnsIds({
+ categoriesIds: categoriesStore.getChildrenIdsOrParent(categoryId),
+ })]
+
+ deleteCategoryId.value = null
+ await categoriesStore.deleteCategory(categoryId, trnsIds)
+
+ setTimeout(() => {
+ showSuccessToast(trnsIds.length > 0
+ ? 'categories.form.delete.okWithTrns'
+ : 'categories.form.delete.okWithoutTrns', trnsIds.length > 0
+ ? { length: trnsIds.length, trns: t('trns.plural', trnsIds.length) }
+ : undefined)
+ }, 300)
+}
+
+const { getCategoryContextMenuItems: getLaptopMenuItems } = useCategoryContextMenu({
+ excludeOpen: true,
+ onDelete: onClickDelete,
+ returnBackOnSave: true,
+ withQuickToggles: true,
+})
+
+const { getCategoryContextMenuItems: getMobileMenuItems } = useCategoryContextMenu({
+ excludeOpen: true,
+ onDelete: onClickDelete,
+ onEdit: (id) => {
+ editingCategoryId.value = id
+ },
+ withQuickToggles: true,
+})
+
+function getCategoryContextMenuItems(categoryId: CategoryId) {
+ return isLaptop.value
+ ? getLaptopMenuItems(categoryId)
+ : getMobileMenuItems(categoryId)
+}
+
+const hasFavorites = computed(() => categoriesStore.favoriteCategoriesIds.length > 0)
+const hasRecent = computed(() => categoriesStore.recentCategoriesIds.length > 0)
const isShowAllCategoriesFallback = computed(() =>
- categoriesStore.favoriteCategoriesIds.length === 0
- && categoriesStore.recentCategoriesIds.length === 0
+ !hasFavorites.value
+ && !hasRecent.value
&& categoriesStore.categoriesIdsForTrnValues.length > 0,
)
</script>
<template>
<!-- Favorite categories -->
- <div v-if="categoriesStore.favoriteCategoriesIds.length > 0">
+ <div v-if="hasFavorites">
<UiTitleModal>
{{ t('categories.favoriteCategories') }}
</UiTitleModal>
@@ -30,6 +123,8 @@ const isShowAllCategoriesFallback = computed(() =>
:activeItemId="trnsFormStore.values.categoryId ?? undefined"
:ids="categoriesStore.favoriteCategoriesIds"
+ :getContextMenuItems="getCategoryContextMenuItems"
+ :onNew="hasRecent ? undefined : onClickNew"
class="px-3 pt-1"
@selected="id => emit('selectCategory', id)"
@@ -37,7 +132,7 @@ const isShowAllCategoriesFallback = computed(() =>
</div>
<!-- Recent categories -->
- <div v-if="categoriesStore.recentCategoriesIds.length > 0">
+ <div v-if="hasRecent">
<UiTitleModal>
{{ t('categories.recentCategories') }}
</UiTitleModal>
@@ -46,6 +141,8 @@ const isShowAllCategoriesFallback = computed(() =>
:activeItemId="trnsFormStore.values.categoryId ?? undefined"
:ids="categoriesStore.recentCategoriesIds"
+ :getContextMenuItems="getCategoryContextMenuItems"
+ :onNew="onClickNew"
class="px-3 pt-1"
@selected="id => emit('selectCategory', id)"
@@ -58,9 +155,26 @@ const isShowAllCategoriesFallback = computed(() =>
:activeItemId="trnsFormStore.values.categoryId ?? undefined"
:ids="categoriesStore.categoriesIdsForTrnValues"
+ :getContextMenuItems="getCategoryContextMenuItems"
+ :onNew="onClickNew"
class="px-3 pt-1"
@selected="id => emit('selectCategory', id)"
/>
</div>
+
+ <CategoriesEditModal
+ v-if="(editingCategoryId || isCreatingNewCategory) && !isLaptop"
+ :categoryId="editingCategoryId ?? undefined"
+ @closed="editingCategoryId = null; isCreatingNewCategory = false"
+ />
+
+ <LayoutConfirmModal
+ v-if="deleteCategoryId"
+ :title="t('categories.form.delete.title')"
+ :description="deleteDescText"
+ :highlight="deleteHighlight"
+ @closed="deleteCategoryId = null"
+ @confirm="onDeleteConfirm"
+ />
</template>
diff --git a/app/app/components/trnForm/SelectorCategory.vue b/app/app/components/trnForm/SelectorCategory.vue
index 98055c1c..9ed4af57 100644
--- a/app/app/components/trnForm/SelectorCategory.vue
+++ b/app/app/components/trnForm/SelectorCategory.vue
@@ -36,10 +36,10 @@ const isShow = ref(false)
</template>
<template #custom="{ close }">
- <CategoriesCommandPalette
+ <CategoriesSelectorModal
:hide="close"
:activeItemId="props.categoryId"
- class="min-w-80 px-3"
+ class="min-w-80"
@selected="(id: CategoryId) => { emit('selected', id); close() }"
/>
</template>
diff --git a/app/i18n/locales/en-US.js b/app/i18n/locales/en-US.js
index 83dd1b54..5f204434 100644
--- a/app/i18n/locales/en-US.js
+++ b/app/i18n/locales/en-US.js
@@ -58,6 +58,12 @@ export default {
},
categories: {
+ actions: {
+ addToFavorites: 'Add to favorites',
+ addToRecent: 'Show in recent',
+ removeFromFavorites: 'Remove from favorites',
+ removeFromRecent: 'Hide from recent',
+ },
allTitle: 'All',
createNewTitle: 'New category',
errors: {
@@ -118,7 +124,7 @@ export default {
recent: 'Recent',
recentCategories: 'Recent categories',
search: {
- placeholder: 'Search categories...',
+ placeholder: 'Search',
},
title: 'Categories',
},
diff --git a/app/i18n/locales/ru-RU.js b/app/i18n/locales/ru-RU.js
index 3fa43d3c..37e10a4c 100644
--- a/app/i18n/locales/ru-RU.js
+++ b/app/i18n/locales/ru-RU.js
@@ -58,6 +58,12 @@ export default {
},
categories: {
+ actions: {
+ addToFavorites: 'Добавить в избранное',
+ addToRecent: 'Показывать в недавних',
+ removeFromFavorites: 'Убрать из избранного',
+ removeFromRecent: 'Не показывать в недавних',
+ },
allTitle: 'Все',
createNewTitle: 'Добавление категории',
errors: {
@@ -118,7 +124,7 @@ export default {
recent: 'Недавние',
recentCategories: 'Недавние категории',
search: {
- placeholder: 'Поиск категорий...',
+ placeholder: 'Поиск',
},
title: 'Категории',
},