Skip to content

Commit e43bc6c

Browse files
committed
feat: update NavbarJobs component to handle dropdown click outside
1 parent 4a0ea82 commit e43bc6c

3 files changed

Lines changed: 309 additions & 15 deletions

File tree

custom/NavbarJobs.vue

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
<template>
2-
<div class="cursor-pointer hover:scale-110 transition-transform" @click="isDropdownOpen = !isDropdownOpen">
3-
<div v-if="isAlLeastOneJobRunning" class="relative">
4-
<div class="loader "></div>
5-
<div class="absolute -bottom-1 -right-1 rounded-full bg-lightPrimary w-4 h-4 text-xs flex items-center justify-center text-white"> {{ jobsCount }}</div>
2+
<div ref="dropdownRef">
3+
<div class="cursor-pointer hover:scale-110 transition-transform" @click="isDropdownOpen = !isDropdownOpen">
4+
<div v-if="isAlLeastOneJobRunning" class="relative">
5+
<div class="loader "></div>
6+
<div class="absolute -bottom-1 -right-1 rounded-full bg-lightPrimary w-4 h-4 text-xs flex items-center justify-center text-white"> {{ jobsCount }}</div>
7+
</div>
8+
<div class="flex items-center justify-center" v-else-if="jobs.length > 0">
9+
<Tooltip>
10+
<IconCheckCircleOutline class="w-8 h-8 text-green-500" />
11+
<template #tooltip>
12+
{{ t('All jobs completed') }}
13+
</template>
14+
</Tooltip>
15+
</div>
616
</div>
7-
<div class="flex items-center justify-center" v-else-if="jobs.length > 0">
8-
<Tooltip>
9-
<IconCheckCircleOutline class="w-8 h-8 text-green-500" />
10-
<template #tooltip>
11-
{{ t('All jobs completed') }}
12-
</template>
13-
</Tooltip>
17+
<div v-if="isDropdownOpen" class="absolute right-28 top-14 md:top-12 rounded z-10">
18+
<JobsList :jobs="jobs" />
1419
</div>
1520
</div>
16-
<div v-if="isDropdownOpen" class="absolute right-28 top-14 md:top-12 rounded z-10">
17-
<JobsList :jobs="jobs" />
18-
</div>
1921

2022

2123
</template>
@@ -32,6 +34,7 @@
3234
import type { IJob } from './utils';
3335
import { callAdminForthApi } from '@/utils';
3436
import websocket from '@/websocket';
37+
import { onClickOutside } from '@vueuse/core'
3538
3639
const { t } = useI18n();
3740
@@ -44,6 +47,11 @@
4447
4548
const isDropdownOpen = ref(false);
4649
const jobs = ref<IJob[]>([]);
50+
const dropdownRef = ref<HTMLElement | null>(null);
51+
52+
onClickOutside(dropdownRef, () => {
53+
isDropdownOpen.value = false;
54+
});
4755
4856
const isAlLeastOneJobRunning = computed(() => {
4957
return jobs.value.some(job => job.status === 'IN_PROGRESS');

0 commit comments

Comments
 (0)