From 37d3e2eeba2f4eee00be1816664ff18b58243e6a Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:25:29 -0400 Subject: [PATCH 01/29] server/tsconfig, client/tsconfig: add alias to other folder --- client/tsconfig.json | 4 ++++ server/tsconfig.json | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/client/tsconfig.json b/client/tsconfig.json index 9e63548a60..5838c56b02 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -5,6 +5,10 @@ "module": "ESNext", "lib": ["DOM", "ESNext"], "jsx": "react", + "paths": { + "server/*": ["../server/*"], + "common/*": ["../common/*"] + } }, "include": ["./**/*"], "exclude": ["../node_modules", "../server"] diff --git a/server/tsconfig.json b/server/tsconfig.json index 50811e441c..6f3c4eadad 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -4,6 +4,10 @@ "target": "ES2022", "module": "commonjs", "lib": ["ES2022"], + "paths": { + "client/*": ["../client/*"], + "common/*": ["../common/*"] + }, "types": ["node", "jest", "express"], "typeRoots": ["./types", "../node_modules/@types"] }, From affdf056b507283ea87a36f20838f0432b9a681f Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:27:16 -0400 Subject: [PATCH 02/29] common/types: import server types to expose to client --- common/types/index.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 common/types/index.ts diff --git a/common/types/index.ts b/common/types/index.ts new file mode 100644 index 0000000000..850f11703f --- /dev/null +++ b/common/types/index.ts @@ -0,0 +1,33 @@ +// This file declares shared types between the client & server +// Types should be defined in their own portions of the codebase and exported here. + +// SERVER SHARED TYPES: +export { + SanitisedApiKey, + IApiKey as ApiKey, + ApiKeyResponseOrError, + ApiKeyResponse, + CreateApiKeyRequestBody, + RemoveApiKeyRequestParams +} from '../../server/types/apiKey'; + +export * from '../../server/types/email'; + +export { Error, GenericResponseBody } from '../../server/types/express'; + +export { + User, + PublicUser, + PublicUserOrError, + PublicUserOrErrorOrGeneric, + UpdateSettingsRequestBody, + UnlinkThirdPartyResponseBody, + ResetPasswordInitiateRequestBody, + ResetOrUpdatePasswordRequestParams, + UpdatePasswordRequestBody, + CreateUserRequestBody, + DuplicateUserCheckQuery, + VerifyEmailQuery +} from '../../server/types/user'; + +export * from '../../server/types/userPreferences'; From 76c1750bc09a64453630cd14872e166077d5cbef Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:34:32 -0400 Subject: [PATCH 03/29] client/persistState: migrate to ts, no-verify --- client/{persistState.js => persistState.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/{persistState.js => persistState.ts} (100%) diff --git a/client/persistState.js b/client/persistState.ts similarity index 100% rename from client/persistState.js rename to client/persistState.ts From bebb22a0cecfe5322c17c98bbbfc3e5c21bf86c7 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:35:17 -0400 Subject: [PATCH 04/29] client/store: update to ts, no-verify --- client/{store.js => store.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/{store.js => store.ts} (100%) diff --git a/client/store.js b/client/store.ts similarity index 100% rename from client/store.js rename to client/store.ts From b1dd2e8211305f445a8f89a7db771945df02ad94 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:36:28 -0400 Subject: [PATCH 05/29] client/storeInstance: migrate to ts, no-verify --- client/{storeInstance.js => storeInstance.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/{storeInstance.js => storeInstance.ts} (100%) diff --git a/client/storeInstance.js b/client/storeInstance.ts similarity index 100% rename from client/storeInstance.js rename to client/storeInstance.ts From 4a585477cebd270d8042053aec4b61bcc44a52d2 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:39:05 -0400 Subject: [PATCH 06/29] client/reducers: migrate to ts, no-verify --- client/{reducers.js => reducers.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/{reducers.js => reducers.ts} (100%) diff --git a/client/reducers.js b/client/reducers.ts similarity index 100% rename from client/reducers.js rename to client/reducers.ts From f15484fea848bf7fe1f5c5de2d4f13aa8d7decd3 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:41:48 -0400 Subject: [PATCH 07/29] client/reducers: create root reducer type & keep default export --- client/reducers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/reducers.ts b/client/reducers.ts index f61d2585d6..369ce5a36c 100644 --- a/client/reducers.ts +++ b/client/reducers.ts @@ -31,4 +31,8 @@ const rootReducer = combineReducers({ collections }); +// Type for entire redux state +export type RootState = ReturnType; + +// eslint-disable-next-line import/no-default-export export default rootReducer; From d423f8028e581f2afc9c4c55bef74b126a5fdffe Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:44:48 -0400 Subject: [PATCH 08/29] client/store: add RootState type to setupStore --- client/store.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/store.ts b/client/store.ts index e74248f010..bbb873f514 100644 --- a/client/store.ts +++ b/client/store.ts @@ -2,6 +2,7 @@ import { configureStore } from '@reduxjs/toolkit'; import listenerMiddleware from './middleware'; import DevTools from './modules/App/components/DevTools'; import rootReducer from './reducers'; +import type { RootState } from './reducers'; import { clearState, loadState } from './persistState'; import { getConfig } from './utils/getConfig'; @@ -15,7 +16,7 @@ export function showReduxDevTools() { ); } -export default function setupStore(initialState) { +export default function setupStore(initialState: RootState) { const savedState = loadState(); clearState(); From 01e4abe1393cd1fe0102d3989652281c587a6c85 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:47:52 -0400 Subject: [PATCH 09/29] client/testData/testReduxStore: migrate to ts, no-verify --- client/testData/{testReduxStore.js => testReduxStore.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/testData/{testReduxStore.js => testReduxStore.ts} (100%) diff --git a/client/testData/testReduxStore.js b/client/testData/testReduxStore.ts similarity index 100% rename from client/testData/testReduxStore.js rename to client/testData/testReduxStore.ts From e895e529b990fb650e8ebf9a6e20fbf01e0e9e31 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:48:21 -0400 Subject: [PATCH 10/29] client/testData/testReduxStore: add RootState type --- client/testData/testReduxStore.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/testData/testReduxStore.ts b/client/testData/testReduxStore.ts index f9f5d01925..33223ae950 100644 --- a/client/testData/testReduxStore.ts +++ b/client/testData/testReduxStore.ts @@ -1,5 +1,6 @@ import { initialState as initialFilesState } from '../modules/IDE/reducers/files'; import { initialState as initialPrefState } from '../modules/IDE/reducers/preferences'; +import { RootState } from '../reducers'; const mockProjects = [ { @@ -22,7 +23,7 @@ const mockProjects = [ } ]; -const initialTestState = { +const initialTestState: RootState = { ide: { isPlaying: false, isAccessibleOutputPlaying: false, From c20314810cb13e47f5f5bad70520490fd5ec8008 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:51:34 -0400 Subject: [PATCH 11/29] client/store: update to named export --- .storybook/preview.js | 6 +++--- client/index.integration.test.jsx | 4 ++-- client/index.jsx | 4 ++-- client/store.ts | 2 +- client/storeInstance.ts | 2 +- client/test-utils.js | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index 9260b91c98..2f611743f2 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -2,14 +2,14 @@ import React from 'react'; import { Provider } from 'react-redux'; import { MemoryRouter } from 'react-router'; -import configureStore from '../client/store'; +import { setupStore } from '../client/store'; import '../client/i18n-test'; -import '../client/styles/storybook.css' +import '../client/styles/storybook.css'; import { withThemeProvider, themeToolbarItem } from './decorator-theme'; const initialState = window.__INITIAL_STATE__; -const store = configureStore(initialState); +const store = setupStore(initialState); export const decorators = [ (Story) => ( diff --git a/client/index.integration.test.jsx b/client/index.integration.test.jsx index 66819b1536..f27971b7b9 100644 --- a/client/index.integration.test.jsx +++ b/client/index.integration.test.jsx @@ -4,13 +4,13 @@ import React from 'react'; import Routing from './routes'; import { reduxRender, act, waitFor, screen, within } from './test-utils'; -import configureStore from './store'; +import { setupStore } from './store'; import * as Actions from './modules/User/actions'; import { userResponse } from './testData/testServerResponses'; // setup for the app const initialState = window.__INITIAL_STATE__; -const store = configureStore(initialState); +const store = setupStore(initialState); // need to mock this file or it'll throw ERRCONNECTED jest.mock('./i18n'); diff --git a/client/index.jsx b/client/index.jsx index c4c53c1186..4b79e95f12 100644 --- a/client/index.jsx +++ b/client/index.jsx @@ -5,7 +5,7 @@ import { Router } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import browserHistory from './browserHistory'; -import configureStore from './store'; +import { setupStore } from './store'; import Routing from './routes'; import ThemeProvider from './modules/App/components/ThemeProvider'; import Loader from './modules/App/components/loader'; @@ -19,7 +19,7 @@ require('./images/p5js-square-logo.png'); const initialState = window.__INITIAL_STATE__; -const store = configureStore(initialState); +const store = setupStore(initialState); const DONATE_LOGO_IMAGE_URL = 'https://donorbox.org/images/white_logo.svg'; diff --git a/client/store.ts b/client/store.ts index bbb873f514..4ff0e566fd 100644 --- a/client/store.ts +++ b/client/store.ts @@ -16,7 +16,7 @@ export function showReduxDevTools() { ); } -export default function setupStore(initialState: RootState) { +export function setupStore(initialState: RootState) { const savedState = loadState(); clearState(); diff --git a/client/storeInstance.ts b/client/storeInstance.ts index bd92360c2e..3f19a056de 100644 --- a/client/storeInstance.ts +++ b/client/storeInstance.ts @@ -1,4 +1,4 @@ -import setupStore from './store'; +import { setupStore } from './store'; const initialState = window.__INITIAL_STATE__; const store = setupStore(initialState); diff --git a/client/test-utils.js b/client/test-utils.js index 9b7c8aab31..4e0aca0e79 100644 --- a/client/test-utils.js +++ b/client/test-utils.js @@ -23,7 +23,7 @@ import { Context as ResponsiveContext } from 'react-responsive'; import i18n from './i18n-test'; import ThemeProvider from './modules/App/components/ThemeProvider'; -import configureStore from './store'; +import { setupStore } from './store'; import theme, { Theme } from './theme'; export const history = createMemoryHistory(); @@ -95,7 +95,7 @@ Providers.propTypes = { */ function reduxRender( ui, - { initialState, store = configureStore(initialState), ...renderOptions } = {} + { initialState, store = setupStore(initialState), ...renderOptions } = {} ) { function Wrapper({ children }) { return ( From 2c659b653cf3eb499932d5cd8b13c117130dfab2 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:53:58 -0400 Subject: [PATCH 12/29] client/storeInstance: delete unused file, already defined in client/index --- client/storeInstance.ts | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 client/storeInstance.ts diff --git a/client/storeInstance.ts b/client/storeInstance.ts deleted file mode 100644 index 3f19a056de..0000000000 --- a/client/storeInstance.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { setupStore } from './store'; - -const initialState = window.__INITIAL_STATE__; -const store = setupStore(initialState); - -export default store; From 86fddba67590eccbf2031367cf23a7609ec51de6 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 12:57:11 -0400 Subject: [PATCH 13/29] client/persistState: resolve type errors, add RootState type --- client/persistState.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/persistState.ts b/client/persistState.ts index 457dba016b..ceff31435e 100644 --- a/client/persistState.ts +++ b/client/persistState.ts @@ -1,3 +1,4 @@ +import type { RootState } from './reducers'; /* Saves and loads a snapshot of the Redux store state to session storage @@ -5,7 +6,7 @@ const key = 'p5js-editor'; const storage = sessionStorage; -export const saveState = (state) => { +export const saveState = (state: RootState) => { try { storage.setItem(key, JSON.stringify(state)); } catch (error) { @@ -15,7 +16,9 @@ export const saveState = (state) => { export const loadState = () => { try { - return JSON.parse(storage.getItem(key)); + const stored = storage.getItem(key); + if (!stored) return null; // handle null before parsing + return JSON.parse(stored) as RootState; } catch (error) { console.warn('Failed to retrieve initialize state from storage:', error); return null; From f972900b539d78a2995316ac8644aa86dd232791 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:02:54 -0400 Subject: [PATCH 14/29] client/custom.d.ts: extend window and nodemodules for redux --- client/custom.d.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/client/custom.d.ts b/client/custom.d.ts index 216fa99ad4..729f9e03de 100644 --- a/client/custom.d.ts +++ b/client/custom.d.ts @@ -4,5 +4,18 @@ declare module '*.svg' { const ReactComponent: React.FunctionComponent< React.SVGProps & { title?: string } >; + // eslint-disable-next-line import/no-default-export export default ReactComponent; } + +// Extend window for Redux DevTools +interface Window { + __REDUX_DEVTOOLS_EXTENSION__?: () => any; +} + +// Extend NodeModule for hot reloading +interface NodeModule { + hot?: { + accept(path?: string, callback?: () => void): void; + }; +} From 8b33ce6b89aaedb4afcba5943ea83ae32cc96283 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:05:07 -0400 Subject: [PATCH 15/29] client/modules/IDE/reducers/preferences: update to ts, no-verify --- client/modules/IDE/reducers/{preferences.js => preferences.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/modules/IDE/reducers/{preferences.js => preferences.ts} (100%) diff --git a/client/modules/IDE/reducers/preferences.js b/client/modules/IDE/reducers/preferences.ts similarity index 100% rename from client/modules/IDE/reducers/preferences.js rename to client/modules/IDE/reducers/preferences.ts From 8ea432262f320df143250fd93d40e4023e388ea3 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:07:04 -0400 Subject: [PATCH 16/29] client/modules/IDE/reducers/preferences: update to named export, no-verify --- client/modules/IDE/reducers/preferences.ts | 4 +--- client/reducers.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/client/modules/IDE/reducers/preferences.ts b/client/modules/IDE/reducers/preferences.ts index d6323c4fd2..7c89613f16 100644 --- a/client/modules/IDE/reducers/preferences.ts +++ b/client/modules/IDE/reducers/preferences.ts @@ -17,7 +17,7 @@ export const initialState = { autocompleteHinter: false }; -const preferences = (state = initialState, action) => { +export const preferences = (state = initialState, action) => { switch (action.type) { case ActionTypes.OPEN_PREFERENCES: return Object.assign({}, state, { tabIndex: 0 }); @@ -57,5 +57,3 @@ const preferences = (state = initialState, action) => { return state; } }; - -export default preferences; diff --git a/client/reducers.ts b/client/reducers.ts index 369ce5a36c..2c65e555ca 100644 --- a/client/reducers.ts +++ b/client/reducers.ts @@ -1,7 +1,7 @@ import { combineReducers } from 'redux'; import files from './modules/IDE/reducers/files'; import ide from './modules/IDE/reducers/ide'; -import preferences from './modules/IDE/reducers/preferences'; +import { preferences } from './modules/IDE/reducers/preferences'; import project from './modules/IDE/reducers/project'; import editorAccessibility from './modules/IDE/reducers/editorAccessibility'; import user from './modules/User/reducers'; From 79340a5e09fce85c8f7c179757bca26b2827a9f2 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:30:08 -0400 Subject: [PATCH 17/29] client/modules/IDE/reduces/preferences: add types for state and actions --- client/modules/IDE/reducers/preferences.ts | 36 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/client/modules/IDE/reducers/preferences.ts b/client/modules/IDE/reducers/preferences.ts index 7c89613f16..90874d219b 100644 --- a/client/modules/IDE/reducers/preferences.ts +++ b/client/modules/IDE/reducers/preferences.ts @@ -1,7 +1,34 @@ +import { + UserPreferences as Preferences, + AppThemeOptions +} from '../../../../common/types'; import * as ActionTypes from '../../../constants'; import i18n from '../../../i18n'; -export const initialState = { +export interface PreferencesState + extends Omit { + tabIndex: number; +} + +// prettier-ignore +export type PreferencesAction = + | { type: typeof ActionTypes.OPEN_PREFERENCES } + | { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: number } + | { type: typeof ActionTypes.SET_FONT_SIZE; value: Preferences['fontSize'] } + | { type: typeof ActionTypes.SET_AUTOSAVE; value: Preferences['autosave'] } + | { type: typeof ActionTypes.SET_LINEWRAP; value: Preferences['linewrap'] } + | { type: typeof ActionTypes.SET_LINT_WARNING; value: Preferences['lintWarning'] } + | { type: typeof ActionTypes.SET_TEXT_OUTPUT; value: Preferences['textOutput'] } + | { type: typeof ActionTypes.SET_GRID_OUTPUT; value: Preferences['gridOutput'] } + | { type: typeof ActionTypes.SET_PREFERENCES; preferences: PreferencesState } + | { type: typeof ActionTypes.SET_THEME; value: Preferences['theme'] } + | { type: typeof ActionTypes.SET_AUTOREFRESH; value: Preferences['autorefresh'] } + | { type: typeof ActionTypes.SET_LINE_NUMBERS; value: Preferences['lineNumbers'] } + | { type: typeof ActionTypes.SET_LANGUAGE; language: Preferences['language'] } + | { type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; value: Preferences['autocloseBracketsQuotes'] } + | { type: typeof ActionTypes.SET_AUTOCOMPLETE_HINTER; value: Preferences['autocompleteHinter'] }; + +export const initialState: PreferencesState = { tabIndex: 0, fontSize: 18, autosave: true, @@ -10,14 +37,17 @@ export const initialState = { lintWarning: false, textOutput: false, gridOutput: false, - theme: 'light', + theme: AppThemeOptions.LIGHT, autorefresh: false, language: i18n.language, autocloseBracketsQuotes: true, autocompleteHinter: false }; -export const preferences = (state = initialState, action) => { +export const preferences = ( + state: PreferencesState = initialState, + action: PreferencesAction +) => { switch (action.type) { case ActionTypes.OPEN_PREFERENCES: return Object.assign({}, state, { tabIndex: 0 }); From df2c772cfdf0826ccb9fed663075f54c11a93eab Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:31:41 -0400 Subject: [PATCH 18/29] common/index: export type to resolve type error --- common/types/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/types/index.ts b/common/types/index.ts index 850f11703f..b45c30b26e 100644 --- a/common/types/index.ts +++ b/common/types/index.ts @@ -2,7 +2,7 @@ // Types should be defined in their own portions of the codebase and exported here. // SERVER SHARED TYPES: -export { +export type { SanitisedApiKey, IApiKey as ApiKey, ApiKeyResponseOrError, @@ -13,9 +13,9 @@ export { export * from '../../server/types/email'; -export { Error, GenericResponseBody } from '../../server/types/express'; +export type { Error, GenericResponseBody } from '../../server/types/express'; -export { +export type { User, PublicUser, PublicUserOrError, From a1d3ba4f5149bba82fb83247d257004f2f370916 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:36:28 -0400 Subject: [PATCH 19/29] client/tsconfig & server/tsconfig: remove custom paths, doesnt work --- client/tsconfig.json | 4 ---- server/tsconfig.json | 4 ---- 2 files changed, 8 deletions(-) diff --git a/client/tsconfig.json b/client/tsconfig.json index 5838c56b02..9e63548a60 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -5,10 +5,6 @@ "module": "ESNext", "lib": ["DOM", "ESNext"], "jsx": "react", - "paths": { - "server/*": ["../server/*"], - "common/*": ["../common/*"] - } }, "include": ["./**/*"], "exclude": ["../node_modules", "../server"] diff --git a/server/tsconfig.json b/server/tsconfig.json index 6f3c4eadad..50811e441c 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -4,10 +4,6 @@ "target": "ES2022", "module": "commonjs", "lib": ["ES2022"], - "paths": { - "client/*": ["../client/*"], - "common/*": ["../common/*"] - }, "types": ["node", "jest", "express"], "typeRoots": ["./types", "../node_modules/@types"] }, From 80484ea35938d33bb6c0e159d12c310a63ac236b Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:38:55 -0400 Subject: [PATCH 20/29] client/modules/IDE/actions/preferences: migrate to ts, no-verify --- client/modules/IDE/actions/{preferences.js => preferences.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/modules/IDE/actions/{preferences.js => preferences.ts} (100%) diff --git a/client/modules/IDE/actions/preferences.js b/client/modules/IDE/actions/preferences.ts similarity index 100% rename from client/modules/IDE/actions/preferences.js rename to client/modules/IDE/actions/preferences.ts From 18751e3ce7bcad03f5d93e8268691f0c004b0351 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:48:43 -0400 Subject: [PATCH 21/29] client/modules/IDE/actions/preferences: define types for dispatcher, formParams, getState, and setter params --- client/modules/IDE/actions/preferences.ts | 53 ++++++++++++---------- client/modules/IDE/reducers/preferences.ts | 2 +- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index f6e71504ee..ea237a5413 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -1,8 +1,21 @@ import i18next from 'i18next'; +import { + UserPreferences as Preferences, + AppThemeOptions, + UpdatePreferencesRequestBody +} from '../../../../common/types'; import { apiClient } from '../../../utils/apiClient'; import * as ActionTypes from '../../../constants'; +import { PreferencesState } from '../reducers/preferences'; +import { RootState } from '../../../reducers'; -function updatePreferences(formParams, dispatch) { +export type UpdatePreferencesDispatch = (action: unknown) => void; +export type GetRootState = () => RootState; + +function updatePreferences( + formParams: UpdatePreferencesRequestBody, + dispatch: UpdatePreferencesDispatch +) { apiClient .put('/preferences', formParams) .then(() => {}) @@ -14,15 +27,15 @@ function updatePreferences(formParams, dispatch) { }); } -export function setPreferencesTab(value) { +export function setPreferencesTab(value: PreferencesState['tabIndex']) { return { type: ActionTypes.SET_PREFERENCES_TAB, value }; } -export function setFontSize(value) { - return (dispatch, getState) => { +export function setFontSize(value: PreferencesState['fontSize']) { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { // eslint-disable-line dispatch({ type: ActionTypes.SET_FONT_SIZE, @@ -41,7 +54,7 @@ export function setFontSize(value) { } export function setLineNumbers(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_LINE_NUMBERS, value @@ -59,7 +72,7 @@ export function setLineNumbers(value) { } export function setAutocloseBracketsQuotes(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES, value @@ -77,7 +90,7 @@ export function setAutocloseBracketsQuotes(value) { } export function setAutocompleteHinter(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOCOMPLETE_HINTER, value @@ -95,7 +108,7 @@ export function setAutocompleteHinter(value) { } export function setAutosave(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOSAVE, value @@ -113,7 +126,7 @@ export function setAutosave(value) { } export function setLinewrap(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_LINEWRAP, value @@ -131,7 +144,7 @@ export function setLinewrap(value) { } export function setLintWarning(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_LINT_WARNING, value @@ -149,7 +162,7 @@ export function setLintWarning(value) { } export function setTextOutput(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_TEXT_OUTPUT, value @@ -167,7 +180,7 @@ export function setTextOutput(value) { } export function setGridOutput(value) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_GRID_OUTPUT, value @@ -185,11 +198,7 @@ export function setGridOutput(value) { } export function setTheme(value) { - // return { - // type: ActionTypes.SET_THEME, - // value - // }; - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_THEME, value @@ -207,11 +216,7 @@ export function setTheme(value) { } export function setAutorefresh(value) { - // return { - // type: ActionTypes.SET_AUTOREFRESH, - // value - // }; - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOREFRESH, value @@ -229,14 +234,14 @@ export function setAutorefresh(value) { } export function setAllAccessibleOutput(value) { - return (dispatch) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch(setTextOutput(value)); dispatch(setGridOutput(value)); }; } export function setLanguage(value, { persistPreference = true } = {}) { - return (dispatch, getState) => { + return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { i18next.changeLanguage(value); dispatch({ type: ActionTypes.SET_LANGUAGE, diff --git a/client/modules/IDE/reducers/preferences.ts b/client/modules/IDE/reducers/preferences.ts index 90874d219b..40a1a48d87 100644 --- a/client/modules/IDE/reducers/preferences.ts +++ b/client/modules/IDE/reducers/preferences.ts @@ -13,7 +13,7 @@ export interface PreferencesState // prettier-ignore export type PreferencesAction = | { type: typeof ActionTypes.OPEN_PREFERENCES } - | { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: number } + | { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: PreferencesState['tabIndex'] } | { type: typeof ActionTypes.SET_FONT_SIZE; value: Preferences['fontSize'] } | { type: typeof ActionTypes.SET_AUTOSAVE; value: Preferences['autosave'] } | { type: typeof ActionTypes.SET_LINEWRAP; value: Preferences['linewrap'] } From 867ef829b3cde1e71b8b5fcddad552ae91c18799 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 13:49:56 -0400 Subject: [PATCH 22/29] --amend --- client/modules/IDE/reducers/preferences.ts | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/client/modules/IDE/reducers/preferences.ts b/client/modules/IDE/reducers/preferences.ts index 40a1a48d87..10d2c9799d 100644 --- a/client/modules/IDE/reducers/preferences.ts +++ b/client/modules/IDE/reducers/preferences.ts @@ -14,19 +14,19 @@ export interface PreferencesState export type PreferencesAction = | { type: typeof ActionTypes.OPEN_PREFERENCES } | { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: PreferencesState['tabIndex'] } - | { type: typeof ActionTypes.SET_FONT_SIZE; value: Preferences['fontSize'] } - | { type: typeof ActionTypes.SET_AUTOSAVE; value: Preferences['autosave'] } - | { type: typeof ActionTypes.SET_LINEWRAP; value: Preferences['linewrap'] } - | { type: typeof ActionTypes.SET_LINT_WARNING; value: Preferences['lintWarning'] } - | { type: typeof ActionTypes.SET_TEXT_OUTPUT; value: Preferences['textOutput'] } - | { type: typeof ActionTypes.SET_GRID_OUTPUT; value: Preferences['gridOutput'] } + | { type: typeof ActionTypes.SET_FONT_SIZE; value: PreferencesState['fontSize'] } + | { type: typeof ActionTypes.SET_AUTOSAVE; value: PreferencesState['autosave'] } + | { type: typeof ActionTypes.SET_LINEWRAP; value: PreferencesState['linewrap'] } + | { type: typeof ActionTypes.SET_LINT_WARNING; value: PreferencesState['lintWarning'] } + | { type: typeof ActionTypes.SET_TEXT_OUTPUT; value: PreferencesState['textOutput'] } + | { type: typeof ActionTypes.SET_GRID_OUTPUT; value: PreferencesState['gridOutput'] } | { type: typeof ActionTypes.SET_PREFERENCES; preferences: PreferencesState } - | { type: typeof ActionTypes.SET_THEME; value: Preferences['theme'] } - | { type: typeof ActionTypes.SET_AUTOREFRESH; value: Preferences['autorefresh'] } - | { type: typeof ActionTypes.SET_LINE_NUMBERS; value: Preferences['lineNumbers'] } - | { type: typeof ActionTypes.SET_LANGUAGE; language: Preferences['language'] } - | { type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; value: Preferences['autocloseBracketsQuotes'] } - | { type: typeof ActionTypes.SET_AUTOCOMPLETE_HINTER; value: Preferences['autocompleteHinter'] }; + | { type: typeof ActionTypes.SET_THEME; value: PreferencesState['theme'] } + | { type: typeof ActionTypes.SET_AUTOREFRESH; value: PreferencesState['autorefresh'] } + | { type: typeof ActionTypes.SET_LINE_NUMBERS; value: PreferencesState['lineNumbers'] } + | { type: typeof ActionTypes.SET_LANGUAGE; language: PreferencesState['language'] } + | { type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; value: PreferencesState['autocloseBracketsQuotes'] } + | { type: typeof ActionTypes.SET_AUTOCOMPLETE_HINTER; value: PreferencesState['autocompleteHinter'] }; export const initialState: PreferencesState = { tabIndex: 0, From 3b5856f68eeb56e961e863c3b4714bbd4581d3c1 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 14:02:01 -0400 Subject: [PATCH 23/29] --amend --- client/modules/IDE/actions/preferences.ts | 47 +++++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index ea237a5413..17e1b01473 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -1,13 +1,9 @@ import i18next from 'i18next'; -import { - UserPreferences as Preferences, - AppThemeOptions, - UpdatePreferencesRequestBody -} from '../../../../common/types'; +import { UpdatePreferencesRequestBody } from '../../../../common/types'; import { apiClient } from '../../../utils/apiClient'; import * as ActionTypes from '../../../constants'; -import { PreferencesState } from '../reducers/preferences'; -import { RootState } from '../../../reducers'; +import type { PreferencesState } from '../reducers/preferences'; +import type { RootState } from '../../../reducers'; export type UpdatePreferencesDispatch = (action: unknown) => void; export type GetRootState = () => RootState; @@ -27,14 +23,24 @@ function updatePreferences( }); } -export function setPreferencesTab(value: PreferencesState['tabIndex']) { +type SetPreferencesTabValue = PreferencesState['tabIndex']; +export type SetPreferencesTabAction = { + type: typeof ActionTypes.SET_PREFERENCES_TAB; + value: SetPreferencesTabValue; +}; +export function setPreferencesTab(value: SetPreferencesTabValue) { return { type: ActionTypes.SET_PREFERENCES_TAB, value }; } -export function setFontSize(value: PreferencesState['fontSize']) { +type SetFontSizeValue = PreferencesState['fontSize']; +export type SetFontSizeAction = { + type: typeof ActionTypes.SET_FONT_SIZE; + value: SetFontSizeAction; +}; +export function setFontSize(value: SetFontSizeValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { // eslint-disable-line dispatch({ @@ -53,7 +59,12 @@ export function setFontSize(value: PreferencesState['fontSize']) { }; } -export function setLineNumbers(value) { +type SetLineNumbersValue = PreferencesState['lineNumbers']; +export type SetLineNumbersAction = { + type: typeof ActionTypes.SET_LINE_NUMBERS; + value: SetLineNumbersValue; +}; +export function setLineNumbers(value: SetLineNumbersValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_LINE_NUMBERS, @@ -71,7 +82,14 @@ export function setLineNumbers(value) { }; } -export function setAutocloseBracketsQuotes(value) { +type SetAutocloseBracketsQuotesValue = PreferencesState['autocloseBracketsQuotes']; +export type SetAutocloseBracketsQuotesAction = { + type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; + value: SetAutocloseBracketsQuotesValue; +}; +export function setAutocloseBracketsQuotes( + value: SetAutocloseBracketsQuotesValue +) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES, @@ -89,7 +107,12 @@ export function setAutocloseBracketsQuotes(value) { }; } -export function setAutocompleteHinter(value) { +type SetAutocompleteHinterValue = PreferencesState['autocompleteHinter']; +export type SetAutocompleteHinterValueAction = { + type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; + value: SetAutocompleteHinterValue; +}; +export function setAutocompleteHinter(value: SetAutocompleteHinterValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOCOMPLETE_HINTER, From 879c357f88450957212c187673ec89f726b19975 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 14:08:09 -0400 Subject: [PATCH 24/29] --amend --- client/modules/IDE/actions/preferences.ts | 31 +++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index 17e1b01473..8e0f1f331e 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -23,7 +23,7 @@ function updatePreferences( }); } -type SetPreferencesTabValue = PreferencesState['tabIndex']; +export type SetPreferencesTabValue = PreferencesState['tabIndex']; export type SetPreferencesTabAction = { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: SetPreferencesTabValue; @@ -35,7 +35,7 @@ export function setPreferencesTab(value: SetPreferencesTabValue) { }; } -type SetFontSizeValue = PreferencesState['fontSize']; +export type SetFontSizeValue = PreferencesState['fontSize']; export type SetFontSizeAction = { type: typeof ActionTypes.SET_FONT_SIZE; value: SetFontSizeAction; @@ -59,7 +59,7 @@ export function setFontSize(value: SetFontSizeValue) { }; } -type SetLineNumbersValue = PreferencesState['lineNumbers']; +export type SetLineNumbersValue = PreferencesState['lineNumbers']; export type SetLineNumbersAction = { type: typeof ActionTypes.SET_LINE_NUMBERS; value: SetLineNumbersValue; @@ -82,7 +82,7 @@ export function setLineNumbers(value: SetLineNumbersValue) { }; } -type SetAutocloseBracketsQuotesValue = PreferencesState['autocloseBracketsQuotes']; +export type SetAutocloseBracketsQuotesValue = PreferencesState['autocloseBracketsQuotes']; export type SetAutocloseBracketsQuotesAction = { type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; value: SetAutocloseBracketsQuotesValue; @@ -107,7 +107,7 @@ export function setAutocloseBracketsQuotes( }; } -type SetAutocompleteHinterValue = PreferencesState['autocompleteHinter']; +export type SetAutocompleteHinterValue = PreferencesState['autocompleteHinter']; export type SetAutocompleteHinterValueAction = { type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; value: SetAutocompleteHinterValue; @@ -130,7 +130,12 @@ export function setAutocompleteHinter(value: SetAutocompleteHinterValue) { }; } -export function setAutosave(value) { +export type SetAutosaveValue = PreferencesState['autosave']; +export type SetAutosaveAction = { + type: typeof ActionTypes.SET_AUTOSAVE; + value: SetAutosaveValue; +}; +export function setAutosave(value: SetAutosaveValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOSAVE, @@ -148,7 +153,12 @@ export function setAutosave(value) { }; } -export function setLinewrap(value) { +export type SetLinewrapValue = PreferencesState['linewrap']; +export type SetLinewrapAction = { + type: typeof ActionTypes.SET_LINEWRAP; + value: SetLinewrapValue; +}; +export function setLinewrap(value: SetLinewrapValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_LINEWRAP, @@ -166,7 +176,12 @@ export function setLinewrap(value) { }; } -export function setLintWarning(value) { +export type SetLintWarningValue = PreferencesState['lintWarning']; +export type SetLintWarningAction = { + type: typeof ActionTypes.SET_LINT_WARNING; + value: SetLintWarningValue; +}; +export function setLintWarning(value: SetLintWarningValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_LINT_WARNING, From e27761a9ff152d7843b4d9b61fac634894fa3716 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 14:12:09 -0400 Subject: [PATCH 25/29] --amend --- client/modules/IDE/actions/preferences.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index 8e0f1f331e..5dd05abfc7 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -5,6 +5,8 @@ import * as ActionTypes from '../../../constants'; import type { PreferencesState } from '../reducers/preferences'; import type { RootState } from '../../../reducers'; +// Action definitions: + export type UpdatePreferencesDispatch = (action: unknown) => void; export type GetRootState = () => RootState; @@ -199,7 +201,12 @@ export function setLintWarning(value: SetLintWarningValue) { }; } -export function setTextOutput(value) { +export type SetTextOutputValue = PreferencesState['textOutput']; +export type SetTextOutputAction = { + type: typeof ActionTypes.SET_TEXT_OUTPUT; + value: SetTextOutputValue; +}; +export function setTextOutput(value: SetTextOutputValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_TEXT_OUTPUT, @@ -217,7 +224,12 @@ export function setTextOutput(value) { }; } -export function setGridOutput(value) { +export type SetGridOutputValue = PreferencesState['gridOutput']; +export type SetGridOutputAction = { + type: typeof ActionTypes.SET_GRID_OUTPUT; + value: SetGridOutputValue; +}; +export function setGridOutput(value: SetGridOutputValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_GRID_OUTPUT, From da9d8fdaf5c4e1715a214f85515dfc065a72bb1d Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 14:18:28 -0400 Subject: [PATCH 26/29] --amend --- client/modules/IDE/actions/preferences.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index 5dd05abfc7..092bb71401 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -247,7 +247,12 @@ export function setGridOutput(value: SetGridOutputValue) { }; } -export function setTheme(value) { +export type SetThemeValue = PreferencesState['theme']; +export type SetThemeAction = { + type: typeof ActionTypes.SET_THEME; + preferences: SetThemeValue; +}; +export function setTheme(value: SetThemeValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_THEME, From 3feeaf0686e3fb83fbceb5999f8a25b8d2b8a494 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 14:23:25 -0400 Subject: [PATCH 27/29] --amend --- client/modules/IDE/actions/preferences.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index 092bb71401..6e0592044e 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -270,7 +270,12 @@ export function setTheme(value: SetThemeValue) { }; } -export function setAutorefresh(value) { +export type SetAutorefreshValue = PreferencesState['autorefresh']; +export type SetAutorefreshAction = { + type: typeof ActionTypes.SET_AUTOREFRESH; + value: SetAutorefreshValue; +}; +export function setAutorefresh(value: SetAutorefreshValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ type: ActionTypes.SET_AUTOREFRESH, @@ -288,14 +293,25 @@ export function setAutorefresh(value) { }; } -export function setAllAccessibleOutput(value) { +export type SetAllAccessibleOutputValue = + | SetTextOutputValue + | SetGridOutputValue; +export function setAllAccessibleOutput(value: SetAllAccessibleOutputValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch(setTextOutput(value)); dispatch(setGridOutput(value)); }; } -export function setLanguage(value, { persistPreference = true } = {}) { +export type SetLanguageValue = PreferencesState['language']; +export type SetLanguageAction = { + type: typeof ActionTypes.SET_AUTOREFRESH; + value: SetLanguageValue; +}; +export function setLanguage( + value: SetLanguageValue, + { persistPreference = true } = {} +) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { i18next.changeLanguage(value); dispatch({ From 24f63d542c7649366526008a8f6a808b32107c3f Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 14:45:53 -0400 Subject: [PATCH 28/29] reorganise preferences action type defs --- client/modules/IDE/actions/preferences.ts | 180 +++++++++++++-------- client/modules/IDE/reducers/preferences.ts | 19 +-- 2 files changed, 111 insertions(+), 88 deletions(-) diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index 6e0592044e..6f5f57af5e 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -5,9 +5,117 @@ import * as ActionTypes from '../../../constants'; import type { PreferencesState } from '../reducers/preferences'; import type { RootState } from '../../../reducers'; -// Action definitions: +// Value Definitions: +export type SetPreferencesTabValue = PreferencesState['tabIndex']; +export type SetFontSizeValue = PreferencesState['fontSize']; +export type SetLineNumbersValue = PreferencesState['lineNumbers']; +export type SetAutocloseBracketsQuotesValue = PreferencesState['autocloseBracketsQuotes']; +export type SetAutocompleteHinterValue = PreferencesState['autocompleteHinter']; +export type SetAutosaveValue = PreferencesState['autosave']; +export type SetLinewrapValue = PreferencesState['linewrap']; +export type SetLintWarningValue = PreferencesState['lintWarning']; +export type SetTextOutputValue = PreferencesState['textOutput']; +export type SetGridOutputValue = PreferencesState['gridOutput']; +export type SetThemeValue = PreferencesState['theme']; +export type SetAutorefreshValue = PreferencesState['autorefresh']; +export type SetLanguageValue = PreferencesState['language']; +export type SetAllAccessibleOutputValue = + | SetTextOutputValue + | SetGridOutputValue; + +// Action Definitions: +export type OpenPreferencesAction = { + type: typeof ActionTypes.OPEN_PREFERENCES; +}; +export type SetPreferencesAction = { + type: typeof ActionTypes.SET_PREFERENCES; + preferences: PreferencesState; +}; +export type SetErrorAction = { + type: typeof ActionTypes.ERROR; + error: unknown; +}; + +export type SetPreferencesTabAction = { + type: typeof ActionTypes.SET_PREFERENCES_TAB; + value: SetPreferencesTabValue; +}; +export type SetFontSizeAction = { + type: typeof ActionTypes.SET_FONT_SIZE; + value: SetFontSizeValue; +}; +export type SetLineNumbersAction = { + type: typeof ActionTypes.SET_LINE_NUMBERS; + value: SetLineNumbersValue; +}; +export type SetAutocloseBracketsQuotesAction = { + type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; + value: SetAutocloseBracketsQuotesValue; +}; +export type SetAutocompleteHinterAction = { + type: typeof ActionTypes.SET_AUTOCOMPLETE_HINTER; + value: SetAutocompleteHinterValue; +}; +export type SetAutosaveAction = { + type: typeof ActionTypes.SET_AUTOSAVE; + value: SetAutosaveValue; +}; +export type SetLinewrapAction = { + type: typeof ActionTypes.SET_LINEWRAP; + value: SetLinewrapValue; +}; +export type SetLintWarningAction = { + type: typeof ActionTypes.SET_LINT_WARNING; + value: SetLintWarningValue; +}; +export type SetTextOutputAction = { + type: typeof ActionTypes.SET_TEXT_OUTPUT; + value: SetTextOutputValue; +}; +export type SetGridOutputAction = { + type: typeof ActionTypes.SET_GRID_OUTPUT; + value: SetGridOutputValue; +}; +export type SetThemeAction = { + type: typeof ActionTypes.SET_THEME; + value: SetThemeValue; +}; +export type SetAutorefreshAction = { + type: typeof ActionTypes.SET_AUTOREFRESH; + value: SetAutorefreshValue; +}; +export type SetLanguageAction = { + type: typeof ActionTypes.SET_LANGUAGE; + language: SetLanguageValue; +}; + +export type PreferencesAction = + | OpenPreferencesAction + | SetPreferencesAction + | SetErrorAction + | SetPreferencesTabAction + | SetFontSizeAction + | SetLineNumbersAction + | SetAutocloseBracketsQuotesAction + | SetAutocompleteHinterAction + | SetAutosaveAction + | SetLinewrapAction + | SetLintWarningAction + | SetTextOutputAction + | SetGridOutputAction + | SetThemeAction + | SetAutorefreshAction + | SetLanguageAction; + +export type UpdatePreferencesDispatch = ( + action: PreferencesAction | PreferencesThunk +) => void; + +export type PreferencesThunk = ( + dispatch: UpdatePreferencesDispatch, + getState: GetRootState +) => void; -export type UpdatePreferencesDispatch = (action: unknown) => void; export type GetRootState = () => RootState; function updatePreferences( @@ -25,11 +133,6 @@ function updatePreferences( }); } -export type SetPreferencesTabValue = PreferencesState['tabIndex']; -export type SetPreferencesTabAction = { - type: typeof ActionTypes.SET_PREFERENCES_TAB; - value: SetPreferencesTabValue; -}; export function setPreferencesTab(value: SetPreferencesTabValue) { return { type: ActionTypes.SET_PREFERENCES_TAB, @@ -37,11 +140,6 @@ export function setPreferencesTab(value: SetPreferencesTabValue) { }; } -export type SetFontSizeValue = PreferencesState['fontSize']; -export type SetFontSizeAction = { - type: typeof ActionTypes.SET_FONT_SIZE; - value: SetFontSizeAction; -}; export function setFontSize(value: SetFontSizeValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { // eslint-disable-line @@ -61,11 +159,6 @@ export function setFontSize(value: SetFontSizeValue) { }; } -export type SetLineNumbersValue = PreferencesState['lineNumbers']; -export type SetLineNumbersAction = { - type: typeof ActionTypes.SET_LINE_NUMBERS; - value: SetLineNumbersValue; -}; export function setLineNumbers(value: SetLineNumbersValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -84,11 +177,6 @@ export function setLineNumbers(value: SetLineNumbersValue) { }; } -export type SetAutocloseBracketsQuotesValue = PreferencesState['autocloseBracketsQuotes']; -export type SetAutocloseBracketsQuotesAction = { - type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; - value: SetAutocloseBracketsQuotesValue; -}; export function setAutocloseBracketsQuotes( value: SetAutocloseBracketsQuotesValue ) { @@ -109,11 +197,6 @@ export function setAutocloseBracketsQuotes( }; } -export type SetAutocompleteHinterValue = PreferencesState['autocompleteHinter']; -export type SetAutocompleteHinterValueAction = { - type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; - value: SetAutocompleteHinterValue; -}; export function setAutocompleteHinter(value: SetAutocompleteHinterValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -132,11 +215,6 @@ export function setAutocompleteHinter(value: SetAutocompleteHinterValue) { }; } -export type SetAutosaveValue = PreferencesState['autosave']; -export type SetAutosaveAction = { - type: typeof ActionTypes.SET_AUTOSAVE; - value: SetAutosaveValue; -}; export function setAutosave(value: SetAutosaveValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -155,11 +233,6 @@ export function setAutosave(value: SetAutosaveValue) { }; } -export type SetLinewrapValue = PreferencesState['linewrap']; -export type SetLinewrapAction = { - type: typeof ActionTypes.SET_LINEWRAP; - value: SetLinewrapValue; -}; export function setLinewrap(value: SetLinewrapValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -178,11 +251,6 @@ export function setLinewrap(value: SetLinewrapValue) { }; } -export type SetLintWarningValue = PreferencesState['lintWarning']; -export type SetLintWarningAction = { - type: typeof ActionTypes.SET_LINT_WARNING; - value: SetLintWarningValue; -}; export function setLintWarning(value: SetLintWarningValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -201,11 +269,6 @@ export function setLintWarning(value: SetLintWarningValue) { }; } -export type SetTextOutputValue = PreferencesState['textOutput']; -export type SetTextOutputAction = { - type: typeof ActionTypes.SET_TEXT_OUTPUT; - value: SetTextOutputValue; -}; export function setTextOutput(value: SetTextOutputValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -224,11 +287,6 @@ export function setTextOutput(value: SetTextOutputValue) { }; } -export type SetGridOutputValue = PreferencesState['gridOutput']; -export type SetGridOutputAction = { - type: typeof ActionTypes.SET_GRID_OUTPUT; - value: SetGridOutputValue; -}; export function setGridOutput(value: SetGridOutputValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -247,11 +305,6 @@ export function setGridOutput(value: SetGridOutputValue) { }; } -export type SetThemeValue = PreferencesState['theme']; -export type SetThemeAction = { - type: typeof ActionTypes.SET_THEME; - preferences: SetThemeValue; -}; export function setTheme(value: SetThemeValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -270,11 +323,6 @@ export function setTheme(value: SetThemeValue) { }; } -export type SetAutorefreshValue = PreferencesState['autorefresh']; -export type SetAutorefreshAction = { - type: typeof ActionTypes.SET_AUTOREFRESH; - value: SetAutorefreshValue; -}; export function setAutorefresh(value: SetAutorefreshValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch({ @@ -293,9 +341,6 @@ export function setAutorefresh(value: SetAutorefreshValue) { }; } -export type SetAllAccessibleOutputValue = - | SetTextOutputValue - | SetGridOutputValue; export function setAllAccessibleOutput(value: SetAllAccessibleOutputValue) { return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => { dispatch(setTextOutput(value)); @@ -303,11 +348,6 @@ export function setAllAccessibleOutput(value: SetAllAccessibleOutputValue) { }; } -export type SetLanguageValue = PreferencesState['language']; -export type SetLanguageAction = { - type: typeof ActionTypes.SET_AUTOREFRESH; - value: SetLanguageValue; -}; export function setLanguage( value: SetLanguageValue, { persistPreference = true } = {} diff --git a/client/modules/IDE/reducers/preferences.ts b/client/modules/IDE/reducers/preferences.ts index 10d2c9799d..26ded02862 100644 --- a/client/modules/IDE/reducers/preferences.ts +++ b/client/modules/IDE/reducers/preferences.ts @@ -4,30 +4,13 @@ import { } from '../../../../common/types'; import * as ActionTypes from '../../../constants'; import i18n from '../../../i18n'; +import type { PreferencesAction } from '../actions/preferences'; export interface PreferencesState extends Omit { tabIndex: number; } -// prettier-ignore -export type PreferencesAction = - | { type: typeof ActionTypes.OPEN_PREFERENCES } - | { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: PreferencesState['tabIndex'] } - | { type: typeof ActionTypes.SET_FONT_SIZE; value: PreferencesState['fontSize'] } - | { type: typeof ActionTypes.SET_AUTOSAVE; value: PreferencesState['autosave'] } - | { type: typeof ActionTypes.SET_LINEWRAP; value: PreferencesState['linewrap'] } - | { type: typeof ActionTypes.SET_LINT_WARNING; value: PreferencesState['lintWarning'] } - | { type: typeof ActionTypes.SET_TEXT_OUTPUT; value: PreferencesState['textOutput'] } - | { type: typeof ActionTypes.SET_GRID_OUTPUT; value: PreferencesState['gridOutput'] } - | { type: typeof ActionTypes.SET_PREFERENCES; preferences: PreferencesState } - | { type: typeof ActionTypes.SET_THEME; value: PreferencesState['theme'] } - | { type: typeof ActionTypes.SET_AUTOREFRESH; value: PreferencesState['autorefresh'] } - | { type: typeof ActionTypes.SET_LINE_NUMBERS; value: PreferencesState['lineNumbers'] } - | { type: typeof ActionTypes.SET_LANGUAGE; language: PreferencesState['language'] } - | { type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; value: PreferencesState['autocloseBracketsQuotes'] } - | { type: typeof ActionTypes.SET_AUTOCOMPLETE_HINTER; value: PreferencesState['autocompleteHinter'] }; - export const initialState: PreferencesState = { tabIndex: 0, fontSize: 18, From 0896481296fc0a50176cc05550b221810fbdf703 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 10 Oct 2025 15:07:31 -0400 Subject: [PATCH 29/29] migrate preferences action types to co-located .types file --- client/modules/IDE/actions/preferences.ts | 133 +++--------------- .../modules/IDE/actions/preferences.types.ts | 116 +++++++++++++++ client/modules/IDE/reducers/preferences.ts | 2 +- 3 files changed, 135 insertions(+), 116 deletions(-) create mode 100644 client/modules/IDE/actions/preferences.types.ts diff --git a/client/modules/IDE/actions/preferences.ts b/client/modules/IDE/actions/preferences.ts index 6f5f57af5e..ccb5ef6a63 100644 --- a/client/modules/IDE/actions/preferences.ts +++ b/client/modules/IDE/actions/preferences.ts @@ -2,121 +2,24 @@ import i18next from 'i18next'; import { UpdatePreferencesRequestBody } from '../../../../common/types'; import { apiClient } from '../../../utils/apiClient'; import * as ActionTypes from '../../../constants'; -import type { PreferencesState } from '../reducers/preferences'; -import type { RootState } from '../../../reducers'; - -// Value Definitions: -export type SetPreferencesTabValue = PreferencesState['tabIndex']; -export type SetFontSizeValue = PreferencesState['fontSize']; -export type SetLineNumbersValue = PreferencesState['lineNumbers']; -export type SetAutocloseBracketsQuotesValue = PreferencesState['autocloseBracketsQuotes']; -export type SetAutocompleteHinterValue = PreferencesState['autocompleteHinter']; -export type SetAutosaveValue = PreferencesState['autosave']; -export type SetLinewrapValue = PreferencesState['linewrap']; -export type SetLintWarningValue = PreferencesState['lintWarning']; -export type SetTextOutputValue = PreferencesState['textOutput']; -export type SetGridOutputValue = PreferencesState['gridOutput']; -export type SetThemeValue = PreferencesState['theme']; -export type SetAutorefreshValue = PreferencesState['autorefresh']; -export type SetLanguageValue = PreferencesState['language']; -export type SetAllAccessibleOutputValue = - | SetTextOutputValue - | SetGridOutputValue; - -// Action Definitions: -export type OpenPreferencesAction = { - type: typeof ActionTypes.OPEN_PREFERENCES; -}; -export type SetPreferencesAction = { - type: typeof ActionTypes.SET_PREFERENCES; - preferences: PreferencesState; -}; -export type SetErrorAction = { - type: typeof ActionTypes.ERROR; - error: unknown; -}; - -export type SetPreferencesTabAction = { - type: typeof ActionTypes.SET_PREFERENCES_TAB; - value: SetPreferencesTabValue; -}; -export type SetFontSizeAction = { - type: typeof ActionTypes.SET_FONT_SIZE; - value: SetFontSizeValue; -}; -export type SetLineNumbersAction = { - type: typeof ActionTypes.SET_LINE_NUMBERS; - value: SetLineNumbersValue; -}; -export type SetAutocloseBracketsQuotesAction = { - type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; - value: SetAutocloseBracketsQuotesValue; -}; -export type SetAutocompleteHinterAction = { - type: typeof ActionTypes.SET_AUTOCOMPLETE_HINTER; - value: SetAutocompleteHinterValue; -}; -export type SetAutosaveAction = { - type: typeof ActionTypes.SET_AUTOSAVE; - value: SetAutosaveValue; -}; -export type SetLinewrapAction = { - type: typeof ActionTypes.SET_LINEWRAP; - value: SetLinewrapValue; -}; -export type SetLintWarningAction = { - type: typeof ActionTypes.SET_LINT_WARNING; - value: SetLintWarningValue; -}; -export type SetTextOutputAction = { - type: typeof ActionTypes.SET_TEXT_OUTPUT; - value: SetTextOutputValue; -}; -export type SetGridOutputAction = { - type: typeof ActionTypes.SET_GRID_OUTPUT; - value: SetGridOutputValue; -}; -export type SetThemeAction = { - type: typeof ActionTypes.SET_THEME; - value: SetThemeValue; -}; -export type SetAutorefreshAction = { - type: typeof ActionTypes.SET_AUTOREFRESH; - value: SetAutorefreshValue; -}; -export type SetLanguageAction = { - type: typeof ActionTypes.SET_LANGUAGE; - language: SetLanguageValue; -}; - -export type PreferencesAction = - | OpenPreferencesAction - | SetPreferencesAction - | SetErrorAction - | SetPreferencesTabAction - | SetFontSizeAction - | SetLineNumbersAction - | SetAutocloseBracketsQuotesAction - | SetAutocompleteHinterAction - | SetAutosaveAction - | SetLinewrapAction - | SetLintWarningAction - | SetTextOutputAction - | SetGridOutputAction - | SetThemeAction - | SetAutorefreshAction - | SetLanguageAction; - -export type UpdatePreferencesDispatch = ( - action: PreferencesAction | PreferencesThunk -) => void; - -export type PreferencesThunk = ( - dispatch: UpdatePreferencesDispatch, - getState: GetRootState -) => void; - -export type GetRootState = () => RootState; +import type { + UpdatePreferencesDispatch, + SetPreferencesTabValue, + SetFontSizeValue, + GetRootState, + SetLineNumbersValue, + SetAutocloseBracketsQuotesValue, + SetAutocompleteHinterValue, + SetAutosaveValue, + SetLinewrapValue, + SetLintWarningValue, + SetTextOutputValue, + SetAllAccessibleOutputValue, + SetAutorefreshValue, + SetGridOutputValue, + SetLanguageValue, + SetThemeValue +} from './preferences.types'; function updatePreferences( formParams: UpdatePreferencesRequestBody, diff --git a/client/modules/IDE/actions/preferences.types.ts b/client/modules/IDE/actions/preferences.types.ts new file mode 100644 index 0000000000..e54d28d3cd --- /dev/null +++ b/client/modules/IDE/actions/preferences.types.ts @@ -0,0 +1,116 @@ +import * as ActionTypes from '../../../constants'; +import type { PreferencesState } from '../reducers/preferences'; +import type { RootState } from '../../../reducers'; + +// Value Definitions: +export type SetPreferencesTabValue = PreferencesState['tabIndex']; +export type SetFontSizeValue = PreferencesState['fontSize']; +export type SetLineNumbersValue = PreferencesState['lineNumbers']; +export type SetAutocloseBracketsQuotesValue = PreferencesState['autocloseBracketsQuotes']; +export type SetAutocompleteHinterValue = PreferencesState['autocompleteHinter']; +export type SetAutosaveValue = PreferencesState['autosave']; +export type SetLinewrapValue = PreferencesState['linewrap']; +export type SetLintWarningValue = PreferencesState['lintWarning']; +export type SetTextOutputValue = PreferencesState['textOutput']; +export type SetGridOutputValue = PreferencesState['gridOutput']; +export type SetThemeValue = PreferencesState['theme']; +export type SetAutorefreshValue = PreferencesState['autorefresh']; +export type SetLanguageValue = PreferencesState['language']; +export type SetAllAccessibleOutputValue = + | SetTextOutputValue + | SetGridOutputValue; + +// Action Definitions: +export type OpenPreferencesAction = { + type: typeof ActionTypes.OPEN_PREFERENCES; +}; +export type SetPreferencesAction = { + type: typeof ActionTypes.SET_PREFERENCES; + preferences: PreferencesState; +}; +export type SetErrorAction = { + type: typeof ActionTypes.ERROR; + error: unknown; +}; + +export type SetPreferencesTabAction = { + type: typeof ActionTypes.SET_PREFERENCES_TAB; + value: SetPreferencesTabValue; +}; +export type SetFontSizeAction = { + type: typeof ActionTypes.SET_FONT_SIZE; + value: SetFontSizeValue; +}; +export type SetLineNumbersAction = { + type: typeof ActionTypes.SET_LINE_NUMBERS; + value: SetLineNumbersValue; +}; +export type SetAutocloseBracketsQuotesAction = { + type: typeof ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES; + value: SetAutocloseBracketsQuotesValue; +}; +export type SetAutocompleteHinterAction = { + type: typeof ActionTypes.SET_AUTOCOMPLETE_HINTER; + value: SetAutocompleteHinterValue; +}; +export type SetAutosaveAction = { + type: typeof ActionTypes.SET_AUTOSAVE; + value: SetAutosaveValue; +}; +export type SetLinewrapAction = { + type: typeof ActionTypes.SET_LINEWRAP; + value: SetLinewrapValue; +}; +export type SetLintWarningAction = { + type: typeof ActionTypes.SET_LINT_WARNING; + value: SetLintWarningValue; +}; +export type SetTextOutputAction = { + type: typeof ActionTypes.SET_TEXT_OUTPUT; + value: SetTextOutputValue; +}; +export type SetGridOutputAction = { + type: typeof ActionTypes.SET_GRID_OUTPUT; + value: SetGridOutputValue; +}; +export type SetThemeAction = { + type: typeof ActionTypes.SET_THEME; + value: SetThemeValue; +}; +export type SetAutorefreshAction = { + type: typeof ActionTypes.SET_AUTOREFRESH; + value: SetAutorefreshValue; +}; +export type SetLanguageAction = { + type: typeof ActionTypes.SET_LANGUAGE; + language: SetLanguageValue; +}; + +export type PreferencesAction = + | OpenPreferencesAction + | SetPreferencesAction + | SetErrorAction + | SetPreferencesTabAction + | SetFontSizeAction + | SetLineNumbersAction + | SetAutocloseBracketsQuotesAction + | SetAutocompleteHinterAction + | SetAutosaveAction + | SetLinewrapAction + | SetLintWarningAction + | SetTextOutputAction + | SetGridOutputAction + | SetThemeAction + | SetAutorefreshAction + | SetLanguageAction; + +export type UpdatePreferencesDispatch = ( + action: PreferencesAction | PreferencesThunk +) => void; + +export type PreferencesThunk = ( + dispatch: UpdatePreferencesDispatch, + getState: GetRootState +) => void; + +export type GetRootState = () => RootState; diff --git a/client/modules/IDE/reducers/preferences.ts b/client/modules/IDE/reducers/preferences.ts index 26ded02862..f890bb2ccb 100644 --- a/client/modules/IDE/reducers/preferences.ts +++ b/client/modules/IDE/reducers/preferences.ts @@ -4,7 +4,7 @@ import { } from '../../../../common/types'; import * as ActionTypes from '../../../constants'; import i18n from '../../../i18n'; -import type { PreferencesAction } from '../actions/preferences'; +import type { PreferencesAction } from '../actions/preferences.types'; export interface PreferencesState extends Omit {