fix: fix channel table's sorting problem (#188)

This commit is contained in:
quzard 2023-06-21 23:42:55 +08:00 committed by GitHub
parent 70cffbc258
commit 1f3b3ca7ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -238,9 +238,17 @@ const ChannelsTable = () => {
if (channels.length === 0) return; if (channels.length === 0) return;
setLoading(true); setLoading(true);
let sortedChannels = [...channels]; let sortedChannels = [...channels];
sortedChannels.sort((a, b) => { if (typeof sortedChannels[0][key] === 'string'){
return ('' + a[key]).localeCompare(b[key]); sortedChannels.sort((a, b) => {
}); return ('' + a[key]).localeCompare(b[key]);
});
} else {
sortedChannels.sort((a, b) => {
if (a[key] === b[key]) return 0;
if (a[key] > b[key]) return -1;
if (a[key] < b[key]) return 1;
});
}
if (sortedChannels[0].id === channels[0].id) { if (sortedChannels[0].id === channels[0].id) {
sortedChannels.reverse(); sortedChannels.reverse();
} }