itube-specs 0.0.726 → 0.0.728
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ELanguage } from '../runtime';
|
|
2
|
+
import type { IGroupCategories } from '../types';
|
|
3
|
+
|
|
4
|
+
export const useFetchGroupsCategoriesLazy = (
|
|
5
|
+
apiMethod: (...args: any[]) => Promise<IGroupCategories[]>
|
|
6
|
+
) => {
|
|
7
|
+
const data = useState<IGroupCategories[] | null>('lazy-groups-categories', () => null);
|
|
8
|
+
const isLoading = useState<boolean>('lazy-groups-categories-loading', () => false);
|
|
9
|
+
const lang = useLang() as ELanguage;
|
|
10
|
+
|
|
11
|
+
async function load() {
|
|
12
|
+
if (data.value?.length || isLoading.value) return;
|
|
13
|
+
isLoading.value = true;
|
|
14
|
+
try {
|
|
15
|
+
data.value = await apiMethod(lang);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error('Failed to load groups categories:', err);
|
|
18
|
+
} finally {
|
|
19
|
+
isLoading.value = false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { data, isLoading, load };
|
|
24
|
+
};
|