Skip to content

Commit

Permalink
feat: add spinnerLoader in a Teleport tag vuejs, so cool
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianBx committed Nov 22, 2023
1 parent 4c8f35d commit 4d1253a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</head>
<body>
<div id="app"></div>
<div id="modal-and-loader"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions src/components/LoadingCircle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

<style scoped>
.loader {
border: 4px solid transparent;
border-top: 4px solid #3498db;
border: 5px solid transparent;
border-top: 10px solid #3498db;
border-radius: 50%;
width: 50px;
height: 50px;
width: 105px;
height: 105px;
animation: spin 0.7s cubic-bezier(0.42, 0, 0.58, 1) infinite;
}
Expand Down
13 changes: 13 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ body::-webkit-scrollbar{
display: none;
}

#modal-and-loader {
position: fixed;
top: -250px;
left: 0;
z-index: 99;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
pointer-events: none;
}

.animate-fadeIn {
animation: fadeIn 0.5s ease-in-out;
}
Expand Down
8 changes: 5 additions & 3 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ onMounted(() => {
<div class="flex justify-center w-full pb-6">
<SearchBar />
</div>
<div v-show="isLoading" class="flex justify-center w-full">
<LoadingCircle />
</div>
<Teleport to="#modal-and-loader">
<div v-show="isLoading" class="flex justify-center w-full">
<LoadingCircle />
</div>
</Teleport>
<section
class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-8 gap-y-8"
>
Expand Down
8 changes: 7 additions & 1 deletion src/views/ShowSnippetView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { useGetSnippets } from "../composables/useGetSnippets";
import { useClipboard } from "@vueuse/core";
import PencilIcon from "../assets/icons/PencilIcon.vue";
import CopyIcon from "../assets/icons/CopyIcon.vue";
import LoadingCircle from "../components/LoadingCircle.vue";
import "../assets/highlight-syntax.css";
const authStore = useAuthStore();
const router = useRouter();
const date = new Date();
const id = router.currentRoute.value.params.id;
const { snippet, fetchSnippetById } = useGetSnippets();
const { isLoading, snippet, fetchSnippetById } = useGetSnippets();
const snippetData = reactive({
id: id as string,
Expand Down Expand Up @@ -78,6 +79,11 @@ onMounted(async () => {
Snippet: {{ snippetData.title }}
</h3>
</div>
<Teleport to="#modal-and-loader">
<div v-show="isLoading" class="flex justify-center w-full">
<LoadingCircle />
</div>
</Teleport>
<form class="space-y-6">
<div>
<h3>{{ snippetData.title }}</h3>
Expand Down

0 comments on commit 4d1253a

Please sign in to comment.