mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix initial hotbar not showing (#2551)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
8dde4a1ecb
commit
8d42d40433
20
src/common/__tests__/hotbar-store.test.ts
Normal file
20
src/common/__tests__/hotbar-store.test.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import mockFs from "mock-fs";
|
||||||
|
import { HotbarStore, hotbarStore } from "../hotbar-store";
|
||||||
|
|
||||||
|
describe("HotbarStore", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
HotbarStore.resetInstance();
|
||||||
|
mockFs({ tmp: { "lens-hotbar-store.json": "{}" } });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
mockFs.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("load", () => {
|
||||||
|
it("loads one hotbar by default", () => {
|
||||||
|
hotbarStore.load();
|
||||||
|
expect(hotbarStore.hotbars.length).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -35,10 +35,14 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
|
@action protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
|
||||||
this.hotbars = data.hotbars || [{
|
if (data.hotbars?.length === 0) {
|
||||||
name: "default",
|
this.hotbars = [{
|
||||||
items: []
|
name: "default",
|
||||||
}];
|
items: []
|
||||||
|
}];
|
||||||
|
} else {
|
||||||
|
this.hotbars = data.hotbars;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getByName(name: string) {
|
getByName(name: string) {
|
||||||
|
|||||||
@ -14,20 +14,24 @@ interface Props {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class HotbarMenu extends React.Component<Props> {
|
export class HotbarMenu extends React.Component<Props> {
|
||||||
render() {
|
|
||||||
const { className } = this.props;
|
get hotbarItems() {
|
||||||
const hotbar = hotbarStore.getByName("default"); // FIXME
|
const hotbar = hotbarStore.getByName("default"); // FIXME
|
||||||
|
|
||||||
if (!hotbar) {
|
if (!hotbar) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = hotbar.items.map((item) => catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item.entity.uid)).filter(Boolean);
|
return hotbar.items.map((item) => catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item.entity.uid)).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { className } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("HotbarMenu flex column", className)}>
|
<div className={cssNames("HotbarMenu flex column", className)}>
|
||||||
<div className="items flex column gaps">
|
<div className="items flex column gaps">
|
||||||
{items.map((entity, index) => {
|
{this.hotbarItems.map((entity, index) => {
|
||||||
return (
|
return (
|
||||||
<HotbarIcon
|
<HotbarIcon
|
||||||
key={index}
|
key={index}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user