From 4ac3ff4614c98a3ae0f0ead9031e759b4bc100a3 Mon Sep 17 00:00:00 2001 From: Ashley Anderson Date: Fri, 29 Mar 2024 17:55:20 -0500 Subject: [PATCH] Organize source files into subdirs (#58) --- __tests__/main.test.tsx | 2 +- index.html | 2 +- src/assets/preact.svg | 1 - src/{ => components}/app.tsx | 4 ++-- src/{ => components}/main.tsx | 4 ++-- src/{ => components}/scene.tsx | 10 +++++----- src/{ => css}/app.css | 0 src/{ => css}/index.css | 0 src/hooks/useSelectionBox.ts | 4 ++-- src/{ => lib}/PointCanvas.ts | 2 +- src/{ => lib}/PointSelectionBox.ts | 0 src/{ => lib}/TrackManager.ts | 0 src/{ => lib}/ViewerState.ts | 0 tsconfig.json | 8 +++++++- vite.config.ts | 5 +++++ 15 files changed, 26 insertions(+), 16 deletions(-) delete mode 100644 src/assets/preact.svg rename src/{ => components}/app.tsx (94%) rename src/{ => components}/main.tsx (91%) rename src/{ => components}/scene.tsx (97%) rename src/{ => css}/app.css (100%) rename src/{ => css}/index.css (100%) rename src/{ => lib}/PointCanvas.ts (99%) rename src/{ => lib}/PointSelectionBox.ts (100%) rename src/{ => lib}/TrackManager.ts (100%) rename src/{ => lib}/ViewerState.ts (100%) diff --git a/__tests__/main.test.tsx b/__tests__/main.test.tsx index 55c9bb7b..af4b845f 100644 --- a/__tests__/main.test.tsx +++ b/__tests__/main.test.tsx @@ -1,6 +1,6 @@ import { expect, test } from "vitest"; -import Scene from "../src/scene"; +import Scene from "@/components/scene"; import React from "react"; import { render } from "@testing-library/react"; diff --git a/index.html b/index.html index 4ad1c503..9f2a2f58 100644 --- a/index.html +++ b/index.html @@ -13,6 +13,6 @@
- + diff --git a/src/assets/preact.svg b/src/assets/preact.svg deleted file mode 100644 index 908f17de..00000000 --- a/src/assets/preact.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/app.tsx b/src/components/app.tsx similarity index 94% rename from src/app.tsx rename to src/components/app.tsx index 7d30c2ae..9fb021dc 100644 --- a/src/app.tsx +++ b/src/components/app.tsx @@ -1,6 +1,6 @@ import { useState, useEffect } from "react"; -import "./app.css"; -import Scene from "./scene.tsx"; +import "@/css/app.css"; +import Scene from "@/components/scene.tsx"; const aspectRatio = 4 / 3; diff --git a/src/main.tsx b/src/components/main.tsx similarity index 91% rename from src/main.tsx rename to src/components/main.tsx index eb385f5e..c98f99d1 100644 --- a/src/main.tsx +++ b/src/components/main.tsx @@ -4,8 +4,8 @@ import { ThemeProvider as EmotionThemeProvider } from "@emotion/react"; import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles"; import { defaultTheme } from "@czi-sds/components"; -import App from "./app.tsx"; -import "./index.css"; +import App from "@/components/app.tsx"; +import "@/css/index.css"; const domNode = document.getElementById("app")!; const root = createRoot(domNode); diff --git a/src/scene.tsx b/src/components/scene.tsx similarity index 97% rename from src/scene.tsx rename to src/components/scene.tsx index 85806d57..e646ffcf 100644 --- a/src/scene.tsx +++ b/src/components/scene.tsx @@ -1,11 +1,11 @@ import { useEffect, useRef, useState } from "react"; import { Button, InputSlider, InputText, InputToggle, LoadingIndicator } from "@czi-sds/components"; -import { PointCanvas } from "./PointCanvas"; -import { TrackManager, loadTrackManager } from "./TrackManager"; -import useSelectionBox from "./hooks/useSelectionBox"; +import { PointCanvas } from "@/lib/PointCanvas"; +import { TrackManager, loadTrackManager } from "@/lib/TrackManager"; +import { ViewerState, clearUrlHash } from "@/lib/ViewerState"; -import { ViewerState, clearUrlHash } from "./ViewerState"; +import useSelectionBox from "@/hooks/useSelectionBox"; interface SceneProps { renderWidth?: number; @@ -113,7 +113,7 @@ export default function Scene(props: SceneProps) { canvas.current?.highlightPoints(selected); const maxPointsPerTimepoint = trackManager?.maxPointsPerTimepoint || 0; - Promise.all(selected.map((p) => curTime * maxPointsPerTimepoint + p).map(fetchAndAddTrack)); + Promise.all(selected.map((p: number) => curTime * maxPointsPerTimepoint + p).map(fetchAndAddTrack)); // TODO: cancel the fetch if the selection changes? }, [selectedPoints]); diff --git a/src/app.css b/src/css/app.css similarity index 100% rename from src/app.css rename to src/css/app.css diff --git a/src/index.css b/src/css/index.css similarity index 100% rename from src/index.css rename to src/css/index.css diff --git a/src/hooks/useSelectionBox.ts b/src/hooks/useSelectionBox.ts index 85c04f40..be5100ca 100644 --- a/src/hooks/useSelectionBox.ts +++ b/src/hooks/useSelectionBox.ts @@ -1,8 +1,8 @@ import { SelectionHelper } from "three/addons/interactive/SelectionHelper.js"; import { useEffect, useRef, useState } from "react"; -import { PointSelectionBox, PointsCollection } from "../PointSelectionBox"; -import { PointCanvas } from "../PointCanvas"; +import { PointSelectionBox, PointsCollection } from "@/lib/PointSelectionBox"; +import { PointCanvas } from "@/lib/PointCanvas"; export default function useSelectionBox(canvas: PointCanvas | undefined) { const [selecting, setSelecting] = useState(false); diff --git a/src/PointCanvas.ts b/src/lib/PointCanvas.ts similarity index 99% rename from src/PointCanvas.ts rename to src/lib/PointCanvas.ts index 3d260c0a..b53ac834 100644 --- a/src/PointCanvas.ts +++ b/src/lib/PointCanvas.ts @@ -21,7 +21,7 @@ import { RenderPass } from "three/addons/postprocessing/RenderPass.js"; import { OutputPass } from "three/addons/postprocessing/OutputPass.js"; import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js"; -import { Track } from "./lib/three/Track"; +import { Track } from "@/lib/three/Track"; type Tracks = Map; diff --git a/src/PointSelectionBox.ts b/src/lib/PointSelectionBox.ts similarity index 100% rename from src/PointSelectionBox.ts rename to src/lib/PointSelectionBox.ts diff --git a/src/TrackManager.ts b/src/lib/TrackManager.ts similarity index 100% rename from src/TrackManager.ts rename to src/lib/TrackManager.ts diff --git a/src/ViewerState.ts b/src/lib/ViewerState.ts similarity index 100% rename from src/ViewerState.ts rename to src/lib/ViewerState.ts diff --git a/tsconfig.json b/tsconfig.json index cd7ce624..3440dd52 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,13 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + + /* Paths */ + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + } }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] diff --git a/vite.config.ts b/vite.config.ts index 1201335e..c14eec59 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,6 +5,11 @@ import react from "@vitejs/plugin-react"; export default defineConfig({ plugins: [react()], + resolve: { + alias: { + "@": "/src", + }, + }, test: { environment: "jsdom", browser: {