Skip to content

Commit 72386db

Browse files
committed
+ div.spinner-border#global-loading-spinner to fix rstacruz/nprogress#142 (comment) @ layouts/default.vue
+ `stores/globalLoading.ts` $ yarn remove {,@types/}nprogress @ fe
1 parent 9dc770e commit 72386db

8 files changed

Lines changed: 36 additions & 33 deletions

File tree

fe/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"lodash": "^4.17.21",
3030
"luxon": "^3.5.0",
3131
"noty": "^3.2.0-beta-deprecated",
32-
"nprogress": "^0.2.0",
3332
"nuxt": "^3.13.0",
3433
"scroll-into-view-if-needed": "^3.1.0",
3534
"tippy.js": "^6.3.7",
@@ -51,7 +50,6 @@
5150
"@types/lodash": "^4.17.7",
5251
"@types/luxon": "^3.4.2",
5352
"@types/node": "^22.5.0",
54-
"@types/nprogress": "^0.2.3",
5553
"@typescript-eslint/eslint-plugin": "^8.3.0",
5654
"@typescript-eslint/parser": "^8.3.0",
5755
"@vue/eslint-config-typescript": "^13.0.0",

fe/src/api/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { PublicRuntimeConfig } from 'nuxt/schema';
22
import type { Enabled, InfiniteData, Query, UseInfiniteQueryOptions, UseQueryOptions } from '@tanstack/vue-query';
33
import { QueryObserver } from '@tanstack/vue-query';
4-
import nProgress from 'nprogress';
54
import { FetchError } from 'ofetch';
65
import _ from 'lodash';
76

