Skip to content

Commit 94d9cce

Browse files
Fix an issue with choosing a ship spawn template from the starmap core.
1 parent 09061a1 commit 94d9cce

4 files changed

Lines changed: 24 additions & 37 deletions

File tree

app/components/ui/SearchableInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default function SearchableInput<T extends { id: any }>({
5353
placeholder,
5454
inputClassName,
5555
className,
56+
label = "Search",
5657
}: {
5758
queryKey?: string;
5859
displayValue?: (item: T) => string;
@@ -71,6 +72,7 @@ export default function SearchableInput<T extends { id: any }>({
7172
placeholder?: string;
7273
inputClassName?: string;
7374
className?: string;
75+
label?: string;
7476
}) {
7577
const list = useAsyncList<T>({
7678
async load({ signal, cursor, filterText = "" }) {
@@ -101,6 +103,7 @@ export default function SearchableInput<T extends { id: any }>({
101103
}}
102104
menuTrigger="focus"
103105
className={className}
106+
aria-label={label}
104107
>
105108
<div className="relative mt-1">
106109
<div className="relative w-full cursor-default overflow-hidden rounded-lg text-left focus:outline-none sm:text-sm">

app/cores/StarmapCore/StarmapCoreContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const StarmapCoreContextMenu = ({
221221
if (!position) return;
222222

223223
await q.ship.spawn.netSend({
224-
template: { name: template.id, pluginId: template.pluginName },
224+
template: { name: template.name, pluginId: template.pluginName },
225225
position: {
226226
x: position.x,
227227
y: useStarmapStore.getState().yDimensionIndex,

app/cores/StarmapCore/data.server.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export const starmapCore = t.router({
346346
})
347347
.slice(0, 10)
348348
.map(({ pluginName, name, category, assets: { vanity } }) => ({
349-
id: name,
349+
id: `${name}-${pluginName}`,
350350
pluginName,
351351
name,
352352
category,

app/cores/StarmapCore/index.tsx

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { ErrorBoundary } from "react-error-boundary";
5757
import { type PerspectiveCamera, Plane, Vector3 } from "three";
5858
import { FiringPhasers } from "./FiringPhasers";
5959
import { StarmapCoreContextMenu } from "./StarmapCoreContextMenu";
60+
import Select from "@thorium/ui/Select";
6061

6162
export class SelectStarmapEntityEvent extends Event {
6263
static name = "select-starmap-entity";
@@ -678,7 +679,9 @@ function ShipControls() {
678679
function StarmapCoreMenubar() {
679680
const useStarmapStore = useGetStarmapStore();
680681
const [playerShips] = q.ship.players.useNetRequest();
681-
682+
const [shipTemplates] = q.starmapCore.spawnSearch.useNetRequest({
683+
query: "",
684+
});
682685
const playerShip = playerShips[0];
683686
useEffect(() => {
684687
useStarmapStore.setState({
@@ -707,41 +710,22 @@ function StarmapCoreMenubar() {
707710
<Icon name="arrow-left" />
708711
</Button>
709712
)}
710-
<SearchableInput<{
711-
id: string;
712-
pluginName: string;
713-
name: string;
714-
category: string;
715-
vanity: string;
716-
}>
717-
inputClassName="input-xs"
718-
queryKey="spawn"
719-
getOptions={async ({ queryKey, signal }) => {
720-
const result = await q.starmapCore.spawnSearch.netRequest(
721-
{ query: queryKey[1] },
722-
{ signal },
723-
);
724-
return result;
725-
}}
726-
ResultLabel={({ active, result, selected }) => (
727-
<DefaultResultLabel active={active} selected={selected}>
728-
<div className="flex gap-4">
729-
<img src={result.vanity} alt="" className="w-8 h-8" />
730-
<div>
731-
<p className="m-0 leading-none">{result.name}</p>
732-
<p className="m-0 leading-none">
733-
<small>{result.category}</small>
734-
</p>
735-
</div>
736-
</div>
737-
</DefaultResultLabel>
738-
)}
739-
setSelected={(item) =>
740-
useStarmapStore.setState({ spawnShipTemplate: item })
741-
}
742-
selected={selectedSpawn}
713+
<Select
714+
label="Ship Template"
715+
labelHidden
716+
size="xs"
743717
placeholder="Ship Spawn Search..."
744-
/>
718+
buttonClassName="whitespace-nowrap"
719+
items={shipTemplates.map((s) => ({ id: s.id, label: s.name }))}
720+
selected={selectedSpawn?.id || null}
721+
setSelected={(value) =>
722+
useStarmapStore.setState({
723+
spawnShipTemplate:
724+
shipTemplates.find((s) => s.id === value) || null,
725+
})
726+
}
727+
></Select>
728+
745729
<Button
746730
title="Follow selected entity"
747731
disabled={selectedObjectIds.length === 0}

0 commit comments

Comments
 (0)