Skip to content

Commit

Permalink
feat: begin moving common interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
micahg committed Jul 25, 2024
1 parent 8d51d8f commit a64a1b1
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 137 deletions.
284 changes: 200 additions & 84 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"homepage": "https://github.com/micahg/tbltp",
"workspaces": [
"packages/api",
"packages/mui"
"packages/mui",
"packages/common"
]
}
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"websocket": "^1.0.34"
},
"dependencies": {
"@micahg/tbltp-common": "file:../common",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.48.0",
"@opentelemetry/exporter-jaeger": "^1.25.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/models/scene.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Schema, model } from "mongoose";
import { Rect } from "../utils/tablestate";
import { Rect } from "@micahg/tbltp-common";

/**
* Student Interface.
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
updateAssetFromUpload,
} from "../utils/localstore";
import { validateAngle, validateViewPort } from "../utils/viewport";
import { Rect } from "../utils/tablestate";
import { Rect } from "@micahg/tbltp-common";

const NAME_REGEX = /^[\w\s]{1,64}$/;

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/utils/scene.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IScene, Scene } from "../models/scene";
import { IUser } from "../models/user";
import { Rect } from "./tablestate";
import { Rect } from "@micahg/tbltp-common";

export function getSceneById(id: string, userId: string) {
return Scene.findOne({ _id: id, user: userId });
Expand Down
19 changes: 0 additions & 19 deletions packages/api/src/utils/tablestate.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api/src/utils/viewport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Rect } from "./tablestate";
import { Rect } from "@micahg/tbltp-common";

export function validateViewPort(viewport: Rect): boolean {
if (!viewport) return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/utils/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "./constants";

import { log } from "./logger";
import { TableState } from "./tablestate";
import { TableState } from "@micahg/tbltp-common";
import { getFakeUser } from "./auth";
import { IScene } from "../models/scene";
import { getUserByID } from "./user";
Expand Down
18 changes: 18 additions & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@micahg/tbltp-common",
"version": "0.1.0",
"description": "Common bits for tbltp",
"main": "src/index.ts",
"devDependencies": {
"ts-loader": "^9.5.1",
"typescript": "^5.5.4",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --progress --config webpack.config.js"
},
"author": "Micah Galizia",
"license": "ISC"
}
6 changes: 6 additions & 0 deletions packages/common/src/geometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Rect {
x: number;
y: number;
width: number;
height: number;
}
2 changes: 2 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./geometry";
export * from "./tablestate";
12 changes: 12 additions & 0 deletions packages/common/src/tablestate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Rect } from "./geometry";

export interface TableState {
overlay?: string;
overlayRev?: number;
background?: string;
backgroundRev?: number;
viewport: Rect;
angle: number;
backgroundSize?: Rect;
}

11 changes: 11 additions & 0 deletions packages/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"allowJs": true,
"moduleResolution": "node",
"declaration": true,
}
}
21 changes: 21 additions & 0 deletions packages/common/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path');

module.exports = {
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
1 change: 1 addition & 0 deletions packages/mui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@auth0/auth0-spa-js": "^2.1.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@micahg/tbltp-common": "file:../common",
"@mui/icons-material": "^5.14.1",
"@mui/material": "^5.15.8",
"@reduxjs/toolkit": "^1.9.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/mui/src/components/ContentEditor/ContentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, {
import { useDispatch, useSelector } from "react-redux";
import { AppReducerState } from "../../reducers/AppReducer";
import { getRect, newSelectedRegion } from "../../utils/drawing";
import { Rect, equalRects } from "../../utils/geometry";
import { equalRects } from "../../utils/geometry";
import { MouseStateMachine } from "../../utils/mousestatemachine";
import { setCallback } from "../../utils/statemachine";
import styles from "./ContentEditor.module.css";
Expand Down Expand Up @@ -45,6 +45,7 @@ import {
import { setupOffscreenCanvas } from "../../utils/offscreencanvas";
import { debounce } from "lodash";
import { LoadProgress } from "../../utils/content";
import { Rect } from "@micahg/tbltp-common";

const sm = new MouseStateMachine();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createRef, useCallback, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { AppReducerState } from "../../reducers/AppReducer";
import { Rect } from "../../utils/geometry";
import Alert from "@mui/material/Alert";
import Stack from "@mui/material/Stack";

Expand All @@ -11,21 +10,7 @@ import { Box } from "@mui/material";
import { setupOffscreenCanvas } from "../../utils/offscreencanvas";
import { debounce } from "lodash";
import { Thing } from "../../utils/drawing";

/**
* Table state sent to display client by websocket. A partial Scene.
*
* TODO do not redefine this - move models somewhere neutral.
*/
export interface TableState {
overlay?: string;
overlayRev?: number;
background?: string;
backgroundRev?: number;
viewport: Rect;
angle: number;
backgroundSize?: Rect;
}
import { Rect, TableState } from "@micahg/tbltp-common";

// TODO UNION MICAH DON"T SKIP NOW
export type TableUpdate = TableState & {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui/src/middleware/ContentMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios, { AxiosProgressEvent, AxiosResponse } from "axios";
import { AppReducerState } from "../reducers/AppReducer";
import { getToken } from "../utils/auth";
import { ContentReducerError, Scene } from "../reducers/ContentReducer";
import { Rect } from "../utils/geometry";
import { Rect } from "@micahg/tbltp-common";
import { AnyAction, Dispatch, MiddlewareAPI } from "@reduxjs/toolkit";
import { LoadProgress } from "../utils/content";

Expand Down
2 changes: 1 addition & 1 deletion packages/mui/src/reducers/ContentReducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PayloadAction } from "@reduxjs/toolkit";
import { Rect } from "../utils/geometry";
import { Rect } from "@micahg/tbltp-common";

// copied from api
export interface Scene {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui/src/utils/contentworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { LoadProgress, loadImage } from "./content";
import { Drawable, Thing, newDrawableThing } from "./drawing";
import {
Point,
Rect,
createPoints,
firstZoomStep,
normalizeRect,
Expand All @@ -18,6 +17,7 @@ import {
translatePoints,
copyRect,
} from "./geometry";
import { Rect } from "@micahg/tbltp-common";

/**
* Worker for offscreen drawing in the content editor.
Expand Down
2 changes: 1 addition & 1 deletion packages/mui/src/utils/drawing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Rect } from "./geometry";
import { Rect } from "@micahg/tbltp-common";

export type DrawContext = CanvasDrawPath &
CanvasPathDrawingStyles &
Expand Down
8 changes: 1 addition & 7 deletions packages/mui/src/utils/geometry.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { getRect } from "./drawing";
import { Rect } from "@micahg/tbltp-common";

export interface Point {
x: number;
y: number;
}

export interface Rect {
x: number;
y: number;
width: number;
height: number;
}

export interface ImageBound {
left: number;
top: number;
Expand Down

0 comments on commit a64a1b1

Please sign in to comment.