mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
184ed8e17d
## Summary - Moved out canvas loading handling to canvas store - Tag editable routes via meta to remove router dependency from generic helpers - Replace all occurrences of `genericHelpers` mixin with composable and audit usage - Moved out `isRedirectSafe` and `getRedirectQueryParameter` out of genericHelpers to remove dependency on router Removing the router dependency is important, because `useRouter` and `useRoute` compostables are only available if called from component instance. So if composable is nested within another composable, we wouldn't be able to use these. In this case we'd always need to inject the router and pass it through several composables. That's why I moved the `readonly` logic to router meta and `isRedirectSafe` and `getRedirectQueryParameter` out as they were only used in a single component. --------- Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
49 lines
1 KiB
TypeScript
49 lines
1 KiB
TypeScript
import { ref, computed } from 'vue';
|
|
import { useI18n } from '@/composables/useI18n';
|
|
import { ElLoading as Loading } from 'element-plus';
|
|
|
|
interface LoadingService {
|
|
text: string;
|
|
close: () => void;
|
|
}
|
|
|
|
export function useLoadingService() {
|
|
const i18n = useI18n();
|
|
const loadingService = ref<LoadingService | null>(null);
|
|
|
|
function startLoading(text?: string) {
|
|
if (loadingService.value !== null) {
|
|
return;
|
|
}
|
|
|
|
loadingService.value = Loading.service({
|
|
lock: true,
|
|
text: text || i18n.baseText('genericHelpers.loading'),
|
|
background: 'var(--color-dialog-overlay-background)',
|
|
}) as unknown as LoadingService;
|
|
}
|
|
|
|
function setLoadingText(text: string) {
|
|
if (loadingService.value) {
|
|
loadingService.value.text = text;
|
|
}
|
|
}
|
|
|
|
function stopLoading() {
|
|
if (loadingService.value) {
|
|
loadingService.value.close();
|
|
loadingService.value = null;
|
|
}
|
|
}
|
|
|
|
const isLoading = computed(() => loadingService.value !== null);
|
|
|
|
return {
|
|
loadingService,
|
|
isLoading,
|
|
startLoading,
|
|
setLoadingText,
|
|
stopLoading,
|
|
};
|
|
}
|