mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix hotbar items drag-n-drop bugs (#4433)
This commit is contained in:
parent
0673c98f4e
commit
8ff7c03993
@ -230,6 +230,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
restackItems(from: number, to: number): void {
|
restackItems(from: number, to: number): void {
|
||||||
const { items } = this.getActive();
|
const { items } = this.getActive();
|
||||||
const source = items[from];
|
const source = items[from];
|
||||||
|
|||||||
@ -29,6 +29,14 @@
|
|||||||
width: var(--hotbar-width);
|
width: var(--hotbar-width);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
&.draggingOver::after {
|
||||||
|
content: " ";
|
||||||
|
position: fixed;
|
||||||
|
left: var(--hotbar-width);
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.HotbarItems {
|
.HotbarItems {
|
||||||
--cellWidth: 40px;
|
--cellWidth: 40px;
|
||||||
--cellHeight: 40px;
|
--cellHeight: 40px;
|
||||||
|
|||||||
@ -33,6 +33,7 @@ import { HotbarSelector } from "./hotbar-selector";
|
|||||||
import { HotbarCell } from "./hotbar-cell";
|
import { HotbarCell } from "./hotbar-cell";
|
||||||
import { HotbarIcon } from "./hotbar-icon";
|
import { HotbarIcon } from "./hotbar-icon";
|
||||||
import { defaultHotbarCells, HotbarItem } from "../../../common/hotbar-types";
|
import { defaultHotbarCells, HotbarItem } from "../../../common/hotbar-types";
|
||||||
|
import { action, makeObservable, observable } from "mobx";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: IClassName;
|
className?: IClassName;
|
||||||
@ -40,6 +41,13 @@ interface Props {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class HotbarMenu extends React.Component<Props> {
|
export class HotbarMenu extends React.Component<Props> {
|
||||||
|
@observable draggingOver = false;
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
makeObservable(this);
|
||||||
|
}
|
||||||
|
|
||||||
get hotbar() {
|
get hotbar() {
|
||||||
return HotbarStore.getInstance().getActive();
|
return HotbarStore.getInstance().getActive();
|
||||||
}
|
}
|
||||||
@ -54,9 +62,17 @@ export class HotbarMenu extends React.Component<Props> {
|
|||||||
return catalogEntityRegistry.getById(item?.entity.uid) ?? null;
|
return catalogEntityRegistry.getById(item?.entity.uid) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
onDragStart() {
|
||||||
|
this.draggingOver = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
onDragEnd(result: DropResult) {
|
onDragEnd(result: DropResult) {
|
||||||
const { source, destination } = result;
|
const { source, destination } = result;
|
||||||
|
|
||||||
|
this.draggingOver = false;
|
||||||
|
|
||||||
if (!destination) { // Dropped outside of the list
|
if (!destination) { // Dropped outside of the list
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -165,9 +181,9 @@ export class HotbarMenu extends React.Component<Props> {
|
|||||||
const hotbar = hotbarStore.getActive();
|
const hotbar = hotbarStore.getActive();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("HotbarMenu flex column", className)}>
|
<div className={cssNames("HotbarMenu flex column", { draggingOver: this.draggingOver }, className)}>
|
||||||
<div className="HotbarItems flex column gaps">
|
<div className="HotbarItems flex column gaps">
|
||||||
<DragDropContext onDragEnd={this.onDragEnd.bind(this)}>
|
<DragDropContext onDragStart={() => this.onDragStart()} onDragEnd={(result) => this.onDragEnd(result)}>
|
||||||
{this.renderGrid()}
|
{this.renderGrid()}
|
||||||
</DragDropContext>
|
</DragDropContext>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user