Skip to content

Commit

Permalink
Merge pull request #14 from fumeapp/redo-crumbs
Browse files Browse the repository at this point in the history
✨ simpler breadcrumbs
  • Loading branch information
acidjazz authored Aug 25, 2024
2 parents 2c319bf + 15871e1 commit 4339ae0
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 153 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ jobs:
test:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: bio-test
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: start mysql
run: sudo service mysql start
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
Expand Down
5 changes: 3 additions & 2 deletions app/components/header/HeaderMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ const { crumbs, actions } = useCrumb()
</template>
<template #right>
<div class="flex items-center space-x-2">
<header-auth />
<header-profile />
<u-color-mode-button />
</div>
</template>
</u-header>
<div class="bg-gray-100 dark:bg-gray-950">
<div class="py-2 px-4 sm:px-6 lg:px-8 max-w-7xl mx-auto">
<div class="flex items-center justify-between space-x-2 py-2">
<div v-if="crumbs.length" class="flex items-center justify-between space-x-2 py-2">
<u-breadcrumb :links="crumbs" />
<u-button-group v-if="actions && actions[0]" :size="actions[0].size">
<u-button v-for="action in actions" :key="action.label" v-bind="action" @click="action.click" />
</u-button-group>
</div>
<div v-else class="h-10" />
</div>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
<script setup lang="ts">
const { user, clear } = await useUserSession()
const { fromLink } = useCrumb()
const logout = async () => {
clear()
useApi().api('/api/logout')
await navigateTo('/')
}
const items = [
[
{
label: '',
email: user.value.email,
name: user.value.name,
slot: 'account',
disabled: true,
},
],
[
{
label: 'Tokens',
icon: 'i-mdi-key',
shortcuts: ['T'],
to: '/tokens',
},
{
label: 'Users',
icon: 'i-mdi-account-multiple',
to: '/users',
shortcuts: ['U'],
disabled: !user.value?.isAdmin,
},
{ shortcuts: ['T'], ...fromLink('Tokens') },
{ shortcuts: ['U'], disabled: !user.value.isAdmin, ...fromLink('Users') },
],
[
{
label: 'Logout',
icon: 'i-mdi-logout',
click: async () => {
clear()
useApi().api('/api/logout')
await navigateTo('/')
},
click: logout,
shortcuts: ['L'],
},
],
]
</script>

<template>
<u-dropdown v-if="user" :items="items">
<u-dropdown :items="items">
<u-avatar
:src="user.avatar"
size="sm"
icon="i-mdi-account-circle"
:ui="{ rounded: 'bg-gray-200 dark:bg-gray-800' }"
/>
<template #account>
<template #account="{ item }">
<div class="flex flex-col items-start">
<div class="font-semibold text-gray-800 dark:text-gray-300">{{ user.name }}</div>
<div class="text-sm text-gray-500 dark:text-gray-400">{{ user.email }}</div>
<div class="font-semibold text-gray-800 dark:text-gray-300">{{ item.name }}</div>
<div class="text-sm text-gray-500 dark:text-gray-400">{{ item.email }}</div>
</div>
</template>
</u-dropdown>
Expand Down
47 changes: 10 additions & 37 deletions app/composables/crumb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ButtonColor, ButtonSize } from '#ui/types'

import { links } from '~/utils/shared'
import { type HeaderIconLink, links } from '~/utils/shared'

