Skip to content

Commit

Permalink
add navbar loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD committed Feb 27, 2025
1 parent 5726e54 commit b62c458
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
7 changes: 4 additions & 3 deletions apps/shelve/app/components/layout/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const allNavigations = computed(() => {
const isSearchActive = ref(false)
const searchQuery = ref('')
const selectedTeamIndex = ref(0)
const loading = useNavbarLoading()
const toggleSearch = () => {
isSearchActive.value = !isSearchActive.value
Expand Down Expand Up @@ -77,9 +78,9 @@ defineShortcuts({
<div class="navbar-wrapper flex flex-col sm:flex-row sm:items-center gap-4">
<LayoutGroup>
<Motion :layout="true" class="outline-none">
<BgHighlight rounded="full" class="hover:scale-105">
<BgHighlight rounded="full" class="hover:scale-105 cursor-pointer" @click="toggleSearch">
<div class="navbar">
<div class="nav-item p-0.5! cursor-pointer" @click="toggleSearch">
<div class="nav-item p-0.5!">
<UIcon :name="isSearchActive ? 'lucide:x' : 'lucide:search'" class="text-lg" />
</div>
</div>
Expand All @@ -102,7 +103,7 @@ defineShortcuts({
:exit="{ opacity: 0 }"
:transition="{ duration: 0.2 }"
>
<UIcon name="lucide:search" class="icon mb-0.5 mr-2" />
<UIcon :name="loading ? 'lucide:loader' : 'lucide:search'" class="icon mr-2" :class="loading ? 'animate-spin' : ''" />
<input
id="search-input"
v-model="searchQuery"
Expand Down
12 changes: 6 additions & 6 deletions apps/shelve/app/components/team/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import type { CommandItem } from '@types'
import { AnimatePresence, Motion } from 'motion-v'
const isSearchActive = defineModel<boolean>({ required: false })
const search = defineModel<string>('search', { required: false })
const isSearchActive = defineModel<boolean>({ required: true })
const search = defineModel<string>('search', { required: true })
const selectedIndex = defineModel<number>('selectedIndex', { required: false, default: 0 })
const { createTeam } = useTeamsService()
// Command palette setup
const { commandGroups, createTeamFromSearch, version, subMenuState, deactivateSubMenu } = useAppCommands()
const { commandGroups, version, subMenuState, deactivateSubMenu } = useAppCommands()
const {
scrollContainerRef,
Expand All @@ -16,7 +17,6 @@ const {
getItemGlobalIndex,
navigateUp,
navigateDown,
selectCurrentItem,
scrollToSelectedItem
} = useCommandPalette(search, commandGroups, {
onClose: () => {
Expand Down Expand Up @@ -58,7 +58,7 @@ const handleSubmenuAction = (item: CommandItem, index: number) => {
savedMainMenuIndex = index
// Execute the action (which will activate the submenu)
item.action()
if (item.action) item.action()
// Reset selection in new submenu
selectedIndex.value = 0
Expand Down Expand Up @@ -193,7 +193,7 @@ function playAction(item: CommandItem, index: number) {
<CustomButton
:label="`Create ${search} team`"
loading-auto
@click="createTeamFromSearch(search)"
@click="createTeam(search)"
/>
</div>
</div>
Expand Down
9 changes: 1 addition & 8 deletions apps/shelve/app/composables/useAppCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function useAppCommands() {
icon: 'lucide:bug',
description: 'Report a bug or issue',
action: () => {
window.open('https://github.com/hugorcd/shelve/issues', '_blank')
window.open('https://github.com/HugoRCD/shelve/issues/new/choose', '_blank')
},
keywords: ['issues', 'bug', 'report', 'problem'],
},
Expand Down Expand Up @@ -321,15 +321,8 @@ export function useAppCommands() {
]
})

// Helper function to create a team
const createTeamFromSearch = async (teamName: string) => {
if (!teamName) return
await createTeam(teamName)
}

return {
commandGroups,
createTeamFromSearch,
version,
currentTeam,
subMenuState,
Expand Down
4 changes: 4 additions & 0 deletions apps/shelve/app/composables/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ export function useEnvironments(): Ref<Environment[]> {
export function useVariables(projectId: string): Ref<Variable[]> {
return useState<Variable[]>(`variables-${projectId}`)
}

export function useNavbarLoading(): Ref<boolean> {
return useState<boolean>('navbar-loading', () => false)
}
3 changes: 3 additions & 0 deletions apps/shelve/app/composables/useTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function useTeamsService() {
const currentTeam = useTeam()
const loading = ref(false)
const createLoading = ref(false)
const navbarLoading = useNavbarLoading()

const defaultTeamSlug = useCookie<string>('defaultTeamSlug')

Expand Down Expand Up @@ -50,6 +51,7 @@ export function useTeamsService() {

async function createTeam(name: string): Promise<Team | undefined> {
createLoading.value = true
navbarLoading.value = true
try {
const team = await $fetch<Team>('/api/teams', {
method: 'POST',
Expand All @@ -67,6 +69,7 @@ export function useTeamsService() {
toast.error('Failed to create team')
} finally {
createLoading.value = false
navbarLoading.value = false
}
}

Expand Down

0 comments on commit b62c458

Please sign in to comment.