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