Skip to content

Commit

Permalink
Add initial support for a header menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Apr 2, 2024
1 parent 5e35a6a commit 68bf6cf
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 34 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require": {
"composer/installers": "^2.0",
"cweagans/composer-patches": "~1.0",
"dobefu/nuxtify_profile": "^1.0.0-alpha3",
"dobefu/nuxtify_profile": "^1.0.x-dev",
"drupal/core-composer-scaffold": "^10.2",
"drupal/core-recommended": "^10"
},
Expand Down
96 changes: 85 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/components/base/AuthBtns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const localePath = useLocalePath()
</script>

<template>
<div class="font-semibold">
<div>
<ClientOnly>
<template #fallback>
<div class="relative w-16 max-w-full">
Expand Down
51 changes: 38 additions & 13 deletions frontend/components/layout/Header.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
<script setup lang="ts">
import type { MenuAvailable } from '#build/graphql-operations'
const config = useRuntimeConfig()
const localePath = useLocalePath()
const { t } = useI18n()
const { locale, t } = useI18n()
const { data: menu } = await useAsyncData(
'menu',
async () => await useGraphqlQuery(
'menu',
{
name: 'MAIN' as MenuAvailable,
langcode: locale.value,
},
),
)
</script>

<template>
<header>
<div class="flex items-center justify-between max-w-6xl gap-4 py-4 sm:py-8 m-auto border-b">
<NuxtLink
class="text-xl sm:text-2xl font-semibold flex items-center gap-2"
:to="localePath('/')"
>
<NuxtImg
class="w-8 h-8 sm:w-12 sm:h-12"
src="/logo.svg"
:alt="t('site_logo', { name: config.public.siteName })"
/>
{{ config.public.siteName }}
</NuxtLink>
<div class="flex items-center justify-between max-w-6xl gap-4 py-4 sm:py-8 m-auto border-b font-semibold">
<div class="flex items-center gap-3 sm:gap-6">
<NuxtLink
class="text-xl sm:text-2xl flex items-center gap-2"
:to="localePath('/')"
>
<NuxtImg
class="w-8 h-8 sm:w-12 sm:h-12"
src="/logo.svg"
:alt="t('site_logo', { name: config.public.siteName })"
/>
{{ config.public.siteName }}
</NuxtLink>

<nav>
<NuxtLink
v-for="item in menu?.data?.menu?.items"
:key="item.id"
:to="localePath(item?.url || '')"
>
{{ item.title }}
</NuxtLink>
</nav>
</div>

<BaseAuthBtns />
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/composables/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function useAuth() {
return

try {
const userData: User | undefined = await $fetch('/api/auth/session', {
const userData = await $fetch<User | undefined>('/api/auth/session', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 0 additions & 4 deletions frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export default defineNuxtConfig({
},

routeRules: {
'/': {
swr: 300,
},
'/api/**': {
robots: false,
sitemap: false,
Expand Down Expand Up @@ -148,7 +145,6 @@ export default defineNuxtConfig({
'/api/sitemap',
],
exclude: [
'/api/**',
'/user',
'/user/logout',
'/user/register/confirm',
Expand Down
9 changes: 9 additions & 0 deletions frontend/queries/menu.query.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query menu($name: MenuAvailable!, $langcode: String!) {
menu(name: $name, langcode: $langcode) {
items {
id
title
url
}
}
}
4 changes: 2 additions & 2 deletions frontend/server/api/auth/session.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export default eventHandler(async (event): Promise<User | undefined> => {
const uid = body.uid

try {
const user: {
const user = await $fetch<{
[key: string]: { value: string }[]
} = await $fetch(`${process.env.NUXT_PUBLIC_BACKEND_URL}/user/${uid}?_format=json`, {
}>(`${process.env.NUXT_PUBLIC_BACKEND_URL}/user/${uid}?_format=json`, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineEventHandler(async (_event) => {
let cursor = '0'

do {
const { data }: { data: SitemapQuery } = await $fetch('/api/graphql/query/sitemap', {
const { data } = await $fetch<{ data: SitemapQuery }>('/api/graphql/query/sitemap', {
query: {
__variables: JSON.stringify({
first: itemsPerPage,
Expand Down

0 comments on commit 68bf6cf

Please sign in to comment.