mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Generating 12 cells by default
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
1cc44fcc84
commit
e37d91ff3d
@ -32,6 +32,8 @@ export interface HotbarStoreModel {
|
|||||||
activeHotbarId: string;
|
activeHotbarId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const defaultHotbarCells = 12; // Number is choosen to easy hit any item with keyboard
|
||||||
|
|
||||||
export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||||
@observable hotbars: Hotbar[] = [];
|
@observable hotbars: Hotbar[] = [];
|
||||||
@observable private _activeHotbarId: string;
|
@observable private _activeHotbarId: string;
|
||||||
@ -61,12 +63,16 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
return this.hotbars.findIndex((hotbar) => hotbar.id === this.activeHotbarId);
|
return this.hotbars.findIndex((hotbar) => hotbar.id === this.activeHotbarId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get initialItems() {
|
||||||
|
return [...Array.from(Array(defaultHotbarCells).fill(null))];
|
||||||
|
}
|
||||||
|
|
||||||
@action protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
|
@action protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
|
||||||
if (data.hotbars?.length === 0) {
|
if (data.hotbars?.length === 0) {
|
||||||
this.hotbars = [{
|
this.hotbars = [{
|
||||||
id: uuid.v4(),
|
id: uuid.v4(),
|
||||||
name: "Default",
|
name: "Default",
|
||||||
items: [],
|
items: this.initialItems,
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
this.hotbars = data.hotbars;
|
this.hotbars = data.hotbars;
|
||||||
@ -98,7 +104,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
add(data: HotbarCreateOptions) {
|
add(data: HotbarCreateOptions) {
|
||||||
const {
|
const {
|
||||||
id = uuid.v4(),
|
id = uuid.v4(),
|
||||||
items = [],
|
items = this.initialItems,
|
||||||
name,
|
name,
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
|
|||||||
@ -12,10 +12,15 @@
|
|||||||
height: 4px; // extra spacing for mac-os "traffic-light" buttons
|
height: 4px; // extra spacing for mac-os "traffic-light" buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
.AddCellButton {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.HotbarItems {
|
.HotbarItems {
|
||||||
--cellWidth: 40px;
|
--cellWidth: 40px;
|
||||||
--cellHeight: 40px;
|
--cellHeight: 40px;
|
||||||
--cellFullHeight: 60px;
|
|
||||||
|
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
@ -108,13 +113,15 @@
|
|||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
min-height: 40px;
|
min-height: 40px;
|
||||||
margin: 8px auto;
|
margin: 12px auto 8px;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
color: var(--textColorDimmed);
|
color: var(--textColorDimmed);
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
opacity: 0;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--sidebarBackground);
|
background-color: var(--sidebarBackground);
|
||||||
|
|||||||
@ -2,17 +2,16 @@ import "./hotbar-menu.scss";
|
|||||||
import "./hotbar.commands";
|
import "./hotbar.commands";
|
||||||
|
|
||||||
import React, { ReactNode } from "react";
|
import React, { ReactNode } from "react";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { HotbarIcon } from "./hotbar-icon";
|
import { HotbarIcon } from "./hotbar-icon";
|
||||||
import { cssNames, cssVar, IClassName } from "../../utils";
|
import { cssNames, IClassName } from "../../utils";
|
||||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||||
import { HotbarItem, HotbarStore } from "../../../common/hotbar-store";
|
import { defaultHotbarCells, HotbarItem, HotbarStore } from "../../../common/hotbar-store";
|
||||||
import { catalogEntityRunContext } from "../../api/catalog-entity";
|
import { catalogEntityRunContext } from "../../api/catalog-entity";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { CommandOverlay } from "../command-palette";
|
import { CommandOverlay } from "../command-palette";
|
||||||
import { HotbarSwitchCommand } from "./hotbar-switch-command";
|
import { HotbarSwitchCommand } from "./hotbar-switch-command";
|
||||||
import { action, reaction } from "mobx";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: IClassName;
|
className?: IClassName;
|
||||||
@ -20,12 +19,6 @@ interface Props {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class HotbarMenu extends React.Component<Props> {
|
export class HotbarMenu extends React.Component<Props> {
|
||||||
componentDidMount() {
|
|
||||||
disposeOnUnmount(this, [
|
|
||||||
reaction(() => this.hotbar, () => this.createInitialCells(), { fireImmediately: true })
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
get hotbar() {
|
get hotbar() {
|
||||||
return HotbarStore.getInstance().getActive();
|
return HotbarStore.getInstance().getActive();
|
||||||
}
|
}
|
||||||
@ -52,20 +45,6 @@ export class HotbarMenu extends React.Component<Props> {
|
|||||||
CommandOverlay.open(<HotbarSwitchCommand />);
|
CommandOverlay.open(<HotbarSwitchCommand />);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
createInitialCells() {
|
|
||||||
if (this.hotbar.items.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const element = document.querySelector<HTMLDivElement>(".HotbarItems");
|
|
||||||
const height = element.offsetHeight;
|
|
||||||
const cellHeight = cssVar(element).get("--cellFullHeight").toString();
|
|
||||||
const cellsFit = Math.floor(height / parseInt(cellHeight)) - 1;
|
|
||||||
|
|
||||||
this.hotbar.items = [...Array.from(Array(cellsFit).fill(null))];
|
|
||||||
}
|
|
||||||
|
|
||||||
renderGrid() {
|
renderGrid() {
|
||||||
if (!this.hotbar.items.length) return;
|
if (!this.hotbar.items.length) return;
|
||||||
|
|
||||||
@ -109,7 +88,7 @@ export class HotbarMenu extends React.Component<Props> {
|
|||||||
<div className={cssNames("HotbarMenu flex column", className)}>
|
<div className={cssNames("HotbarMenu flex column", className)}>
|
||||||
<div className="HotbarItems flex column gaps">
|
<div className="HotbarItems flex column gaps">
|
||||||
{this.renderGrid()}
|
{this.renderGrid()}
|
||||||
{this.renderAddCellButton()}
|
{this.hotbar.items.length != defaultHotbarCells && this.renderAddCellButton()}
|
||||||
</div>
|
</div>
|
||||||
<div className="HotbarSelector flex align-center">
|
<div className="HotbarSelector flex align-center">
|
||||||
<Icon material="play_arrow" className="previous box" onClick={() => this.previous()} />
|
<Icon material="play_arrow" className="previous box" onClick={() => this.previous()} />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user