Skip to content

Commit dc543c8

Browse files
committed
add board search form, some optimizations
1 parent bb1f3a1 commit dc543c8

File tree

10 files changed

+364
-4
lines changed

10 files changed

+364
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@hey-api/client-fetch": "^0.10.0",
17+
"@tanstack/react-form": "^1.6.3",
1718
"@tanstack/react-query": "^5.74.4",
1819
"@tanstack/react-router": "^1.117.0",
1920
"@tanstack/zod-adapter": "^1.117.0",

pnpm-lock.yaml

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/form/Button.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cn } from "@/lib/utils.ts";
2+
import { type ComponentProps, type FC, forwardRef } from "react";
3+
4+
export const Button: FC<ComponentProps<"button">> = forwardRef(({ children, className = "", ...props }, ref) => (
5+
<button
6+
ref={ref}
7+
className={cn(
8+
"inline-block bg-blue-500 text-white font-medium rounded-lg px-4 py-2 hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-400 transition",
9+
className,
10+
)}
11+
{...props}
12+
>
13+
{children}
14+
</button>
15+
));

src/components/form/RangeInput.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { cn } from "@/lib/utils.ts";
2+
import { type ComponentProps, type FC, forwardRef } from "react";
3+
4+
export const RangeInput: FC<Omit<ComponentProps<"input">, "type">> = forwardRef(
5+
({ className, value, ...props }, ref) => (
6+
<div className="flex items-center w-full space-x-4">
7+
<input
8+
ref={ref}
9+
type="range"
10+
className={cn(
11+
"w-full h-2 bg-gray-200 rounded-lg accent-blue-400 appearance-none focus:outline-none focus:ring-2 focus:ring-blue-400 transition",
12+
className,
13+
)}
14+
value={value}
15+
{...props}
16+
/>
17+
<span className="w-12 text-right text-gray-700">{value}</span>
18+
</div>
19+
),
20+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { cn } from "@/lib/utils.ts";
2+
import { type ComponentProps, type FC, type PropsWithChildren, forwardRef } from "react";
3+
4+
export const SelectInput: FC<PropsWithChildren<ComponentProps<"select">>> = forwardRef(
5+
({ children, className = "", ...props }, ref) => {
6+
return (
7+
<div className="relative w-full">
8+
<select
9+
ref={ref}
10+
className={cn(
11+
"block w-full appearance-none bg-white border border-gray-300 rounded-lg px-4 py-2 pr-8 text-gray-800 leading-tight focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent hover:border-gray-400 transition",
12+
className,
13+
)}
14+
{...props}
15+
>
16+
{children}
17+
</select>
18+
19+
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2">
20+
<svg
21+
className="h-4 w-4 text-gray-500"
22+
xmlns="http://www.w3.org/2000/svg"
23+
viewBox="0 0 20 20"
24+
fill="currentColor"
25+
>
26+
<title>Dropdown Arrow</title>
27+
<path
28+
fillRule="evenodd"
29+
clipRule="evenodd"
30+
d="M5.23 7.21a.75.75 0 011.06-.02L10 10.674l3.71-3.486a.75.75 0 111.04 1.084l-4.24 3.99a.75.75 0 01-1.04 0l-4.24-3.99a.75.75 0 01-.02-1.06z"
31+
/>
32+
</svg>
33+
</div>
34+
</div>
35+
);
36+
},
37+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { cn } from "@/lib/utils.ts";
2+
import { type ComponentProps, type FC, forwardRef } from "react";
3+
4+
export const ToggleInput: FC<Omit<ComponentProps<"input">, "type">> = forwardRef(
5+
({ className = "", ...props }, ref) => (
6+
<label className={cn("relative inline-flex items-center cursor-pointer", className)}>
7+
<input type="checkbox" className="sr-only peer" {...props} ref={ref} />
8+
<div className="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-blue-400 rounded-full peer-checked:bg-blue-500 transition-all" />
9+
<div className="absolute left-1 top-1 bg-white w-4 h-4 rounded-full peer-checked:translate-x-5 transition-transform" />
10+
</label>
11+
),
12+
);

src/routes/boards/-components/BoardDestinationInfo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const findDestination = (via: Array<BoardViaEventDto>): [string | null, "schedul
4141
}
4242

4343
if (firstCancelledViaIndex === 0) {
44-
// the first event is canceled, train ends at the current point
45-
return [null, "canceled"];
44+
// the first event is canceled, actual train destination is unknown
45+
return [destination.pointName, "canceled"];
4646
}
4747

4848
// train ends at the first non-canceled via point

src/routes/boards/-components/BoardEntryTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type BoardEntryDto, listBoardDepartures, type PointInfoDto, type SimRailServerDto } from "@/api/generated";
1+
import { type BoardEntryDto, type PointInfoDto, type SimRailServerDto, listBoardDepartures } from "@/api/generated";
22
import { Throbber } from "@/components/Throbber.tsx";
33
import { BoardEntry } from "@/routes/boards/-components/BoardEntry.tsx";
44
import { BoardTableHeading } from "@/routes/boards/-components/BoardTableHeading.tsx";
@@ -101,7 +101,7 @@ const getBoardFetchTimeRange = (server: SimRailServerDto, timeSpan: number): [st
101101
const sdt = cdt.setZone(serverTz);
102102
const dt = sdt.isValid ? sdt : cdt;
103103

104-
const timeStart = dt.minus(3 * 60 * 1000); // current time - 3 minutes
104+
const timeStart = dt.minus(5 * 60 * 1000); // current time - 5 minutes
105105
const timeEnd = dt.plus(timeSpan * 60 * 1000); // current time + timeSpan minutes
106106
return [timeStart.toISO(), timeEnd.toISO()];
107107
};

0 commit comments

Comments
 (0)