feat: will now properly re-order channels whenever a new club/soc is added
Some checks failed
On_Push / lint_fmt (push) Successful in 11s
On_Push / lint_clippy (push) Failing after 1m30s
On_Push / build (push) Has been skipped
On_Push / deploy (push) Has been skipped

This commit is contained in:
silver 2025-02-27 22:37:40 +00:00
parent 143483d3b3
commit 934842cbc9
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -363,28 +363,31 @@ pub mod committee {
} }
let mut channel_names = vec![]; let mut channel_names = vec![];
let mut positions = vec![];
for role in roles_db.values() { for role in roles_db.values() {
// save these to db // save these to db
db_role_set(db, role).await; db_role_set(db, role).await;
// pull out teh channel names
if re_order { if re_order {
channel_names.push((role.name_channel.to_owned(), role.id_channel)); let channel_id = role.id_channel.to_owned();
if let Some(channel) = channels.get_mut(&channel_id) {
// record the position of each of teh C&S channels
positions.push(channel.position);
// pull out teh channel names
channel_names.push((role.name_channel.to_owned(), channel_id));
}
} }
} }
if re_order { if re_order {
// sort by the position and name
positions.sort();
channel_names.sort_by_key(|(name, _)| name.to_owned()); channel_names.sort_by_key(|(name, _)| name.to_owned());
// get a list of all teh new positions
let mut new_positions = vec![]; let mut new_positions = vec![];
for (i, (_, id)) in channel_names.iter().enumerate() { for (i, (_, id)) in channel_names.iter().enumerate() {
if let Some(channel) = channels.get_mut(id) { new_positions.push((id.to_owned(), positions[i] as u64));
let position_new = i as u64;
if position_new != channel.position as u64 {
new_positions.push((channel.id.to_owned(), position_new));
}
}
} }
if !new_positions.is_empty() { if !new_positions.is_empty() {