Skip to content

Commit

Permalink
Patch: removed enum from declaration file
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Mar 9, 2024
1 parent 8c652db commit bd7d792
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { twMerge } from "tailwind-merge";
import { useEvents, useInteractions } from "@/hooks";
import { type ISTKProps, STKMode } from "@/types";
import { type ISTKProps } from "@/types";
import { default as Controls } from "./controls";
import { default as Footer } from "./footer";
import { default as Operations } from "./operations";
Expand Down Expand Up @@ -46,7 +46,7 @@ const User: React.FC<ISTKProps> = (props) => {
};

const Core = (props: ISTKProps) => {
if (props.mode === STKMode.Designer) {
if (props.mode === "designer") {
return <Designer {...props} />;
}
return <User {...props} />;
Expand Down
19 changes: 16 additions & 3 deletions src/components/workspace/elements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { twMerge } from "tailwind-merge";
import { dataAttributes } from "@/constants";
import { store } from "@/store";
import { clearAndSelectElements, deselectElement, selectElement } from "@/store/reducers/editor";
import { ISTKProps, STKMode } from "@/types";
import { ISTKProps } from "@/types";
import { Tool } from "../../toolbar/data";
import {
ElementType,
Expand All @@ -19,15 +19,28 @@ import {

export * from "./utils";

export const Element = ({ type = ElementType.Seat, id, x = 250, y = 250, isSelected = false, consumer, ...props }) => {
interface IElementProps {
[prop: string]: any;
consumer: ISTKProps;
}

export const Element: React.FC<IElementProps> = ({
type = ElementType.Seat,
id,
x = 250,
y = 250,
isSelected = false,
consumer,
...props
}) => {
const ref = useRef<HTMLElement>();

const Element = elements[type] as any;

const styles = (consumer as ISTKProps).styles?.elements;

useEffect(() => {
if (!ref.current || consumer.mode !== STKMode.Designer) return;
if (!ref.current || consumer.mode !== "designer") return;
const node = d3.select(ref.current);
if (type === ElementType.Seat) {
handleSeatDrag(node);
Expand Down
4 changes: 2 additions & 2 deletions src/components/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { twMerge } from "tailwind-merge";
import { ids } from "@/constants";
import { store } from "@/store";
import { initializeElements, sync } from "@/store/reducers/editor";
import { type ISTKProps, STKMode } from "@/types";
import { type ISTKProps } from "@/types";
import { Tool, tools } from "../toolbar/data";
import { default as Crosshairs } from "./crosshairs";
import { default as Element, ElementType } from "./elements";
Expand Down Expand Up @@ -123,7 +123,7 @@ export const Workspace: React.FC<ISTKProps> = (props) => {
{selectedPolylineId && <line id={ids.templine} className="stroke-2 stroke-black fill-white" />}
</g>
</svg>
{props.mode === STKMode.Designer && (
{props.mode === "designer" && (
<>
<Crosshairs render={tools[selectedTool]?.crosshairs} />
<Grid />
Expand Down
3 changes: 1 addition & 2 deletions src/stories/designer.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SeatToolkit from "@/index";
import { STKMode } from "@/types";

export default {
title: "Designer Mode",
Expand All @@ -11,5 +10,5 @@ export default {
};

export const Default = {
render: () => <SeatToolkit mode={STKMode.Designer} />
render: () => <SeatToolkit mode={"designer"} />
};
3 changes: 1 addition & 2 deletions src/stories/user.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SeatToolkit from "@/index";
import { STKMode } from "@/types";

export default {
title: "User Mode",
Expand All @@ -13,7 +12,7 @@ export default {
export const Default = {
render: () => (
<SeatToolkit
mode={STKMode.User}
mode={"user"}
data={{
seats: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/types/elements/seat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ISection } from "./polyline";
import type { ISection } from "./polyline";

export interface ISeatCategory {
id: string;
Expand Down
19 changes: 13 additions & 6 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { IBooth, IImage, IPolyline, IPopulatedSeat, ISeat, ISeatCategory, ISection, IShape, IText } from "./elements";
import { IStyles } from "./styles";
import type {
IBooth,
IImage,
IPolyline,
IPopulatedSeat,
ISeat,
ISeatCategory,
ISection,
IShape,
IText
} from "./elements";
import type { IStyles } from "./styles";

export * from "./elements";

export enum STKMode {
Designer = "designer",
User = "user"
}
export type STKMode = "designer" | "user";

export interface IEvents {
onSeatClick?: (seat: IPopulatedSeat) => void;
Expand Down

0 comments on commit bd7d792

Please sign in to comment.