Skip to content

Commit

Permalink
fix build issues with types
Browse files Browse the repository at this point in the history
  • Loading branch information
BrookJeynes committed Aug 20, 2024
1 parent 1355265 commit ee59614
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/components/UserPins.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";

import { pins } from "../data/pins";
import { LocalStoragePin, Pin } from "../types";
import { LocalStoragePin, Pin, PinTitle } from "../types";
import { FaQuestionCircle } from "react-icons/fa";

import { useMapEvents } from "react-leaflet";
Expand All @@ -13,9 +13,9 @@ export function SidebarPins({
selected_pin: Pin | undefined,
setSelectedPin: React.Dispatch<React.SetStateAction<Pin | undefined>>
}) {
const [selected_type, setSelectedType] = useState("Food");
const [selected_type, setSelectedType] = useState<PinTitle>("Food");

const types = [
const types: PinTitle[] = [
"Food",
"Plorts",
"Utility",
Expand All @@ -32,7 +32,7 @@ export function SidebarPins({
</div>
<select
value={selected_type}
onChange={event => setSelectedType(event.target.value)}
onChange={event => setSelectedType(event.target.value as PinTitle)}
className="bg-transparent outline outline-1 p-1"
>
{types.map((type: string) => <option key={type} value={type}>{type}</option>)}
Expand Down Expand Up @@ -60,7 +60,7 @@ export function SidebarPins({

<div className="flex flex-wrap gap-2">
{
pins[selected_type].map((key: Pin) =>
pins[selected_type as PinTitle].map((key: Pin) =>
<PinIcon
key={key.name}
pin={key}
Expand Down
24 changes: 12 additions & 12 deletions src/components/planner/Planner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Planner({
plotPlan,
setPlotPlan,
}: {
plotType: PlotOptions;
plotType?: PlotOptions;
icons: PlannerIcons;
setIcons: React.Dispatch<React.SetStateAction<PlannerIcons>>;
plotPlan: LocalStoragePlotPlan;
Expand All @@ -38,10 +38,10 @@ export default function Planner({
}
: icons.right === null
? {
name: plotType.name,
name: plotType?.name ?? "",
icon: L.icon({
...icon_template,
iconUrl: plotType.icon,
iconUrl: plotType?.icon ?? "",
}),
}
: null,
Expand All @@ -56,10 +56,10 @@ export default function Planner({
? null
: icons.left
: {
name: plotType.name,
name: plotType?.name ?? "",
icon: L.icon({
...icon_template,
iconUrl: plotType.icon,
iconUrl: plotType?.icon ?? "",
}),
},
right:
Expand Down Expand Up @@ -91,8 +91,8 @@ export default function Planner({
checked={plotPlan.selectedOptionA === 0}
onChange={(e) =>
e.target.checked
? onChange(0, Side.left, plotType.optionsA)
: onChange(-1, Side.left, plotType.optionsA)
? onChange(0, Side.left, plotType?.optionsA ?? [])
: onChange(-1, Side.left, plotType?.optionsA ?? [])
}
name={plotType.optionsA[0].name}
/>
Expand All @@ -103,7 +103,7 @@ export default function Planner({
<div className="flex flex-col gap-1">
<h2 className="ml-2 text-lg">{plotType.optionsAName}</h2>
<select
onChange={(e) => onChange(e.target.value, Side.left, plotType.optionsA)}
onChange={(e) => onChange(parseInt(e.target.value, 10), Side.left, plotType?.optionsA ?? [])}
className="bg-transparent outline outline-1 p-1"
value={plotPlan.selectedOptionA ? plotPlan.selectedOptionA : "Empty"}
>
Expand All @@ -130,8 +130,8 @@ export default function Planner({
checked={plotPlan.selectedOptionB === 0}
onChange={(e) =>
e.target.checked
? onChange(0, Side.right, plotType.optionsB)
: onChange(-1, Side.right, plotType.optionsB)
? onChange(0, Side.right, plotType?.optionsB ?? [])
: onChange(-1, Side.right, plotType?.optionsB ?? [])
}
name={plotType.optionsB[0].name}
/>
Expand All @@ -142,7 +142,7 @@ export default function Planner({
<div className="flex flex-col gap-1">
<h2 className="ml-2 text-lg">{plotType.optionsBName}</h2>
<select
onChange={(e) => onChange(e.target.value, Side.right, plotType.optionsB)}
onChange={(e) => onChange(parseInt(e.target.value, 10), Side.right, plotType?.optionsB ?? [])}
className="bg-transparent outline outline-1 p-1"
value={plotPlan.selectedOptionB ? plotPlan.selectedOptionB : "Empty"}
>
Expand All @@ -160,7 +160,7 @@ export default function Planner({
)}
</div>) : (<></>)}

{plotType?.upgrades.length > 0 ? (
{plotType && plotType?.upgrades.length > 0 ? (
<div className="flex flex-col gap-1">
<h2 className="ml-2 text-lg">Upgrades</h2>
{plotType.upgrades.map((additionalOption, index) => (
Expand Down
17 changes: 9 additions & 8 deletions src/components/planner/PlotPlanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function PlotPlanner({
};

const [plotPlan, setPlotPlan] = useState<LocalStoragePlotPlan>(retrievedPlotPlan);
const [plotType, setplotType] = useState<PlotOptions>(getSelectedPlotTypeFromRetrievedPlotPlan);
const [plotType, setplotType] = useState<PlotOptions | undefined>(getSelectedPlotTypeFromRetrievedPlotPlan);
const [icons, setIcons] = useState<PlannerIcons>(getIconsFromRetrievedPlan);

const doubleIconYOffset = 0.35;
Expand Down Expand Up @@ -147,30 +147,31 @@ export function PlotPlanner({
value={
plotPlan !== null && plotPlan.selectedPlotType !== undefined
? plotPlan.selectedPlotType
: "Empty"
: -1
}
onChange={(e) => {
const plot_index = parseInt(e.target.value, 10);
setIcons({
left:
e.target.value !== "Empty"
plot_index !== -1
? {
name: plotTypes[e.target.value].name,
name: (plotTypes[plot_index] as PlotOptions).name,
icon: L.icon({
...icon_template,
iconUrl: plotTypes[e.target.value].icon,
iconUrl: plotTypes[plot_index].icon,
}),
}
: null,
right: null,
});
setplotType(plotTypes[e.target.value]);
setplotType(plotTypes[plot_index]);
handlePlotPlanChange({
selectedPlotType: e.target.value !== "Empty" ? Number(e.target.value) : "Empty",
selectedPlotType: plot_index !== -1 ? plot_index : undefined,
selectedUpgrades: [],
});
}}
>
<option>Empty</option>
<option value={-1}>Empty</option>
{plotTypes.map((plotType, index) => (
<option key={index} value={index}>
{plotType.name}
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface PlotOptions extends Pin {
upgrades: string[]
}

export type PinTitle = "Food" | "Utility" | "Plorts" | "Slimes" | "Gordos" | "Resources";
export interface Pins {
Food: Pin[],
Utility: Pin[],
Expand All @@ -82,7 +83,7 @@ export interface LocalStoragePin {
}

export interface LocalStoragePlotPlan {
selectedPlotType?: number,
selectedPlotType?: number
selectedOptionA?: number,
selectedOptionB?: number,
selectedUpgrades: number[]
Expand Down

0 comments on commit ee59614

Please sign in to comment.