1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-25 11:42:30 +01:00

new channel sorting

This commit is contained in:
Puyodead1 2023-11-27 17:32:59 -05:00
parent 5a654d340b
commit bdefa79025
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
2 changed files with 15 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import {
type GatewayGuildMemberListUpdateDispatchData,
} from "@spacebarchat/spacebar-api-types/v9";
import { ObservableMap, ObservableSet, action, computed, makeObservable, observable } from "mobx";
import { compareChannels } from "../../utils/Utils";
import AppStore from "../AppStore";
import GuildMemberListStore from "../GuildMemberListStore";
import GuildMemberStore from "../GuildMemberStore";
@ -142,9 +143,15 @@ export default class Guild {
@computed
get channels() {
return this.app.channels.all
.filter((channel) => this.channels_.has(channel.id))
.sort((a, b) => (a.position ?? 0) - (b.position ?? 0));
const guildChannels = this.app.channels.all.filter((channel) => this.channels_.has(channel.id));
const topLevelChannels = guildChannels.filter((channel) => !channel.parentId);
const sortedChannels = topLevelChannels
.sort(compareChannels)
.flatMap((topLevelChannel) => [
topLevelChannel,
...guildChannels.filter((channel) => channel.parentId === topLevelChannel.id).sort(compareChannels),
]);
return sortedChannels;
}
@computed

View File

@ -1,5 +1,6 @@
import * as Icons from "@mdi/js";
import { APIAttachment, EmbedType } from "@spacebarchat/spacebar-api-types/v9";
import Channel from "../stores/objects/Channel";
import { ARCHIVE_MIMES, EMBEDDABLE_AUDIO_MIMES, EMBEDDABLE_IMAGE_MIMES, EMBEDDABLE_VIDEO_MIMES } from "./constants";
export const decimalColorToHex = (decimal: number) => {
@ -128,3 +129,7 @@ export function hexToRGB(hex: string) {
b: parseInt(m[3], 16),
};
}
export function compareChannels(a: Channel, b: Channel): number {
return (a.position ?? 0) - (b.position ?? 0);
}