diff --git a/html/src/app.js b/html/src/app.js index db4bf0b8..aecc28a3 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -6524,6 +6524,19 @@ speechSynthesis.getVoices(); return 0; }; + // descending + var compareByCreatedAt = function (a, b) { + var A = String(a.created_at).toUpperCase(); + var B = String(b.created_at).toUpperCase(); + if (A < B) { + return 1; + } + if (A > B) { + return -1; + } + return 0; + }; + // private var compareByPrivate = function (a, b) { if (typeof a.ref === 'undefined' || typeof b.ref === 'undefined') { @@ -8138,10 +8151,10 @@ speechSynthesis.getVoices(); $app.data.searchWorldOption = ''; $app.data.searchWorldParams = {}; $app.data.searchAvatarResults = []; - $app.data.searchAvatarParams = {}; + $app.data.searchAvatarFilter = ''; + $app.data.searchAvatarSort = ''; $app.data.isSearchUserLoading = false; $app.data.isSearchWorldLoading = false; - $app.data.isSearchAvatarLoading = false; API.$on('LOGIN', function () { $app.searchText = ''; @@ -8151,10 +8164,10 @@ speechSynthesis.getVoices(); $app.searchWorldOption = ''; $app.searchWorldParams = {}; $app.searchAvatarResults = []; - $app.searchAvatarParams = {}; + $app.searchAvatarFilter = ''; + $app.searchAvatarSort = ''; $app.isSearchUserLoading = false; $app.isSearchWorldLoading = false; - $app.isSearchAvatarLoading = false; }); $app.methods.clearSearch = function () { @@ -8166,6 +8179,7 @@ speechSynthesis.getVoices(); $app.methods.search = function () { this.searchUser(); this.searchWorld({}); + this.searchAvatar(); }; $app.methods.searchUser = async function () { @@ -8292,57 +8306,64 @@ speechSynthesis.getVoices(); }); }; - $app.methods.searchAvatar = function (option) { - var params = { - n: 10, - offset: 0 - }; - switch (option) { - case 'updated': - params.sort = 'updated'; - break; - case 'created': - params.sort = 'created'; - break; - case 'mine': - params.user = 'me'; - params.releaseStatus = 'all'; - break; - default: - params.sort = 'popularity'; - params.search = this.searchText; - break; + $app.methods.searchAvatar = function () { + if (!this.searchAvatarFilter) { + this.searchAvatarFilter = 'all'; } - params.order = 'descending'; - // TODO: option.platform - this.searchAvatarParams = params; - this.moreSearchAvatar(); - }; - - $app.methods.moreSearchAvatar = function (go) { - var params = this.searchAvatarParams; - if (go) { - params.offset += params.n * go; - if (params.offset < 0) { - params.offset = 0; + if (!this.searchAvatarSort) { + this.searchAvatarSort = 'name'; + } + var avatars = []; + var query = this.searchText.toUpperCase(); + if (!query) { + for (var ref of API.cachedAvatars.values()) { + if (ref.authorId === API.currentUser.id) { + avatars.push(ref); + } } - } - this.isSearchAvatarLoading = true; - API.getAvatars(params) - .finally(() => { - this.isSearchAvatarLoading = false; - }) - .then((args) => { - var map = new Map(); - for (var json of args.json) { - var ref = API.cachedAvatars.get(json.id); - if (typeof ref !== 'undefined') { - map.set(ref.id, ref); + } else { + for (var ref of API.cachedAvatars.values()) { + var match = ref.name.toUpperCase().includes(query); + if (!match && ref.description) { + match = ref.description.toUpperCase().includes(query); + } + if (!match && ref.authorName) { + match = ref.authorName.toUpperCase().includes(query); + } + if (match) { + switch (this.searchAvatarFilter) { + case 'all': + avatars.push(ref); + break; + case 'public': + if (ref.releaseStatus === 'public') { + avatars.push(ref); + } + break; + case 'private': + if (ref.releaseStatus === 'private') { + avatars.push(ref); + } + break; } } - this.searchAvatarResults = Array.from(map.values()); - return args; - }); + if (avatars.length >= 1000) { + break; + } + } + } + switch (this.searchAvatarSort) { + case 'updated': + avatars.sort(compareByUpdatedAt); + break; + case 'created': + avatars.sort(compareByCreatedAt); + break; + case 'name': + avatars.sort(compareByName); + break; + } + this.searchAvatarResults = avatars; }; // App: Favorite diff --git a/html/src/index.pug b/html/src/index.pug index 26524309..78658eab 100644 --- a/html/src/index.pug +++ b/html/src/index.pug @@ -255,25 +255,29 @@ html el-button-group(style="margin-top:15px") el-button(v-if="searchWorldParams.offset" @click="moreSearchWorld(-1)" icon="el-icon-back" size="small") Prev el-button(v-if="searchWorldResults.length" @click="moreSearchWorld(1)" icon="el-icon-right" size="small") Next - //- el-tab-pane(label="Avatar" v-loading="isSearchAvatarLoading" style="min-height:60px") - //- el-dropdown(@command="(command) => searchAvatar(command)" size="small" trigger="click" style="margin-bottom:15px") - //- el-button(size="small") Search by Category #[i.el-icon-arrow-down.el-icon--right] - //- el-dropdown-menu(#default="dropdown") - //- el-dropdown-item(command="updated") Updated Recently - //- el-dropdown-item(command="created") New - //- el-dropdown-item(command="mine") Mine - span(style="margin-left:10px;font-size:12px;color:#909399") Avatar search is not possible. - .x-friend-list + el-tab-pane(label="Avatar" style="min-height:60px") + el-tooltip(placement="bottom" content="Refresh own avatars" :disabled="hideTooltips") + el-button(type="default" :loading="userDialog.isAvatarsLoading" @click="refreshUserDialogAvatars()" size="mini" icon="el-icon-refresh" circle) + span(style="margin-left:5px") Total {{ searchAvatarResults.length }} + el-radio-group(v-model="searchAvatarSort" size="mini" style="margin-left:30px" @change="searchAvatar") + el-radio(label="name") by name + el-radio(label="update") by update + el-radio(label="created") by created + el-radio-group(v-model="searchAvatarFilter" size="mini" style="margin-left:80px" @change="searchAvatar") + el-radio(label="all") all + el-radio(label="public") public + el-radio(label="private") private + .x-friend-list(style="margin-top:20px") .x-friend-item(v-for="avatar in searchAvatarResults" :key="avatar.id" @click="showAvatarDialog(avatar.id)") template(v-once) .avatar img(v-lazy="avatar.thumbnailImageUrl") .detail span.name(v-text="avatar.name") + span.extra(v-text="avatar.releaseStatus" v-if="avatar.releaseStatus === 'public'" style="color: #67c23a;") + span.extra(v-text="avatar.releaseStatus" v-else-if="avatar.releaseStatus === 'private'" style="color: #f56c6c;") + span.extra(v-text="avatar.releaseStatus" v-else) span.extra(v-text="avatar.authorName") - el-button-group(style="margin-top:15px") - el-button(v-if="searchAvatarParams.offset" @click="moreSearchAvatar(-1)" icon="el-icon-back" size="small") Prev - el-button(v-if="searchAvatarResults.length" @click="moreSearchAvatar(1)" icon="el-icon-right" size="small") Next //- favorite .x-container(v-show="$refs.menu && $refs.menu.activeIndex === 'favorite'" v-if="$refs.menu && $refs.menu.activeIndex === 'favorite'")