chore: make sure role ordering updates are instantenous

pull/1139/head
izzy 2025-08-07 16:57:20 +02:00
parent 56af4b9423
commit 9d82873d2a
2 changed files with 18 additions and 27 deletions

2
external/revolt.js vendored

@ -1 +1 @@
Subproject commit cd9e84a337c72709b82bb4eca794ec7474a0ee7e
Subproject commit a45710f80cd7b4424a2114d2a32cbb83a4d95761

View File

@ -20,6 +20,7 @@ import {
ColourSwatches,
InputBox,
Category,
Row,
} from "@revoltchat/ui";
import Tooltip from "../../../components/common/Tooltip";
@ -94,10 +95,7 @@ export function useRolesForReorder(server: Server) {
* Role reordering component
*/
const RoleReorderPanel = observer(
({
server,
onRolesReordered,
}: Props & { onRolesReordered: () => void }) => {
({ server, onExit }: Props & { onExit: () => void }) => {
const initialRoles = useRolesForReorder(server);
const [roles, setRoles] = useState(initialRoles);
const [isReordering, setIsReordering] = useState(false);
@ -148,7 +146,6 @@ const RoleReorderPanel = observer(
});
console.log("Roles reordered successfully");
onRolesReordered();
} catch (error) {
console.error("Failed to reorder roles:", error);
setRoles(initialRoles);
@ -168,12 +165,20 @@ const RoleReorderPanel = observer(
<H1>
<Text id="app.settings.permissions.role_ranking" />
</H1>
<Button
palette="secondary"
disabled={!hasChanges || isReordering}
onClick={saveReorder}>
<Text id="app.special.modals.actions.save" />
</Button>
<Row>
<Button
palette="secondary"
onClick={onExit}
style={{ marginBottom: "16px" }}>
<Text id="app.special.modals.actions.back" />
</Button>
<Button
palette="secondary"
disabled={!hasChanges || isReordering}
onClick={saveReorder}>
<Text id="app.special.modals.actions.save" />
</Button>
</Row>
</SpaceBetween>
<RoleReorderContainer>
@ -244,7 +249,6 @@ export function useRoles(server: Server) {
*/
export const Roles = observer(({ server }: Props) => {
const [showReorderPanel, setShowReorderPanel] = useState(false);
const [rolesWereReordered, setRolesWereReordered] = useState(false);
// Consolidate all permissions that we can change right now.
const currentRoles = useRoles(server);
@ -271,26 +275,13 @@ export const Roles = observer(({ server }: Props) => {
margin-inline: auto 8px;
`;
const handleBackFromReorder = () => {
setShowReorderPanel(false);
if (rolesWereReordered) {
window.location.reload(); // Refresh because I don't actually care anymore.
}
};
if (showReorderPanel) {
return (
<div>
<RoleReorderPanel
server={server}
onRolesReordered={() => setRolesWereReordered(true)}
onExit={() => setShowReorderPanel(false)}
/>
<Button
palette="secondary"
onClick={handleBackFromReorder}
style={{ marginBottom: "16px" }}>
<Text id="app.special.modals.actions.back" />
</Button>
</div>
);
}