Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {IconDefinition} from "@fortawesome/free-solid-svg-icons";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import { IconDefinition } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

export function IconButton({
icon,
Expand Down
33 changes: 16 additions & 17 deletions frontend/src/components/Welcome.test.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import { render, screen } from "@testing-library/react"
import { describe, expect,it } from "vitest"
import { vi } from "vitest"

import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { vi } from "vitest";

vi.mock("../../wailsjs/go/dispatcher/Service", () => ({
Dispatch: vi.fn().mockResolvedValue(undefined)
Dispatch: vi.fn().mockResolvedValue(undefined),
}));

import userEvent from "@testing-library/user-event"
import userEvent from "@testing-library/user-event";

import {Dispatch} from "../../wailsjs/go/dispatcher/Service";
import {Command} from "../App";
import Welcome from "./Welcome"
import { Dispatch } from "../../wailsjs/go/dispatcher/Service";
import { Command } from "../App";
import Welcome from "./Welcome";

describe("Welcome", () => {
it("renders the Create New Split File button", async () => {
render(<Welcome />)
render(<Welcome />);

const button = screen.getByRole("button", {
name: /create new split file/i
})
name: /create new split file/i,
});

expect(button).toBeInTheDocument()
await userEvent.click(button)
expect(Dispatch).toHaveBeenCalledExactlyOnceWith(Command.NEW, null)
})
})
expect(button).toBeInTheDocument();
await userEvent.click(button);
expect(Dispatch).toHaveBeenCalledExactlyOnceWith(Command.NEW, null);
});
});
10 changes: 0 additions & 10 deletions frontend/src/components/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ export default function Welcome() {
Exit OpenSplit
</button>

<button
style={{ marginTop: 30 }}
onClick={async () => {
localStorage.clear();
await Dispatch(Command.RESET, null);
}}
>
<small>Reset All Preferences</small>
</button>

<div id="cw">
<p>Copyright ZellyDev LLC - ZellyDev Games {new Date().getFullYear()}</p>
</div>
Expand Down
24 changes: 7 additions & 17 deletions frontend/src/components/editor/SplitEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { WindowCenter, WindowSetSize } from "../../../wailsjs/runtime";
import { Command } from "../../App";
import SegmentPayload from "../../models/segmentPayload";
import SplitFilePayload from "../../models/splitFilePayload";
import {TimeRow} from "./TimeRow";
import {colorFromId, GroupCtx} from "./hashColor";
import {IconButton} from "../Tooltip";
import { IconButton } from "../Tooltip";
import { colorFromId, GroupCtx } from "./hashColor";
import { TimeRow } from "./TimeRow";

type SplitEditorParams = {
splitFilePayload: SplitFilePayload | null;
Expand Down Expand Up @@ -290,7 +290,7 @@ export default function SplitEditor({ splitFilePayload }: SplitEditorParams) {
const nextInheritedGroup = ownGroup ?? null;
const nextIsDirectChild = !!ownGroup;

const frag = (
const frag = (
<React.Fragment key={segment.id}>
<tr className={rowClassName} style={rowStyle}>
<td>
Expand Down Expand Up @@ -328,20 +328,10 @@ export default function SplitEditor({ splitFilePayload }: SplitEditorParams) {
</td>

<td>
{!hasChildren && (
<TimeRow
time={segment.average ? segment.average + totalAvg : null}
/>
)}
{!hasChildren && <TimeRow time={segment.average ? segment.average + totalAvg : null} />}
</td>

<td>
{!hasChildren && (
<TimeRow
time={segment.pb ? segment.pb + totalBest : null}
/>
)}
</td>
<td>{!hasChildren && <TimeRow time={segment.pb ? segment.pb + totalBest : null} />}</td>

<td>
<IconButton icon={faFolder} tooltip="Add subsegment" onClick={() => addSegment(segment)} />
Expand All @@ -362,7 +352,7 @@ export default function SplitEditor({ splitFilePayload }: SplitEditorParams) {
);

if (!hasChildren) {
totalAvg += segment.average
totalAvg += segment.average;
totalBest += segment.pb;
}
return frag;
Expand Down
28 changes: 12 additions & 16 deletions frontend/src/components/editor/TimeRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {msToParts, numeric, partsToMS, TimeParts} from "../splitter/Timer";
import {forwardRef, RefObject, useImperativeHandle, useRef} from "react";
import { forwardRef, RefObject, useImperativeHandle, useRef } from "react";

import { msToParts, partsToMS } from "../splitter/Timer";

type timeRowParams = {
time: number | null;
Expand All @@ -9,12 +10,11 @@ type Handle = {
getMillis(): number;
};

export const TimeRow = forwardRef<Handle, timeRowParams>(
(props, ref) => {
const hourRef: RefObject<HTMLInputElement | null> = useRef(null)
const minuteRef: RefObject<HTMLInputElement | null> = useRef(null)
const secondRef: RefObject<HTMLInputElement | null> = useRef(null)
const centiRef: RefObject<HTMLInputElement | null> = useRef(null)
export const TimeRow = forwardRef<Handle, timeRowParams>((props, ref) => {
const hourRef: RefObject<HTMLInputElement | null> = useRef(null);
const minuteRef: RefObject<HTMLInputElement | null> = useRef(null);
const secondRef: RefObject<HTMLInputElement | null> = useRef(null);
const centiRef: RefObject<HTMLInputElement | null> = useRef(null);

useImperativeHandle(ref, () => ({
getMillis: () => {
Expand All @@ -24,17 +24,13 @@ export const TimeRow = forwardRef<Handle, timeRowParams>(
minutes: parseInt(minuteRef.current?.value ?? "0", 10),
seconds: parseInt(secondRef.current?.value ?? "0", 10),
centis: parseInt(centiRef.current?.value ?? "0", 10),
})
}
}))
});
},
}));

return (
<div className="segment-time">
<input
ref={hourRef}
placeholder="H"
defaultValue={props.time != null ? msToParts(props.time).hours : ""}
/>
<input ref={hourRef} placeholder="H" defaultValue={props.time != null ? msToParts(props.time).hours : ""} />
<span>:</span>
<input
ref={minuteRef}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/splitter/SegmentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export default function SegmentList({ sessionPayload, comparison }: SplitListPar
) : null;

const lastLeafId = lastLeafByParentId.get(segmentData.Segment.id) ?? null;
const lastLeafSplit = lastLeafId ? sessionPayload.current_run?.splits[lastLeafId] ?? null : null;
const lastLeafSplit = lastLeafId ? (sessionPayload.current_run?.splits[lastLeafId] ?? null) : null;

// Comparison time (cumulative display) pulled from last leaf
let parentComparison: JSX.Element | null = null;
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/test/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "@testing-library/jest-dom"
import "@testing-library/jest-dom";

import { vi } from "vitest"
import { vi } from "vitest";

vi.mock("../../wailsjs/runtime/runtime", () => ({
EventsOn: vi.fn(),
EventsOff: vi.fn(),
EventsEmit: vi.fn(),
WindowSetTitle: vi.fn(),
WindowSetSize: vi.fn(),
}))
}));
4 changes: 2 additions & 2 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default defineConfig({
test: {
environment: "jsdom",
setupFiles: "./src/test/setupTests.ts",
globals: true
}
globals: true,
},
});