Skip to content

Commit 5ba06d3

Browse files
committed
feat(pages): add mini sidebar button loading state
1 parent f6c5f7e commit 5ba06d3

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

apps/client/src/components/MiniSidebarBtn.vue

+55-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@
55
:active="active"
66
v-ripple
77
:disable="disable"
8+
v-bind="{
9+
...$attrs,
10+
11+
onClick: (...args) => onClick(args, $attrs),
12+
}"
813
>
914
<q-item-section avatar>
10-
<q-icon :name="icon" />
15+
<q-circular-progress
16+
v-if="loading"
17+
indeterminate
18+
size="20px"
19+
style="margin-left: 2px"
20+
/>
21+
22+
<q-icon
23+
v-else
24+
:name="icon"
25+
/>
1126
</q-item-section>
1227

1328
<q-tooltip
@@ -25,11 +40,47 @@
2540
</q-item>
2641
</template>
2742

28-
<script setup lang="ts">
29-
defineProps<{
43+
<script lang="ts">
44+
export default {
45+
inheritAttrs: false,
46+
};
47+
48+
export interface MiniSidebarBtnProps extends QItemProps {
49+
delay?: boolean;
3050
active?: boolean;
3151
icon: string;
3252
tooltip: string;
3353
disable?: boolean;
34-
}>();
54+
}
55+
</script>
56+
57+
<script setup lang="ts">
58+
import { sleep } from '@stdlib/misc';
59+
import type { QItemProps } from 'quasar';
60+
61+
const props = defineProps<MiniSidebarBtnProps>();
62+
63+
const loading = ref(false);
64+
65+
async function onClick(args: any[], attrs: any) {
66+
if (attrs.onClick == null) {
67+
return;
68+
}
69+
70+
args[0].preventDefault();
71+
72+
loading.value = true;
73+
74+
if (props.delay) {
75+
await sleep(500);
76+
}
77+
78+
try {
79+
await attrs.onClick(...args);
80+
} catch (error) {
81+
mainLogger.error(error);
82+
}
83+
84+
loading.value = false;
85+
}
3586
</script>

0 commit comments

Comments
 (0)