interface Button {
label?: string
Expand All @@ -22,47 +22,20 @@ const crumbs = ref<HeaderIconLink[]>([])
const actions = ref<Button[]>([])

export const useCrumb = () => {
const action = (button: Button) => {
actions.value.push({ ...defaultAction, ...button })
return {
action,
}
}

const add = (label: string) => {
links.find(link => link.label === label ? crumbs.value.push(link) : null)
return {
add,
action,
// eslint-disable-next-line ts/no-use-before-define
custom,
}
}

const custom = (link: HeaderIconLink) => {
crumbs.value.push(link)
return {
add,
custom,
action,
}
}
const init = () => {
const set = (...crumbsArg: HeaderIconLink[]) => crumbs.value = crumbsArg
const action = (...actionsArg: Button[]) => actions.value = actionsArg.map(action => ({ ...defaultAction, ...action }))
const fromLink = (label: string): HeaderIconLink => links.find(link => label === link.label) as HeaderIconLink
const clear = () => {
crumbs.value = []
actions.value = []
return {
add,
action,
custom,
}
}

return {
crumbs,
actions,
set,
action,
add,
custom,
init,
fromLink,
actions,
crumbs,
clear,
}
}
2 changes: 0 additions & 2 deletions app/middleware/auth.global.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export default defineNuxtRouteMiddleware(async (to, _from) => {
const { loggedIn } = useUserSession()

useCrumb().init().add('Home')

const gatedRoutes = [
'/home',
'/token',
Expand Down
39 changes: 0 additions & 39 deletions app/pages/history.vue

This file was deleted.

2 changes: 2 additions & 0 deletions app/pages/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import type { Cartridge, Pen } from '@prisma/client'
import type { MetapiResponse } from '~/types/metapi'
useCrumb().clear()
const { data: page } = await useAsyncData('index', () => queryContent('/').findOne())
if (!page.value)
Expand Down
6 changes: 6 additions & 0 deletions app/pages/tokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ useSeoMeta({
ogDescription: page.value.description,
})
const { set, fromLink } = useCrumb()
set(
fromLink('Home'),
fromLink('Tokens'),
)
const { data: tokens, refresh } = await useFetch<MetapiResponse<Token[]>>('/api/token')
</script>

Expand Down
31 changes: 13 additions & 18 deletions app/pages/users/[user]/equipment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@ import type { User } from '~/types/models'
const route = useRoute()
const penModal = ref(false)
const cartridgeModal = ref(false)
const { data: user } = await useFetch<MetapiResponse<User>>(`/api/user/${route.params.user}`)
const { data: user } = await useFetch<MetapiResponse<User>>(`/api/all/user/${route.params.user}`)
useCrumb()
.custom({
label: 'Users',
icon: 'i-mdi-account-multiple',
to: '/users',
},
)
.custom({
label: user.value?.data.name as string,
icon: 'i-mdi-account',
})
.custom({
label: 'Equipment',
icon: 'i-mdi-medical-bag',
})
.action({ label: 'Add a Pen', click: () => penModal.value = true })
.action({ label: 'Add a Cartridge', click: () => cartridgeModal.value = true })
const { set, fromLink, action } = useCrumb()
set(
fromLink('Home'),
fromLink('Users'),
{ label: user.value?.data.name as string, icon: 'i-mdi-account' },
{ label: 'Equipment', icon: 'i-mdi-medical-bag' },
)
action(
{ label: 'Add a Pen', click: () => penModal.value = true },
{ label: 'Add a Cartridge', click: () => cartridgeModal.value = true },
)
const { data: pens, refresh: penRefresh } = await useFetch<MetapiResponse<Pen[]>>(`/api/user/${route.params.user}/pen`)
const { data: cartridges, refresh: cartRefresh } = await useFetch<MetapiResponse<Cartridge[]>>(`/api/user/${route.params.user}/cartridge`)
Expand Down
26 changes: 10 additions & 16 deletions app/pages/users/[user]/history.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ import type { Shot, User } from '~/types/models'
import type { MetapiResponse } from '~/types/metapi'
const route = useRoute()
const { data: user } = await useFetch<MetapiResponse<User>>(`/api/user/${route.params.user}`)
useCrumb()
.custom({
label: 'Users',
icon: 'i-mdi-account-multiple',
to: '/users',
})
.custom({
label: user.value?.data.name as string,
icon: 'i-mdi-account',
})
.custom({
label: 'Shots',
icon: 'i-mdi-syringe',
})
const { data: user } = await useFetch<MetapiResponse<User>>(`/api/all/user/${route.params.user}`)
const { set, fromLink } = useCrumb()
set(
fromLink('Home'),
fromLink('Users'),
{ label: user.value?.data.name as string, icon: 'i-mdi-account' },
fromLink('Shots'),
)
const columns = [
{ label: 'Cartridge', key: 'cartridge' },
Expand Down
13 changes: 11 additions & 2 deletions app/pages/users/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import { formatDistance } from 'date-fns'
import type { MetapiResponse } from '~/types/metapi'
import type { User } from '~/types/models'
useCrumb().add('Users')
const { set, fromLink } = useCrumb()
set(
fromLink('Home'),
{
label: 'Users',
icon: 'i-mdi-account-multiple',
to: '/users',
},
)
const columns = [
{
Expand All @@ -28,7 +37,7 @@ const columns = [
},
]
const { data: users } = await useFetch<MetapiResponse<User>>('/api/resource/user')
const { data: users } = await useFetch<MetapiResponse<User>>('/api/all/user')
</script>

<template>
Expand Down
11 changes: 10 additions & 1 deletion app/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ export const links: HeaderIconLink[] = [
icon: 'i-heroicons-home',
to: '/home',
},
{
label: 'Tokens',
icon: 'i-mdi-key',
to: '/tokens',
},
{
label: 'Users',
icon: 'i-mdi-account-multiple',
to: '/users',
},
{
label: 'Shots',
icon: 'i-mdi-syringe',
to: '/history',
},
]

Expand Down
2 changes: 1 addition & 1 deletion server/api/[...slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ routing.apiResource('/pen', router, pen)
routing.apiResource('/cartridge', router, cartridge)
routing.apiResource('/shot', router, shot)

routing.apiResource('/resource/user', router, user)
routing.apiResource('/all/user', router, user)
routing.apiResource('/user/:user/pen', router, pens)
routing.apiResource('/user/:user/cartridge', router, cartridges)
routing.apiResource('/user/:user/shot', router, shots)
Expand Down
Loading

0 comments on commit 4339ae0

Please sign in to comment.