Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Sep 21, 2023
1 parent 9021636 commit b10f39d
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 110 deletions.
12 changes: 6 additions & 6 deletions src/viser/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type ViewerContextContents = {
getRenderRequest: React.MutableRefObject<null | GetRenderRequestMessage>;
};
export const ViewerContext = React.createContext<null | ViewerContextContents>(
null
null,
);

THREE.ColorManagement.enabled = true;
Expand All @@ -86,7 +86,7 @@ function ViewerRoot() {
return server;
}
const servers = new URLSearchParams(window.location.search).getAll(
searchParamKey
searchParamKey,
);
const initialServer =
servers.length >= 1 ? servers[0] : getDefaultServerFromUrl();
Expand Down Expand Up @@ -268,7 +268,7 @@ function BackgroundImage() {
// Logic ahead relies on perspective camera assumption.
if (!(camera instanceof THREE.PerspectiveCamera)) {
console.error(
"Camera is not a perspective camera, cannot render background image"
"Camera is not a perspective camera, cannot render background image",
);
return;
}
Expand All @@ -278,7 +278,7 @@ function BackgroundImage() {
backgroundMesh.current!.position.set(
camera.position.x,
camera.position.y,
camera.position.z
camera.position.z,
);
backgroundMesh.current!.position.addScaledVector(lookdir, 1.0);
backgroundMesh.current!.quaternion.copy(camera.quaternion);
Expand All @@ -288,7 +288,7 @@ function BackgroundImage() {
backgroundMesh.current!.scale.set(
camera.getFilmWidth() / f,
camera.getFilmHeight() / f,
1.0
1.0,
);

// Set near/far uniforms.
Expand All @@ -312,7 +312,7 @@ function SceneContextSetter() {
const { sceneRef, cameraRef } = React.useContext(ViewerContext)!;
sceneRef.current = useThree((state) => state.scene);
cameraRef.current = useThree(
(state) => state.camera as THREE.PerspectiveCamera
(state) => state.camera as THREE.PerspectiveCamera,
);
return <></>;
}
Expand Down
14 changes: 7 additions & 7 deletions src/viser/client/src/CameraControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function SynchronizedCameraControls() {

const sendCameraThrottled = makeThrottledMessageSender(
viewer.websocketRef,
20
20,
);

type CameraDetails = {
Expand Down Expand Up @@ -114,12 +114,12 @@ export function SynchronizedCameraControls() {
const newPosition = new THREE.Vector3().lerpVectors(
camera.position,
targetPosition,
alpha
alpha,
);
const newLookAt = new THREE.Vector3().lerpVectors(
cameraControls.getTarget(new THREE.Vector3()),
targetLookAt,
alpha
alpha,
);

if (newPosition.distanceTo(targetPosition) < tolerance) {
Expand Down Expand Up @@ -219,28 +219,28 @@ export function SynchronizedCameraControls() {
cameraControls.rotate(
-0.05 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
0,
true
true,
);
});
rightKey.addEventListener("holding", (event) => {
cameraControls.rotate(
0.05 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
0,
true
true,
);
});
upKey.addEventListener("holding", (event) => {
cameraControls.rotate(
0,
-0.05 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
true
true,
);
});
downKey.addEventListener("holding", (event) => {
cameraControls.rotate(
0,
0.05 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
true
true,
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/viser/client/src/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function ControlPanel(props: {
// TODO: will result in unnecessary re-renders.
const viewer = React.useContext(ViewerContext)!;
const showGenerated = viewer.useGui(
(state) => "root" in state.guiIdSetFromContainerId
(state) => "root" in state.guiIdSetFromContainerId,
);
const [showSettings, { toggle }] = useDisclosure(false);

Expand Down
16 changes: 8 additions & 8 deletions src/viser/client/src/ControlPanel/FloatingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function FloatingPanel({
const computePanelOffset = (
panelPosition: number,
panelSize: number,
parentSize: number
parentSize: number,
) =>
Math.abs(panelPosition + panelSize / 2.0) <
Math.abs(panelPosition - parentSize + panelSize / 2.0)
Expand All @@ -73,12 +73,12 @@ export default function FloatingPanel({

newX = Math.min(
newX,
parent.clientWidth - panel.clientWidth - panelBoundaryPad
parent.clientWidth - panel.clientWidth - panelBoundaryPad,
);
newX = Math.max(newX, panelBoundaryPad);
newY = Math.min(
newY,
parent.clientHeight - panel.clientHeight - panelBoundaryPad
parent.clientHeight - panel.clientHeight - panelBoundaryPad,
);
newY = Math.max(newY, panelBoundaryPad);

Expand Down Expand Up @@ -109,13 +109,13 @@ export default function FloatingPanel({
unfixedOffset.current.x = computePanelOffset(
panel.offsetLeft,
panel.clientWidth,
parent.clientWidth
parent.clientWidth,
);
if (unfixedOffset.current.y === undefined)
unfixedOffset.current.y = computePanelOffset(
panel.offsetTop,
panel.clientHeight,
parent.clientHeight
parent.clientHeight,
);

// panel.style.maxHeight = `${(
Expand Down Expand Up @@ -145,7 +145,7 @@ export default function FloatingPanel({
const dragHandler = (
event:
| React.TouchEvent<HTMLDivElement>
| React.MouseEvent<HTMLDivElement, MouseEvent>
| React.MouseEvent<HTMLDivElement, MouseEvent>,
) => {
const state = dragInfo.current;
const panel = panelWrapperRef.current;
Expand Down Expand Up @@ -182,7 +182,7 @@ export default function FloatingPanel({
const newY = state.startPosY + deltaY;
[unfixedOffset.current.x, unfixedOffset.current.y] = setPanelLocation(
newX,
newY
newY,
);
}
window.addEventListener(eventNames.move, dragListener);
Expand All @@ -194,7 +194,7 @@ export default function FloatingPanel({
}
window.removeEventListener(eventNames.move, dragListener);
},
{ once: true }
{ once: true },
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/viser/client/src/ControlPanel/Generated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function GeneratedGuiContainer({
if (viewer === undefined) viewer = React.useContext(ViewerContext)!;

const guiIdSet = viewer.useGui(
(state) => state.guiIdSetFromContainerId[containerId]
(state) => state.guiIdSetFromContainerId[containerId],
);
const guiConfigFromId = viewer.useGui((state) => state.guiConfigFromId);

Expand Down Expand Up @@ -505,7 +505,7 @@ function VectorInput(
precision: number;
onChange: (value: number[]) => void;
disabled: boolean;
}
},
) {
return (
<Flex justify="space-between" style={{ columnGap: "0.3rem" }}>
Expand Down
4 changes: 2 additions & 2 deletions src/viser/client/src/ControlPanel/GuiState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export function useGuiState(initialServer: string) {
state.guiValueFromId = {};
state.guiAttributeFromId = {};
}),
}))
)
})),
),
)[0];
}

Expand Down
8 changes: 4 additions & 4 deletions src/viser/client/src/ControlPanel/SceneTreeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function SceneTreeTable(props: { compact: boolean }) {

const nodeFromName = viewer.useSceneTree((state) => state.nodeFromName);
const setLabelVisibility = viewer.useSceneTree(
(state) => state.setLabelVisibility
(state) => state.setLabelVisibility,
);
function setVisible(name: string, visible: boolean) {
const attr = viewer.nodeAttributesFromName.current;
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function SceneTreeTable(props: { compact: boolean }) {
function getSceneTreeSubRows(
parentName: string,
parentCount: number,
isParentVisible: boolean
isParentVisible: boolean,
): SceneTreeTableRow[] {
const node = nodeFromName[parentName];
if (node === undefined) return [];
Expand Down Expand Up @@ -106,7 +106,7 @@ export default function SceneTreeTable(props: { compact: boolean }) {
subRows: getSceneTreeSubRows(
childName,
parentCount + 1,
isVisibleEffective
isVisibleEffective,
),
};
});
Expand Down Expand Up @@ -156,7 +156,7 @@ export default function SceneTreeTable(props: { compact: boolean }) {
},
},
],
[]
[],
);

const [sceneTreeOpened, { open: openSceneTree, close: closeSceneTree }] =
Expand Down
4 changes: 3 additions & 1 deletion src/viser/client/src/ControlPanel/SidebarPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export default function SidebarPanel({
toggleCollapsed();
}}
>
<Tooltip zIndex={100} label={"Show sidebar"}>{<IconChevronLeft />}</Tooltip>
<Tooltip zIndex={100} label={"Show sidebar"}>
{<IconChevronLeft />}
</Tooltip>
</ActionIcon>
</Box>
);
Expand Down
18 changes: 9 additions & 9 deletions src/viser/client/src/SceneTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Text } from "@mantine/core";
import { useSceneTreeState } from "./SceneTreeState";

export type MakeObject<T extends THREE.Object3D = THREE.Object3D> = (
ref: React.Ref<T>
ref: React.Ref<T>,
) => React.ReactNode;

/** Scenes will consist of nodes, which form a tree. */
Expand All @@ -25,7 +25,7 @@ export class SceneNode<T extends THREE.Object3D = THREE.Object3D> {
constructor(
public name: string,
public makeObject: MakeObject<T>,
public cleanup?: () => void
public cleanup?: () => void,
) {
this.children = [];
this.clickable = false;
Expand All @@ -41,7 +41,7 @@ function SceneNodeThreeChildren(props: {
}) {
const viewer = React.useContext(ViewerContext)!;
const children = viewer.useSceneTree(
(state) => state.nodeFromName[props.name]?.children
(state) => state.nodeFromName[props.name]?.children,
);

// Create a group of children inside of the parent object.
Expand All @@ -53,15 +53,15 @@ function SceneNodeThreeChildren(props: {
})}
<SceneNodeLabel name={props.name} />
</group>,
props.parent
props.parent,
);
}

/** Component for updating attributes of a scene node. */
function SceneNodeLabel(props: { name: string }) {
const viewer = React.useContext(ViewerContext)!;
const labelVisible = viewer.useSceneTree(
(state) => state.labelVisibleFromName[props.name]
(state) => state.labelVisibleFromName[props.name],
);
return labelVisible ? (
<Html>
Expand All @@ -84,10 +84,10 @@ function SceneNodeLabel(props: { name: string }) {
export function SceneNodeThreeObject(props: { name: string }) {
const viewer = React.useContext(ViewerContext)!;
const makeObject = viewer.useSceneTree(
(state) => state.nodeFromName[props.name]?.makeObject
(state) => state.nodeFromName[props.name]?.makeObject,
);
const cleanup = viewer.useSceneTree(
(state) => state.nodeFromName[props.name]?.cleanup
(state) => state.nodeFromName[props.name]?.cleanup,
);
const clickable =
viewer.useSceneTree((state) => state.nodeFromName[props.name]?.clickable) ??
Expand All @@ -101,7 +101,7 @@ export function SceneNodeThreeObject(props: { name: string }) {
// PivotControls.
const objNode = React.useMemo(
() => makeObject && makeObject(setRef),
[makeObject]
[makeObject],
);
const children =
obj === null ? null : (
Expand Down Expand Up @@ -146,7 +146,7 @@ export function SceneNodeThreeObject(props: { name: string }) {
// Clicking logic.
const sendClicksThrottled = makeThrottledMessageSender(
viewer.websocketRef,
50
50,
);
const [hovered, setHovered] = React.useState(false);
useCursor(hovered);
Expand Down
14 changes: 7 additions & 7 deletions src/viser/client/src/SceneTreeState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const makeRoot: MakeObject<THREE.Group> = (ref) => (
<group
ref={ref}
quaternion={new THREE.Quaternion().setFromEuler(
new THREE.Euler(-Math.PI / 2.0, 0.0, 0.0)
new THREE.Euler(-Math.PI / 2.0, 0.0, 0.0),
)}
/>
);
Expand All @@ -35,12 +35,12 @@ const rootAxesTemplate: MakeObject<THREE.Group> = (ref) => (

const rootNodeTemplate = new SceneNode(
"",
makeRoot
makeRoot,
) as SceneNode<THREE.Object3D>;

const rootAxesNode = new SceneNode(
"/WorldAxes",
rootAxesTemplate
rootAxesTemplate,
) as SceneNode<THREE.Object3D>;
rootNodeTemplate.children.push("/WorldAxes");

Expand Down Expand Up @@ -87,7 +87,7 @@ export function useSceneTreeState() {
function findChildrenRecursive(name: string) {
removeNames.push(name);
state.nodeFromName[name]!.children.forEach(
findChildrenRecursive
findChildrenRecursive,
);
}
findChildrenRecursive(name);
Expand Down Expand Up @@ -116,8 +116,8 @@ export function useSceneTreeState() {
set((state) => {
state.labelVisibleFromName[name] = labelVisibility;
}),
}))
)
)
})),
),
),
)[0];
}
Loading

0 comments on commit b10f39d

Please sign in to comment.