From 4778b73764d568d0005bbfb71b0254d091b9b365 Mon Sep 17 00:00:00 2001 From: Clemens Solar Date: Tue, 16 Jan 2024 20:45:23 +0100 Subject: [PATCH] fix: eslint errors --- src/components/Layout.tsx | 1 - src/components/Layout/ImportFromUrlDialog.tsx | 2 +- src/components/OpenscadWorkerProvider.tsx | 29 +++++++++++++++---- src/lib/openSCAD/execute.ts | 2 +- src/lib/openSCAD/parseParameter.ts | 9 +++--- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index b3cd246..cb54a4c 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -14,7 +14,6 @@ import { Link, Outlet, useNavigate } from 'react-router-dom'; import ImportFromUrlDialog from './Layout/ImportFromUrlDialog'; -const drawerWidth = 340; const toolbarHeight = 64; // TODO Will this work everywhere? type Props = { diff --git a/src/components/Layout/ImportFromUrlDialog.tsx b/src/components/Layout/ImportFromUrlDialog.tsx index 95191c5..e5b384e 100644 --- a/src/components/Layout/ImportFromUrlDialog.tsx +++ b/src/components/Layout/ImportFromUrlDialog.tsx @@ -10,7 +10,7 @@ type Props = { onClose: (url?: string) => void; }; -export default function ImportFromUrlDialog({ onClose }) { +export default function ImportFromUrlDialog({ onClose }: Props) { const [url, setUrl] = useState(''); const handleUrlChange = (event: React.ChangeEvent) => { diff --git a/src/components/OpenscadWorkerProvider.tsx b/src/components/OpenscadWorkerProvider.tsx index 180a821..39b67bd 100644 --- a/src/components/OpenscadWorkerProvider.tsx +++ b/src/components/OpenscadWorkerProvider.tsx @@ -1,20 +1,32 @@ import React, { createContext, useState } from 'react'; import executeOpenSCAD from '../lib/openSCAD/execute'; +import { OpenSCADWorkerInputMessage } from '../types'; // Create a context for the web worker const OpenSCADWorkerContext = createContext<{ - export?: (code: string, fileType: string, params?: any) => void; + export?: ( + code: string, + fileType: string, + params?: OpenSCADWorkerInputMessage['params'] + ) => void; exportFile?: File | null; log?: string[]; - preview?: (code: string, params?: any) => void; + preview?: ( + code: string, + params?: OpenSCADWorkerInputMessage['params'] + ) => void; previewFile?: File | null; }>({ log: [], }); +type Props = { + children: React.ReactNode; +}; + // Create a provider component -export default function OpenscadWorkerProvider({ children }) { +export default function OpenscadWorkerProvider({ children }: Props) { const [log, setLog] = useState([]); const [previewFile, setPreviewFile] = useState(null); const [exportFile, setExportFile] = useState(null); @@ -24,7 +36,11 @@ export default function OpenscadWorkerProvider({ children }) { exportFile, previewFile, - export: async (code: string, fileType: string, params?: any) => { + export: async ( + code: string, + fileType: string, + params?: OpenSCADWorkerInputMessage['params'] + ) => { const output = await executeOpenSCAD('export', code, fileType, params); setLog((prevLog) => [ ...prevLog, @@ -34,7 +50,10 @@ export default function OpenscadWorkerProvider({ children }) { setExportFile(output.output); }, - preview: async (code: string, params?: any) => { + preview: async ( + code: string, + params?: OpenSCADWorkerInputMessage['params'] + ) => { const output = await executeOpenSCAD('preview', code, 'stl', params); setLog((prevLog) => [ diff --git a/src/lib/openSCAD/execute.ts b/src/lib/openSCAD/execute.ts index b698150..b777adb 100644 --- a/src/lib/openSCAD/execute.ts +++ b/src/lib/openSCAD/execute.ts @@ -9,7 +9,7 @@ export default async function executeOpenSCAD( type: 'preview' | 'export', code: string, fileType: string, - params: {} + params: OpenSCADWorkerInputMessage['params'] ): Promise { return new Promise((resolve, reject) => { const worker = new Worker('./openSCADWorker.js', { type: 'module' }); diff --git a/src/lib/openSCAD/parseParameter.ts b/src/lib/openSCAD/parseParameter.ts index 174d05a..294c1b9 100644 --- a/src/lib/openSCAD/parseParameter.ts +++ b/src/lib/openSCAD/parseParameter.ts @@ -1,8 +1,6 @@ -import parser from 'openscad-parser'; - export type Parameter = { name: string; - type: any; + type: 'string' | 'number' | 'boolean'; value: string | boolean | number; description?: string; }; @@ -34,7 +32,10 @@ export default function parseParameters(script: string) { return parameters; } -function convertType(rawValue) { +function convertType(rawValue): { + value: string | boolean | number; + type: 'string' | 'number' | 'boolean'; +} { if (/^\d+(\.\d+)?$/.test(rawValue)) { return { value: parseFloat(rawValue), type: 'number' }; } else if (rawValue === 'true' || rawValue === 'false') {