add loader

This commit is contained in:
geoffrey45
2021-12-19 14:14:56 +03:00
parent 7e67b819f0
commit 643aab1ad9
3 changed files with 40 additions and 11 deletions
+1 -3
View File
@@ -18,7 +18,6 @@ from app import cache
import os import os
import requests import requests
import urllib import urllib
import time
from progress.bar import Bar from progress.bar import Bar
from mutagen.flac import MutagenError from mutagen.flac import MutagenError
@@ -260,8 +259,6 @@ def getFolderTree(folder: str = None):
dir_list = req_dir.split('/') dir_list = req_dir.split('/')
requested_dir = os.path.join(home_dir, *dir_list) requested_dir = os.path.join(home_dir, *dir_list)
print(requested_dir)
dir_content = os.scandir(requested_dir) dir_content = os.scandir(requested_dir)
folders = [] folders = []
@@ -293,6 +290,7 @@ def getFolderTree(folder: str = None):
for file in files: for file in files:
file['filepath'] = file['filepath'].replace(home_dir, '') file['filepath'] = file['filepath'].replace(home_dir, '')
return {"files": files, "folders": folders} return {"files": files, "folders": folders}
+27 -3
View File
@@ -2,20 +2,21 @@
<div class="folder-top flex"> <div class="folder-top flex">
<div class="fname"> <div class="fname">
<div> <div>
<div class="ellip">{{ path.split('/').splice(-1) + "" }}</div> <div class="ellip">{{ path.split("/").splice(-1) + "" }}</div>
</div> </div>
</div> </div>
<div class="fsearch"> <div class="fsearch">
<div> <div>
<input type="search" placeholder="Search this directory" /> <input type="search" placeholder="Search this directory" />
</div> </div>
<div v-if="loading" class="loader"></div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
props: ["path"] props: ["path", "loading"],
}; };
</script> </script>
@@ -35,8 +36,31 @@ export default {
} }
.folder-top .fsearch { .folder-top .fsearch {
position: relative;
width: 50%; width: 50%;
margin-right: 1rem; padding-right: 3rem;
.loader {
position: absolute;
top: $small;
right: 0;
width: 2rem;
height: 2rem;
border-radius: 50%;
border: solid;
border-top: solid rgb(255, 174, 0);
border-left: solid rgb(255, 174, 0);
animation: spin .2s linear infinite;
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
}
} }
.folder-top .fsearch div { .folder-top .fsearch div {
+12 -5
View File
@@ -1,7 +1,7 @@
<template> <template>
<div id="f-view-parent" class="rounded"> <div id="f-view-parent" class="rounded">
<div class="fixed"> <div class="fixed">
<SearchBox :path="path" /> <SearchBox :path="path" :loading="loading" />
</div> </div>
<div id="scrollable" ref="scrollable"> <div id="scrollable" ref="scrollable">
<FolderList :folders="folders" /> <FolderList :folders="folders" />
@@ -33,14 +33,15 @@ export default {
const songs = ref([]); const songs = ref([]);
const folders = ref([]); const folders = ref([]);
const last_page = ref([]);
const last_song_id = ref(null);
const scrollable = ref(null); const scrollable = ref(null);
const loading = ref(false);
const last_song_id = ref(null);
const last_page = ref([]);
onMounted(() => { onMounted(() => {
const getPathFolders = (path, last_id) => { const getPathFolders = (path, last_id) => {
loading.value = true;
getData(path, last_id).then((data) => { getData(path, last_id).then((data) => {
scrollable.value.scrollTop = 0; scrollable.value.scrollTop = 0;
@@ -52,6 +53,7 @@ export default {
} }
folders.value = data.folders.value; folders.value = data.folders.value;
loading.value = false;
}); });
}; };
@@ -59,7 +61,7 @@ export default {
watch(route, (new_route) => { watch(route, (new_route) => {
path.value = new_route.params.path; path.value = new_route.params.path;
getPathFolders(path.value); getPathFolders(path.value);
}); });
scrollable.value.onscroll = () => { scrollable.value.onscroll = () => {
@@ -70,9 +72,12 @@ export default {
let offset = height - scrollY; let offset = height - scrollY;
if (offset == 0 || offset == 1) { if (offset == 0 || offset == 1) {
loading.value = true;
getData(path.value, last_song_id.value).then((data) => { getData(path.value, last_song_id.value).then((data) => {
songs.value = songs.value.concat(data.songs.value); songs.value = songs.value.concat(data.songs.value);
loading.value = false;
if (songs.value.length) { if (songs.value.length) {
last_song_id.value = songs.value.slice(-1)[0]._id.$oid; last_song_id.value = songs.value.slice(-1)[0]._id.$oid;
} }
@@ -86,6 +91,7 @@ export default {
folders, folders,
path, path,
scrollable, scrollable,
loading,
}; };
}, },
}; };
@@ -111,6 +117,7 @@ export default {
#scrollable { #scrollable {
overflow-y: scroll; overflow-y: scroll;
height: 100%; height: 100%;
margin-top: $small;
&::-webkit-scrollbar { &::-webkit-scrollbar {
display: none; display: none;