Skip to content

Commit a716045

Browse files
committed
feat: add loading view
1 parent 01fbd76 commit a716045

File tree

8 files changed

+67
-5
lines changed

8 files changed

+67
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@commitlint/cli": "^19.3.0",
1515
"@commitlint/config-conventional": "^19.2.2",
1616
"axios": "^1.7.2",
17+
"pinia": "^2.1.7",
1718
"primeicons": "^7.0.0",
1819
"vue": "^3.4.21",
1920
"vue-router": "4",

src/App.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<script setup>
22
import 'primeicons/primeicons.css'
3+
import { computed } from 'vue'
4+
import { useLoadingStore } from "@/store/loading";
5+
import Icon from "@/components/Icon.vue";
36
7+
const loadingStore = useLoadingStore();
8+
const isLoading = computed(() => loadingStore.isLoading);
49
</script>
510

611
<template>
12+
<div v-if="isLoading" class="bg-white/80 fixed top-0 left-0 z-[1000] h-screen w-full flex justify-center items-center">
13+
<Icon icon="pi-spin pi-spinner" className="text-3xl text-[#67c23a]"/>
14+
</div>
715
<router-view></router-view>
816
</template>
917

10-
<style scoped>
11-
12-
</style>

src/api/examsRepository.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import AxiosClient from "./axios";
2+
3+
const resource = "/category";
4+
5+
export default {
6+
get(classId: string) {
7+
return AxiosClient.get(`${resource}/${classId}/exams`);
8+
}
9+
}
10+

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createApp } from 'vue'
2+
import { createPinia } from 'pinia'
23
import './style.css'
34
import App from './App.vue'
45
import router from './router'
@@ -7,6 +8,7 @@ import loading from "@/assets/avatarDefault.webp";
78

89
const app = createApp(App)
910

11+
app.use(createPinia())
1012
app.use(router)
1113
app.use(VueLazyLoad, {
1214
loading,

src/store/.gitkeep

Whitespace-only changes.

src/store/loading.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { defineStore } from 'pinia';
2+
3+
interface LoadingState {
4+
isLoading: boolean;
5+
};
6+
7+
export const useLoadingStore = defineStore({
8+
id: "loading",
9+
10+
state: ():LoadingState => ({
11+
isLoading: false,
12+
}),
13+
14+
getters: {
15+
16+
},
17+
18+
actions: {
19+
changeLoadingState(_isLoading: boolean) {
20+
this.isLoading = _isLoading;
21+
if (_isLoading) {
22+
document.body.style.overflowY = "hidden";
23+
} else {
24+
document.body.style.overflowY = "scroll";
25+
}
26+
}
27+
}
28+
});

src/views/HomePage.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
:url="`/danh-sach-bai-tap/${category.slug}`"
99
/>
1010
</div>
11-
<div v-else>Loading...</div>
1211

1312
</template>
1413

1514
<script setup>
1615
import ListCard from"@/components/ListCard.vue";
1716
import { RepositoryFactory } from "@/api/RepositoryFactory";
1817
import { onMounted, reactive } from "vue";
18+
import { useLoadingStore } from "@/store/loading";
1919
20+
const loadingStore = useLoadingStore();
2021
const homeData = reactive([]);
2122
2223
onMounted(async ()=> {
2324
const HomeRepository = RepositoryFactory.get("home");
25+
loadingStore.changeLoadingState(true);
2426
const { data } = await HomeRepository.get();
27+
loadingStore.changeLoadingState(false);
2528
homeData.value = data;
2629
});
2730

yarn.lock

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@
545545
"@vue/compiler-dom" "3.4.29"
546546
"@vue/shared" "3.4.29"
547547

548-
"@vue/devtools-api@^6.5.1":
548+
"@vue/devtools-api@^6.5.0", "@vue/devtools-api@^6.5.1":
549549
version "6.6.3"
550550
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.6.3.tgz#b23a588154cba8986bba82b6e1d0248bde3fd1a0"
551551
integrity sha512-0MiMsFma/HqA6g3KLKn+AGpL1kgKhFWszC9U29NfpWK5LE7bjeXxySWJrOJ77hBz+TBrBQ7o4QJqbPbqbs8rJw==
@@ -1575,6 +1575,14 @@ pify@^2.3.0:
15751575
resolved "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz"
15761576
integrity sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==
15771577

1578+
pinia@^2.1.7:
1579+
version "2.1.7"
1580+
resolved "https://registry.yarnpkg.com/pinia/-/pinia-2.1.7.tgz#4cf5420d9324ca00b7b4984d3fbf693222115bbc"
1581+
integrity sha512-+C2AHFtcFqjPih0zpYuvof37SFxMQ7OEG2zV9jRI12i9BOy3YQVAHwdKtyyc8pDcDyIc33WCIsZaCFWU7WWxGQ==
1582+
dependencies:
1583+
"@vue/devtools-api" "^6.5.0"
1584+
vue-demi ">=0.14.5"
1585+
15781586
pirates@^4.0.1:
15791587
version "4.0.6"
15801588
resolved "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz"
@@ -1958,6 +1966,11 @@ vscode-uri@^3.0.8:
19581966
resolved "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.8.tgz"
19591967
integrity sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw==
19601968

1969+
vue-demi@>=0.14.5:
1970+
version "0.14.8"
1971+
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.8.tgz#00335e9317b45e4a68d3528aaf58e0cec3d5640a"
1972+
integrity sha512-Uuqnk9YE9SsWeReYqK2alDI5YzciATE0r2SkA6iMAtuXvNTMNACJLJEXNXaEy94ECuBe4Sk6RzRU80kjdbIo1Q==
1973+
19611974
vue-demi@^0.12.5:
19621975
version "0.12.5"
19631976
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.12.5.tgz#8eeed566a7d86eb090209a11723f887d28aeb2d1"

0 commit comments

Comments
 (0)