diff options
| author | Tusooa Zhu <tusooa@kazv.moe> | 2021-08-14 21:23:45 -0400 |
|---|---|---|
| committer | Tusooa Zhu <tusooa@kazv.moe> | 2022-09-18 13:19:50 -0400 |
| commit | ff2242e85dc89aa7479000cf469ca2bce5d60157 (patch) | |
| tree | 9a577350e43bb9c847dec03aae0173a9edeaf1f7 /src/modules/instance.js | |
| parent | 69b3102fb2396edb63abe98b4a69ebe311e22a70 (diff) | |
Fix load more emoji action
Diffstat (limited to 'src/modules/instance.js')
| -rw-r--r-- | src/modules/instance.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/modules/instance.js b/src/modules/instance.js index bfce6f38..23f534c3 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -164,6 +164,16 @@ const instance = { if (res.ok) { const result = await res.json() const values = Array.isArray(result) ? Object.assign({}, ...result) : result + const caseInsensitiveStrCmp = (a, b) => { + const la = a.toLowerCase() + const lb = b.toLowerCase() + return la > lb ? 1 : (la < lb ? -1 : 0) + } + const byPackThenByName = (a, b) => { + const packOf = emoji => (emoji.tags.filter(k => k.startsWith('pack:'))[0] || '').slice(5) + return caseInsensitiveStrCmp(packOf(a), packOf(b)) || caseInsensitiveStrCmp(a.displayText, b.displayText) + } + const emoji = Object.entries(values).map(([key, value]) => { const imageUrl = value.image_url return { @@ -174,7 +184,7 @@ const instance = { } // Technically could use tags but those are kinda useless right now, // should have been "pack" field, that would be more useful - }).sort((a, b) => a.displayText.toLowerCase() > b.displayText.toLowerCase() ? 1 : -1) + }).sort(byPackThenByName) commit('setInstanceOption', { name: 'customEmoji', value: emoji }) } else { throw (res) |
