Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Aug 4, 2023
1 parent 2d61e3a commit 83bcbf3
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 100 deletions.
8 changes: 4 additions & 4 deletions viser/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ViewerContextContents = {
}>;
};
export const ViewerContext = React.createContext<null | ViewerContextContents>(
null
null,
);

THREE.ColorManagement.enabled = true;
Expand All @@ -65,7 +65,7 @@ function SingleViewer() {
return server;
}
const servers = new URLSearchParams(window.location.search).getAll(
searchParamKey
searchParamKey,
);
const initialServer =
servers.length >= 1 ? servers[0] : getDefaultServerFromUrl();
Expand All @@ -87,7 +87,7 @@ function SingleViewer() {
// viewer context changes.
const memoizedWebsocketInterface = React.useMemo(
() => <WebsocketInterface />,
[]
[],
);

const control_layout = viewer.useGui((state) => state.theme.control_layout);
Expand Down Expand Up @@ -177,7 +177,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
10 changes: 5 additions & 5 deletions 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,
);

// Callback for sending cameras.
Expand Down Expand Up @@ -122,28 +122,28 @@ export function SynchronizedCameraControls() {
cameraControls.rotate(
-0.1 * THREE.MathUtils.DEG2RAD * event?.deltaTime,
0,
true
true,
);
});
rightKey.addEventListener("holding", (event) => {
cameraControls.rotate(
0.1 * 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
16 changes: 8 additions & 8 deletions viser/client/src/ControlPanel/FloatingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FloatingPanel.Handle = function FloatingPanelHandle({
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 @@ -98,12 +98,12 @@ FloatingPanel.Handle = function FloatingPanelHandle({

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 @@ -134,13 +134,13 @@ FloatingPanel.Handle = function FloatingPanelHandle({
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 All @@ -164,7 +164,7 @@ FloatingPanel.Handle = function FloatingPanelHandle({
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 @@ -201,7 +201,7 @@ FloatingPanel.Handle = function FloatingPanelHandle({
const newY = state.startPosY + deltaY;
[unfixedOffset.current.x, unfixedOffset.current.y] = setPanelLocation(
newX,
newY
newY,
);
}
window.addEventListener(eventNames.move, dragListener);
Expand All @@ -213,7 +213,7 @@ FloatingPanel.Handle = function FloatingPanelHandle({
}
window.removeEventListener(eventNames.move, dragListener);
},
{ once: true }
{ once: true },
);
};

Expand Down
4 changes: 2 additions & 2 deletions viser/client/src/ControlPanel/Generated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function GeneratedGuiContainer({
}) {
const 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 @@ -406,7 +406,7 @@ function VectorInput(
precision: number;
onChange: (value: number[]) => void;
disabled: boolean;
}
},
) {
return (
<Flex justify="space-between" style={{ columnGap: "0.3rem" }}>
Expand Down
8 changes: 4 additions & 4 deletions viser/client/src/ControlPanel/GuiState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const cleanGuiState: GuiState = {
theme: {
type: "ThemeConfigurationMessage",
titlebar_content: null,
control_layout: 'floating',
control_layout: "floating",
dark_mode: false,
},
label: "",
Expand Down Expand Up @@ -125,7 +125,7 @@ export function useGuiState(initialServer: string) {
if (guiIdSet === undefined) {
console.log(
"Tried to remove but could not find container ID",
containerId
containerId,
);
return;
}
Expand All @@ -139,8 +139,8 @@ export function useGuiState(initialServer: string) {
state.guiValueFromId = {};
state.guiAttributeFromId = {};
}),
}))
)
})),
),
)[0];
}

Expand Down
8 changes: 4 additions & 4 deletions 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
20 changes: 10 additions & 10 deletions 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 Down Expand Up @@ -65,7 +65,7 @@ function SceneNodeThreeChildren(props: {
}
const unsubscribe = viewer.useSceneTree.subscribe(
(state) => state.nodeFromName[props.name],
updateChildren
updateChildren,
);
updateChildren();

Expand All @@ -82,15 +82,15 @@ function SceneNodeThreeChildren(props: {
return <SceneNodeThreeObject key={child_id} name={child_id} />;
})}
</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 @@ -113,10 +113,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 @@ -126,14 +126,14 @@ export function SceneNodeThreeObject(props: { name: string }) {
// Create object + children.
const objNode = React.useMemo(
() => makeObject && makeObject(setRef),
[setRef, makeObject]
[setRef, makeObject],
);
const children = React.useMemo(
() =>
obj === null ? null : (
<SceneNodeThreeChildren name={props.name} parent={obj} />
),
[props.name, obj]
[props.name, obj],
);

// Update attributes on a per-frame basis. Currently does redundant work,
Expand Down Expand Up @@ -174,7 +174,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 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];
}
4 changes: 2 additions & 2 deletions viser/client/src/SearchParamsUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function setServerParams(serverParams: string[]) {
if (
serverParams.length === 1 &&
window.location.host.includes(
serverParams[0].replace("ws://", "").replace("/", "")
serverParams[0].replace("ws://", "").replace("/", ""),
)
)
serverParams = [];
Expand All @@ -26,6 +26,6 @@ function setServerParams(serverParams: string[]) {
// it. We're going to just not escape the string. :)
serverParams.length === 0
? window.location.href.split("?")[0]
: `?${serverParams.map((s) => `${searchParamKey}=${s}`).join("&")}`
: `?${serverParams.map((s) => `${searchParamKey}=${s}`).join("&")}`,
);
}
Loading

0 comments on commit 83bcbf3

Please sign in to comment.