@@ -27,7 +26,7 @@ export const queryFunction = async <TResponse>
2726
signal?: AbortSignal
2827
): Promise<TResponse> => {
2928
if (import.meta.client) {
30-
nProgress.start();
29+
useGlobalLoadingStore().start();
3130
document.body.style.cursor = 'progress';
3231
}
3332
try {
@@ -48,7 +47,7 @@ export const queryFunction = async <TResponse>
4847
throw e;
4948
} finally {
5049
if (import.meta.client) {
51-
nProgress.done();
50+
useGlobalLoadingStore().stop();
5251
document.body.style.cursor = '';
5352
}
5453
}

fe/src/app.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ import { VueQueryDevtools } from '@tanstack/vue-query-devtools';
1313
import 'bootstrap/dist/css/bootstrap.min.css';
1414
import 'noty/lib/noty.css';
1515
import 'noty/lib/themes/mint.css';
16-
import nProgress from 'nprogress';
17-
import 'nprogress/nprogress.css';
1816
1917
useHead({
2018
titleTemplate: '%pageTitle %separator %siteName',
2119
templateParams: { separator: '-' }
2220
});
2321
2422
if (import.meta.client) {
25-
nProgress.configure({ trickleSpeed: 200 });
2623
await import('bootstrap');
2724
if (import.meta.dev) {
2825
await import('@/stats');

fe/src/checkCSS.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ checkcss.onClassnameDetected = className =>
77
'g-recaptcha',
88
'router-link-', // vue-router
99
'tsqd-', // @tanstack/vue-query-devtools
10-
'nprogress',
1110
'noty_',
1211
'tippy-',
1312
'viewer-',

fe/src/layouts/default.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<MinimumResolutionWarning />
66
</header>
77
<img :src="iconLoadingBlock" :class="{ 'd-none': !routeUpdatingStore.isUpdating }" id="loading-block" />
8+
<div
9+
:class="{ 'visually-hidden': !globalLoadingStore.isLoading }"
10+
class="spinner-border text-primary" role="status" id="global-loading-spinner">
11+
<span class="visually-hidden">Loading...</span>
12+
</div>
813
<main>
914
<AConfigProvider :locale="AntdZhCn">
1015
<slot v-if="!routeUpdatingStore.isUpdating" />
@@ -40,24 +45,27 @@
4045
<script setup lang="ts">
4146
import iconLoadingBlock from 'assets/icon-loading-block.svg';
4247
import AntdZhCn from 'ant-design-vue/es/locale/zh_CN';
43-
import nProgress from 'nprogress';
4448
45-
const routeUpdatingStore = useRouteUpdatingStore();
4649
const config = useRuntimeConfig().public;
50+
const routeUpdatingStore = useRouteUpdatingStore();
51+
const globalLoadingStore = useGlobalLoadingStore();
4752
const isReCAPTCHAEnabled = config.recaptchaSiteKey !== '';
4853
const isGoogleAnalyticsEnabled = config.gaMeasurementId !== '';
4954
5055
const noScriptStyle = `<style>
5156
#app-wrapper {
5257
pointer-events: unset !important;
5358
}
59+
#global-loading-spinner {
60+
visibility: hidden;
61+
}
5462
</style>`; // https://github.com/nuxt/nuxt/issues/13848
5563
useHead({ noscript: [{ innerHTML: noScriptStyle }] });
5664
const appPointerEvents = ref('none');
5765
if (import.meta.client) {
58-
nProgress.start();
66+
globalLoadingStore.start();
5967
onNuxtReady(() => {
60-
nProgress.done();
68+
globalLoadingStore.stop();
6169
appPointerEvents.value = 'unset';
6270
});
6371
}
@@ -74,6 +82,12 @@ if (import.meta.client) {
7482
#footer-lower {
7583
background-color: rgba(0,0,0,.2);
7684
}
85+
86+
#global-loading-spinner {
87+
position: absolute;
88+
right: 1rem;
89+
top: 1rem;
90+
}
7791
#loading-block {
7892
height: 200px;
7993
margin: auto;

fe/src/stores/globalLoading.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import _ from 'lodash';
2+
3+
export const useGlobalLoadingStore = defineStore('globalLoading', () => {
4+
const isLoading = ref(true); // show initially for noscript
5+
6+
const start = _.debounce(() => { isLoading.value = true }, 100);
7+
const stop = () => {
8+
start.cancel();
9+
isLoading.value = false;
10+
};
11+
12+
return { isLoading, start, stop };
13+
});

fe/src/stores/routeUpdating.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import nProgress from 'nprogress';
2-
31
export const useRouteUpdatingStore = defineStore('isRouteUpdating', () => {
2+
const globalLoadingStore = useGlobalLoadingStore();
43
let timeoutId = 0;
54
const isUpdating = ref(false);
65
const start = () => { isUpdating.value = true };
@@ -10,11 +9,11 @@ export const useRouteUpdatingStore = defineStore('isRouteUpdating', () => {
109
if (!import.meta.client)
1110
return;
1211
if (isUpdating.value) {
13-
timeoutId = window.setTimeout(() => { nProgress.start() }, 100);
12+
timeoutId = window.setTimeout(() => { globalLoadingStore.start() }, 100);
1413
window.setTimeout(end, 10000);
1514
} else {
1615
clearTimeout(timeoutId);
17-
nProgress.done();
16+
globalLoadingStore.stop();
1817
}
1918
});
2019

fe/yarn.lock

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,13 +2733,6 @@ __metadata:
27332733
languageName: node
27342734
linkType: hard
27352735

2736-
"@types/nprogress@npm:^0.2.3":
2737-
version: 0.2.3
2738-
resolution: "@types/nprogress@npm:0.2.3"
2739-
checksum: 10c0/cac0fe73aca79bc1472a1556f56303df72026f2fcd8dbe311fe84b1f46e454b9040c1e69223d94e3bf156a5986382170c52ebda19aa70f555f1b6855d8f744a6
2740-
languageName: node
2741-
linkType: hard
2742-
27432736
"@types/resolve@npm:1.20.2":
27442737
version: 1.20.2
27452738
resolution: "@types/resolve@npm:1.20.2"
@@ -8102,13 +8095,6 @@ __metadata:
81028095
languageName: node
81038096
linkType: hard
81048097

8105-
"nprogress@npm:^0.2.0":
8106-
version: 0.2.0
8107-
resolution: "nprogress@npm:0.2.0"
8108-
checksum: 10c0/eab9a923a1ad1eed71a455ecfbc358442dd9bcd71b9fa3fa1c67eddf5159360b182c218f76fca320c97541a1b45e19ced04e6dcb044a662244c5419f8ae9e821
8109-
languageName: node
8110-
linkType: hard
8111-
81128098
"nth-check@npm:^2.0.1, nth-check@npm:^2.1.1":
81138099
version: 2.1.1
81148100
resolution: "nth-check@npm:2.1.1"
@@ -10356,7 +10342,6 @@ __metadata:
1035610342
"@types/lodash": "npm:^4.17.7"
1035710343
"@types/luxon": "npm:^3.4.2"
1035810344
"@types/node": "npm:^22.5.0"
10359-
"@types/nprogress": "npm:^0.2.3"
1036010345
"@typescript-eslint/eslint-plugin": "npm:^8.3.0"
1036110346
"@typescript-eslint/parser": "npm:^8.3.0"
1036210347
"@vesp/nuxt-fontawesome": "npm:^1.1.0"
@@ -10374,7 +10359,6 @@ __metadata:
1037410359
lodash: "npm:^4.17.21"
1037510360
luxon: "npm:^3.5.0"
1037610361
noty: "npm:^3.2.0-beta-deprecated"
10377-
nprogress: "npm:^0.2.0"
1037810362
nuxt: "npm:^3.13.0"
1037910363
schema-dts: "npm:^1.1.2"
1038010364
scroll-into-view-if-needed: "npm:^3.1.0"

0 commit comments

Comments
 (0)