Newer
Older
gnexus-tasks / frontend / src / App.vue
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { api } from './api'
import { resolveLocale } from './i18n/locale'
import { setCurrency } from './taskui'
import type { UserInfo } from './types'

const route = useRoute()
const { t } = useI18n()
const user = ref<UserInfo | null>(null)
const accountUrl = ref('')

const navItems = computed(() => [
  { id: 'stack', label: t('nav.stack'), icon: 'ph-tray', to: '/stack' },
  { id: 'tree', label: t('nav.tree'), icon: 'ph-tree-structure', to: '/tree' },
  { id: 'list', label: t('nav.list'), icon: 'ph-list-bullets', to: '/list' },
  { id: 'projects', label: t('nav.projects'), icon: 'ph-folders', to: '/projects' },
  { id: 'options', label: t('nav.options'), icon: 'ph-shuffle', to: '/options' },
  { id: 'settings', label: t('nav.settings'), icon: 'ph-gear-six', to: '/settings' },
])

const currentLabel = computed(() => {
  const item = navItems.value.find((i) => i.to === route.path)
  if (item) return item.label
  // глубокие страницы: задача → страница задачи, проект → раздел проектов
  if (route.path.startsWith('/tasks/')) return t('nav.task')
  if (route.path.startsWith('/projects/')) return t('nav.projects')
  return 'gntodo'
})

onMounted(async () => {
  const res = await fetch('/auth/me')
  if (res.ok) {
    const data = await res.json()
    user.value = data.user
    accountUrl.value = data.account_url ?? ''
  }
  // валюта и язык — глобальные настройки; язык без переопределения берётся из SSO
  try {
    const s = await api.getSettings()
    setCurrency(s.currency)
    resolveLocale(s.language, user.value?.locale)
  } catch {
    setCurrency('UAH')
    resolveLocale(undefined, user.value?.locale)
  }
})
</script>

<template>
  <GnToastProvider>
    <GnNavigationShell
      brand="gntodo"
      logo-src="/logo.svg"
      :items="navItems"
      :current="currentLabel"
      :title="t('nav.sections')"
      :subtitle="t('nav.subtitle')"
    >
      <!-- Футер навигации: профиль + выход (паттерн profile-identity из кита,
           как в gnexus auth); чип топбара показывает текущий раздел -->
      <template #footer>
        <template v-if="user">
          <!-- Профиль — в системе авторизации (gnexus auth, раздел Account) -->
          <a class="profile-identity" :href="accountUrl" target="_blank" rel="noopener noreferrer">
            <span class="identity">
              <span class="avatar avatar-sm">
                <img v-if="user.avatar_url" :src="user.avatar_url" alt="" />
                <i v-else class="ph ph-user" aria-hidden="true"></i>
              </span>
              <span class="identity-content">
                <span class="identity-title">{{ user.email }}</span>
                <span class="identity-meta">{{ t('nav.account') }}</span>
              </span>
            </span>
          </a>
          <a class="btn-icon" href="/auth/logout" :aria-label="t('nav.signOut')">
            <i class="ph ph-sign-out" aria-hidden="true"></i>
          </a>
        </template>
      </template>
      <template #content>
        <div class="app-content">
          <RouterView />
        </div>
      </template>
    </GnNavigationShell>
  </GnToastProvider>
</template>

<style>
.app-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}
/* У кита .card имеет intrinsic max-width: 340px / width: max-content — в наших видах
   карточки должны заполнять колонку контента целиком (иначе обрезаются действия).
   overflow отключаем, иначе dropdown-меню внутри карточки обрезается. */
.app-content .card {
  max-width: 100%;
  width: 100%;
  overflow: visible;
}
/* знак в шапке крупнее дефолтных 22px кита */
.nav-topbar-brand img {
  width: 48px;
  height: 48px;
}
/* отделение заголовка страницы от контента (у кита margin нет) */
.app-content .page-header {
  margin-bottom: 1.5rem;
}
/* drawer детализации шире дефолтных 460px кита (на мобильных ограничен вьюпортом) */
.drawer-panel {
  width: min(760px, 100vw - 18px);
}
</style>