Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
デザインを調整
Browse files Browse the repository at this point in the history
  • Loading branch information
n4o847 committed Oct 7, 2023
1 parent 8ad846c commit 88177f1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
8 changes: 7 additions & 1 deletion ptcs/ptcs_ui/src/components/Railway.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import { Train } from "./Train";
import { Junction } from "./Junction";
import { useContext } from "react";
import { Stop } from "./Stop";
import { useMantineTheme } from "@mantine/core";

export const Railway: React.FC<React.PropsWithChildren> = ({ children }) => {
const theme = useMantineTheme();
const railwayUI = useContext(RailwayUIContext);

if (!railwayUI) return null;

return (
<svg width="100%" viewBox={`0 0 ${railwayUI.width} ${railwayUI.height}`}>
<rect width={railwayUI.width} height={railwayUI.height} fill="#222222" />
<rect
width={railwayUI.width}
height={railwayUI.height}
fill={theme.colors.dark[7]}
/>
{Object.entries(railwayUI.platforms).map(([id, platform]) => (
<Platform key={id} position={platform.position} />
))}
Expand Down
6 changes: 5 additions & 1 deletion ptcs/ptcs_ui/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const router = createHashRouter([

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<MantineProvider withGlobalStyles withNormalizeCSS>
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{ colorScheme: "dark" }}
>
<RouterProvider router={router} />
</MantineProvider>
</React.StrictMode>
Expand Down
36 changes: 24 additions & 12 deletions ptcs/ptcs_ui/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Code, Container, DEFAULT_THEME, Grid, Stack } from "@mantine/core";
import {
Code,
Container,
DEFAULT_THEME,
Stack,
useMantineTheme,
} from "@mantine/core";
import { DefaultService, RailwayState } from "ptcs_client";
import { Layout } from "../components/Layout";
import { useEffect, useState } from "react";
Expand Down Expand Up @@ -103,19 +109,21 @@ const ui: RailwayUI = {
};

export const Home: React.FC = () => {
const theme = useMantineTheme();
const [railwayState, setRailwayState] = useState<RailwayState | null>(null);
const [time, setTime] = useState<Date>();
const [time, setTime] = useState(() => new Date());

useEffect(() => {
DefaultService.getState().then((state) => {
setTime(new Date());
setRailwayState(state);
});
}, []);

useEffect(() => {
const interval = setInterval(() => {
setTime(new Date());
DefaultService.getState().then((state) => {
setTime(new Date());
setRailwayState(state);
});
}, 500);
Expand All @@ -129,16 +137,20 @@ export const Home: React.FC = () => {
<RailwayUIContext.Provider value={ui}>
<Layout>
<Container>
<Stack>
{time?.toLocaleString()}
<Railway />
<Stack px={60}>
<Railway>
<text
x={10}
y={20}
fontSize={12}
fontFamily={theme.fontFamilyMonospace}
fill={theme.white}
>
{time.toLocaleString()}
</text>
</Railway>
<Debugger />
<Grid>
<Grid.Col span={6}>
<Code block>{JSON.stringify(railwayState, null, 4)}</Code>
</Grid.Col>
<Grid.Col span={6}></Grid.Col>
</Grid>
<Code block>{JSON.stringify(railwayState, null, 4)}</Code>
</Stack>
</Container>
</Layout>
Expand Down

0 comments on commit 88177f1

Please sign in to comment.