From 457180ecafc8bc931e6b7b7b9a3988e41775aa64 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Sat, 18 Dec 2021 12:09:24 +0300 Subject: [PATCH] client: implement a buggy inifinite scroll on folder view --- server/app/api.py | 19 ++++---- server/app/models.py | 15 ++++-- src/components/FolderView/SongList.vue | 7 ++- src/composables/getFiles.js | 14 ++++-- src/views/FolderView.vue | 66 ++++++++++++++++++++------ 5 files changed, 86 insertions(+), 35 deletions(-) diff --git a/server/app/api.py b/server/app/api.py index a0eee770..21afd4d5 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -46,18 +46,20 @@ def search_by_title(): else: query = request.args.get('q') + all_songs = [] + songs = all_songs_instance.find_song_by_title(query) - all_songs = convert_to_json(songs) + all_songs.append(convert_to_json(songs)) - albums = all_songs_instance.find_songs_by_album(query) - all_songs.append(convert_to_json(albums)) + songs_by_albums = all_songs_instance.find_songs_by_album(query) + all_songs.append(convert_to_json(songs_by_albums)) - artists = all_songs_instance.find_songs_by_artist(query) - all_songs.append(convert_to_json(artists)) + songs_by_artists = all_songs_instance.find_songs_by_artist(query) + all_songs.append(convert_to_json(songs_by_artists)) - songs = remove_duplicates(all_songs) + # songs = remove_duplicates(all_songs) - return {'songs': songs} + return {'songs': all_songs} @bp.route('/populate') @@ -272,6 +274,7 @@ def getFolderTree(): start = time.time() req_dir = request.args.get('f') + last_id = request.args.get('last_id') if req_dir is not None: requested_dir = home_dir + req_dir @@ -298,7 +301,7 @@ def getFolderTree(): if entry.is_file(): if isValidFile(entry.name) == True: - songs_array = all_songs_instance.find_songs_by_folder(req_dir) + songs_array = all_songs_instance.find_songs_by_folder(req_dir, last_id) songs = convert_to_json(songs_array) for song in songs: song['artists'] = song['artists'].split(', ') diff --git a/server/app/models.py b/server/app/models.py index 93f22198..6e3dd15d 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -45,12 +45,13 @@ class AllSongs(Mongo): # def drop_db(self): # self.collection.drop() - + def get_song_by_id(self, file_id): return self.collection.find_one({'_id': ObjectId(file_id)}) def insert_song(self, song_obj): - self.collection.update({'filepath': song_obj['filepath']}, song_obj, upsert=True) + self.collection.update( + {'filepath': song_obj['filepath']}, song_obj, upsert=True) def find_song_by_title(self, query): self.collection.create_index([('title', pymongo.TEXT)]) @@ -62,8 +63,12 @@ class AllSongs(Mongo): def get_all_songs(self): return self.collection.find() - def find_songs_by_folder(self, query): - return self.collection.find({'folder': query}) + def find_songs_by_folder(self, query, last_id=None): + limit = 18 + if last_id is None: + return self.collection.find({'folder': query}).limit(limit) + else: + return self.collection.find({'folder': query, '_id': {'$gt': ObjectId(last_id)}}).limit(limit) def find_songs_by_artist(self, query): return self.collection.find({'artists': {'$regex': query, '$options': 'i'}}) @@ -79,4 +84,4 @@ class AllSongs(Mongo): self.collection.remove({'filepath': filepath}) return True except: - return False \ No newline at end of file + return False diff --git a/src/components/FolderView/SongList.vue b/src/components/FolderView/SongList.vue index 32806d63..222e1b96 100644 --- a/src/components/FolderView/SongList.vue +++ b/src/components/FolderView/SongList.vue @@ -1,7 +1,7 @@