Skip to content

Commit

Permalink
add table icons
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Apr 2, 2024
1 parent 9273e15 commit cac50f3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions web/src/components/pages/admin/DrugTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { shortString } from "starknet";
import { editComponents } from "./tables";

const columns = [
{ key: "icon", width: 80 },
{ key: "drug", title: "drug", dataType: DataType.String },
{ key: "drug_id", title: "drug_id", dataType: DataType.Number },
{ key: "name", title: "name", dataType: DataType.String },
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/pages/admin/HustlerItemBaseTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { useDojoContext } from "@/dojo/hooks";
import { observer } from "mobx-react-lite";

import { Table } from "ka-table";
import { DataType, EditingMode, SortingMode } from "ka-table/enums";
import { DataType, EditingMode } from "ka-table/enums";
import { editComponents } from "./tables";

const columns = [
{ key: "icon", width: 80 },
{ key: "slot", title: "slot", dataType: DataType.String },
{ key: "id", title: "id", dataType: DataType.Number },
{ key: "slot_id", title: "slot_id", dataType: DataType.Number },
Expand All @@ -24,7 +26,7 @@ export const HustlerItemBaseTable = observer(() => {
data={config?.items || []}
rowKeyField={"id"}
editingMode={EditingMode.None}
sortingMode={SortingMode.Single}
childComponents={editComponents}
/>
);
});
Expand Down
18 changes: 18 additions & 0 deletions web/src/components/pages/admin/tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export const editComponents = {
</ChildrenOrConnect>
);
}
if (props.column.key === "icon") {
return <>{props.rowData.icon && props.rowData.icon({ width: "36px", height: "36px" })}</>;
}
},
},
cellEditor: {
Expand All @@ -54,6 +57,21 @@ export const editComponents = {
</ChildrenOrConnect>
);
}
if (props.column.key === "icon") {
return <>{props.rowData.icon && props.rowData.icon({ width: "36px", height: "36px" })}</>;
}
},
},
};


export const iconComponents = {
cellText: {
content: (props: any) => {
if (props.column.key === "icon") {
return props.rowData.icon()
// return <>{props.rowData.icon && props.rowData.icon({ width: "36px", height: "36px" })}</>;
}
},
},
};
9 changes: 7 additions & 2 deletions web/src/dojo/stores/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export type HustlerItemConfigFull = HustlerItemConfig & {
upgradeName: string;
};

export type HustlerItemBaseConfigFull = HustlerItemBaseConfig & {
icon: React.FC;
};

export type HustlerConfig = {
hustler_id: number;
weapon: HustlerItemConfig;
Expand All @@ -75,7 +79,7 @@ export type Config = {
ryoAddress: RyoAddress;
drug: DrugConfigFull[];
location: LocationConfigFull[];
items: HustlerItemBaseConfig[];
items: HustlerItemBaseConfigFull[];
tiers: HustlerItemTiersConfig[];
config: GetConfig;
};
Expand Down Expand Up @@ -147,7 +151,8 @@ export class ConfigStoreClass {
return {
...i.node,
name: shortString.decodeShortString(i.node?.name),
} as HustlerItemBaseConfig;
icon: itemIcons[shortString.decodeShortString(i.node?.name) as itemsIconsKeys]
} as HustlerItemBaseConfigFull;
});

//
Expand Down

0 comments on commit cac50f3

Please sign in to comment.