Skip to content

Commit

Permalink
TypeScript style pass
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Jun 19, 2023
1 parent 879ba84 commit 716b8cc
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 103 deletions.
6 changes: 3 additions & 3 deletions viser/client/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files": {
"main.css": "/static/css/main.82973013.css",
"main.js": "/static/js/main.fbdbcf0c.js",
"main.js": "/static/js/main.f2a05ab1.js",
"index.html": "/index.html",
"main.82973013.css.map": "/static/css/main.82973013.css.map",
"main.fbdbcf0c.js.map": "/static/js/main.fbdbcf0c.js.map"
"main.f2a05ab1.js.map": "/static/js/main.f2a05ab1.js.map"
},
"entrypoints": [
"static/css/main.82973013.css",
"static/js/main.fbdbcf0c.js"
"static/js/main.f2a05ab1.js"
]
}
2 changes: 1 addition & 1 deletion viser/client/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Viser</title><script defer="defer" src="/static/js/main.fbdbcf0c.js"></script><link href="/static/css/main.82973013.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Viser</title><script defer="defer" src="/static/js/main.f2a05ab1.js"></script><link href="/static/css/main.82973013.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
3 changes: 3 additions & 0 deletions viser/client/build/static/js/main.f2a05ab1.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
*/

/**
* postprocessing v6.32.0 build Sat Jun 17 2023
* postprocessing v6.31.0 build Sun May 07 2023
* https://github.com/pmndrs/postprocessing
* Copyright 2015-2023 Raoul van Rüschen
* @license Zlib
Expand Down

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions viser/client/build/static/js/main.fbdbcf0c.js

This file was deleted.

26 changes: 13 additions & 13 deletions viser/client/src/CameraControls.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useContext } from "react";
import { PerspectiveCamera } from "three";
import * as holdEvent from "hold-event";
import { CameraControls } from "@react-three/drei";
import { ViewerContext } from ".";
import { makeThrottledMessageSender } from "./WebsocketInterface";
import { CameraControls } from "@react-three/drei";
import { useThree } from "@react-three/fiber";
import * as holdEvent from "hold-event";
import React, { useContext } from "react";
import { PerspectiveCamera } from "three";
import * as THREE from "three";
import { ViewerContext } from ".";

/** OrbitControls, but synchronized with the server and other panels. */
export function SynchronizedCameraControls() {
Expand Down Expand Up @@ -102,16 +102,16 @@ export function SynchronizedCameraControls() {
const sKey = new holdEvent.KeyboardKeyHold(KEYCODE.S, 20);
const dKey = new holdEvent.KeyboardKeyHold(KEYCODE.D, 20);
aKey.addEventListener("holding", (event) => {
cameraControls.truck(-0.002 * event!.deltaTime, 0, false);
cameraControls.truck(-0.002 * event?.deltaTime, 0, false);
});
dKey.addEventListener("holding", (event) => {
cameraControls.truck(0.002 * event!.deltaTime, 0, false);
cameraControls.truck(0.002 * event?.deltaTime, 0, false);
});
wKey.addEventListener("holding", (event) => {
cameraControls.forward(0.002 * event!.deltaTime, false);
cameraControls.forward(0.002 * event?.deltaTime, false);
});
sKey.addEventListener("holding", (event) => {
cameraControls.forward(-0.002 * event!.deltaTime, false);
cameraControls.forward(-0.002 * event?.deltaTime, false);
});

const leftKey = new holdEvent.KeyboardKeyHold(KEYCODE.ARROW_LEFT, 20);
Expand All @@ -120,29 +120,29 @@ export function SynchronizedCameraControls() {
const downKey = new holdEvent.KeyboardKeyHold(KEYCODE.ARROW_DOWN, 20);
leftKey.addEventListener("holding", (event) => {
cameraControls.rotate(
-0.1 * THREE.MathUtils.DEG2RAD * event!.deltaTime,
-0.1 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
0,
true
);
});
rightKey.addEventListener("holding", (event) => {
cameraControls.rotate(
0.1 * THREE.MathUtils.DEG2RAD * event!.deltaTime,
0.1 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
0,
true
);
});
upKey.addEventListener("holding", (event) => {
cameraControls.rotate(
0,
-0.05 * THREE.MathUtils.DEG2RAD * event!.deltaTime,
-0.05 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
true
);
});
downKey.addEventListener("holding", (event) => {
cameraControls.rotate(
0,
0.05 * THREE.MathUtils.DEG2RAD * event!.deltaTime,
0.05 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
true
);
});
Expand Down
13 changes: 7 additions & 6 deletions viser/client/src/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { ViewerContext } from "..";
import GeneratedControls from "./Generated";
import SceneTreeTable from "./SceneTreeTable";
import ServerControls from "./Server";
import { Tabs, TabsValue } from "@mantine/core";
import {
IconAdjustments,
IconBinaryTree2,
IconCloudCheck,
IconCloudOff,
IconTool,
} from "@tabler/icons-react";
import { Tabs, TabsValue } from "@mantine/core";
import { ViewerContext } from "..";
import React from "react";
import GeneratedControls from "./Generated";
import ServerControls from "./Server";
import SceneTreeTable from "./SceneTreeTable";

/** Root component for control panel. Parents a set of control tabs. */
export default function ControlPanel() {
const viewer = React.useContext(ViewerContext)!;

// TODO: will result in unnecessary re-renders
const showGenerated = Object.keys(viewer.useGui((state) => state.guiConfigFromId)).length > 0;
const showGenerated =
Object.keys(viewer.useGui((state) => state.guiConfigFromId)).length > 0;

const [tabState, setTabState] = React.useState<TabsValue>("server");

Expand Down
26 changes: 13 additions & 13 deletions viser/client/src/ControlPanel/FloatingPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Box, Paper } from "@mantine/core";
import { IconCaretUp } from "@tabler/icons-react";
import React from "react";

const FloatingPanelRefContext =
React.createContext<React.RefObject<HTMLDivElement> | null>(null);
Expand Down Expand Up @@ -112,8 +112,8 @@ FloatingPanel.Handle = function FloatingPanelHandle({
);
newY = Math.max(newY, panelBoundaryPad);

panel.style.top = newY.toString() + "px";
panel.style.left = newX.toString() + "px";
panel.style.top = `${newY.toString()}px`;
panel.style.left = `${newX.toString()}px`;

return [
computePanelOffset(newX, panel.clientWidth, parent.clientWidth),
Expand All @@ -129,8 +129,10 @@ FloatingPanel.Handle = function FloatingPanelHandle({
const parent = panel.parentElement;
if (parent === null) return;

panel.style.maxHeight =
(parent.clientHeight - panelBoundaryPad * 2).toString() + "px";
panel.style.maxHeight = `${(
parent.clientHeight -
panelBoundaryPad * 2
).toString()}px`;

const observer = new ResizeObserver(() => {
if (unfixedOffset.current.x === undefined)
Expand All @@ -146,8 +148,10 @@ FloatingPanel.Handle = function FloatingPanelHandle({
parent.clientHeight
);

panel.style.maxHeight =
(parent.clientHeight - panelBoundaryPad * 2).toString() + "px";
panel.style.maxHeight = `${(
parent.clientHeight -
panelBoundaryPad * 2
).toString()}px`;

let newX = unfixedOffset.current.x;
let newY = unfixedOffset.current.y;
Expand All @@ -167,7 +171,7 @@ FloatingPanel.Handle = function FloatingPanelHandle({
color="red"
sx={(theme) => ({
backgroundColor:
theme.colorScheme == "dark"
theme.colorScheme === "dark"
? theme.colors.dark[5]
: theme.colors.gray[1],
lineHeight: "1.5em",
Expand Down Expand Up @@ -256,9 +260,5 @@ FloatingPanel.Contents = function FloatingPanelContents({
}: {
children: string | React.ReactNode;
}) {
return (
<Box className="panel-contents">
{children}
</Box>
);
return <Box className="panel-contents">{children}</Box>;
};
9 changes: 4 additions & 5 deletions viser/client/src/ControlPanel/Generated.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { ViewerContext } from "..";
import { makeThrottledMessageSender } from "../WebsocketInterface";
import { GuiConfig } from "./GuiState";
import {
Accordion,
Expand All @@ -11,13 +11,12 @@ import {
NumberInput,
Select,
Slider,
Space,
Stack,
Text,
TextInput,
Tooltip,
} from "@mantine/core";
import { makeThrottledMessageSender } from "../WebsocketInterface";
import React from "react";

type Folder = {
inputs: GuiConfig[];
Expand Down Expand Up @@ -72,7 +71,7 @@ function GeneratedFolder({ folder }: { folder: Folder }) {
content: {
borderLeft: "1px solid",
borderLeftColor:
theme.colorScheme == "light"
theme.colorScheme === "light"
? theme.colors.gray[3]
: theme.colors.dark[5],
paddingRight: "0",
Expand Down Expand Up @@ -357,7 +356,7 @@ function VectorInput(
<Flex justify="space-between" style={{ columnGap: "0.3rem" }}>
{[...Array(props.n).keys()].map((i) => (
<NumberInput
id={i == 0 ? props.id : undefined}
id={i === 0 ? props.id : undefined}
key={i}
value={props.value[i]}
onChange={(v) => {
Expand Down
2 changes: 1 addition & 1 deletion viser/client/src/ControlPanel/GuiState.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Messages from "../WebsocketMessages";
import React from "react";
import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
import * as Messages from "../WebsocketMessages";

export type GuiConfig =
| Messages.GuiAddButtonMessage
Expand Down
12 changes: 6 additions & 6 deletions viser/client/src/ControlPanel/SceneTreeTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ViewerContext } from "..";
import { ActionIcon, Modal } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import {
IconCaretDown,
IconCaretRight,
Expand All @@ -9,8 +11,6 @@ import {
import { MantineReactTable } from "mantine-react-table";
import { MRT_ColumnDef } from "mantine-react-table";
import React from "react";
import { ViewerContext } from "..";
import { useDisclosure } from "@mantine/hooks";

interface SceneTreeTableRow {
name: string;
Expand Down Expand Up @@ -99,7 +99,7 @@ export default function SceneTreeTable(props: { compact: boolean }) {
<CaretIcon
style={{
opacity: row.subRows?.length === 0 ? "0.0" : "0.4",
marginLeft: (0.75 * row.depth).toString() + "em",
marginLeft: `${(0.75 * row.depth).toString()}em`,
}}
size="1em"
/>
Expand All @@ -111,9 +111,9 @@ export default function SceneTreeTable(props: { compact: boolean }) {
// selecting text when dragging over the hide/show icons.
<span key={index} style={{ userSelect: "none" }}>
<span style={{ opacity: "0.4" }}>
{index == all.length - 1 ? "/" : "/" + part}
{index === all.length - 1 ? "/" : `/${part}`}
</span>
{index == all.length - 1 ? part : ""}
{index === all.length - 1 ? part : ""}
</span>
))}
</>
Expand Down Expand Up @@ -197,7 +197,7 @@ export default function SceneTreeTable(props: { compact: boolean }) {
// table.getIsSomeRowsSelected()
//
const disabled =
table.getFilteredSelectedRowModel().flatRows.length == 0;
table.getFilteredSelectedRowModel().flatRows.length === 0;
return (
<div style={{ display: "flex", gap: "8px" }}>
<ActionIcon
Expand Down
14 changes: 6 additions & 8 deletions viser/client/src/ControlPanel/Server.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import React from "react";
import { ViewerContext } from "..";
import { isTexture } from "../WebsocketInterface";
import { Button, Stack, Switch, TextInput } from "@mantine/core";
import { Stats } from "@react-three/drei";
import { TextInput, Button, Stack, Switch } from "@mantine/core";
import { IconPhoto } from "@tabler/icons-react";
import React from "react";

export default function ServerControls() {
const viewer = React.useContext(ViewerContext)!;
const [showStats, setShowStats] = React.useState(false);

function triggerBlur(event: React.KeyboardEvent<HTMLInputElement>) {
if (event.key != "Enter") return;
if (event.key !== "Enter") return;
event.currentTarget.blur();
event.currentTarget.focus();
}

return (
<>
{showStats ? (
<Stats className="stats-panel" />
) : null}
{showStats ? <Stats className="stats-panel" /> : null}
<Stack spacing="xs">
<TextInput
label="Label"
Expand All @@ -39,13 +37,13 @@ export default function ServerControls() {
/>
<Button
onClick={() => {
if (!isTexture(viewer.sceneRef.current!.background)) {
if (!isTexture(viewer.sceneRef.current?.background)) {
// This should never happen.
alert("No background to download!");
return;
}

const data = viewer.sceneRef.current!.background.image.src;
const data = viewer.sceneRef.current?.background.image.src;
console.log(data);
const link = document.createElement("a");
link.download = "background";
Expand Down
Loading

0 comments on commit 716b8cc

Please sign in to comment.